execute method

  1. @override
Future<bool?> execute(
  1. String caller,
  2. String propertyOrFunction,
  3. List arguments
)
override

Implementation

@override
Future<bool?> execute(String caller, String propertyOrFunction, List<dynamic> arguments) async
{
  var function = propertyOrFunction.toLowerCase().trim();
  switch (function)
  {
    case "write":
    case "publish":
      String? topic   = S.toStr(S.item(arguments, 0));
      String? message = S.toStr(S.item(arguments, 1));
      if (mqtt != null && topic != null && message != null) mqtt!.publish(topic,message);
      return true;

    case "read":
    case "subscribe":
      String? topic = S.toStr(S.item(arguments, 0));
      if (!S.isNullOrEmpty(topic)) mqtt?.subscribe(topic!);
      return true;

    case "unsubscribe":
      String? topic = S.toStr(S.item(arguments, 0));
      if (mqtt != null && topic != null) mqtt!.unsubscribe(topic);
      return true;

    case "connect":
      return await start();

    case "disconnect":
      return await stop();
  }
  return super.execute(caller, propertyOrFunction, arguments);
}