def do_zclwrite(self, line):
     """
     To write ZCL attribute:
     zclwrite <cluster> <attribute> <nodeid> <endpoint> <groupid> <value>
     """
     try:
         args = shlex.split(line)
         all_attrs = self.devCtrl.ZCLAttributeList()
         if len(args) == 1 and args[0] == '?':
             print('\n'.join(all_attrs.keys()))
         elif len(args) == 2 and args[0] == '?':
             if args[1] not in all_attrs:
                 raise exceptions.UnknownCluster(args[1])
             cluster_attrs = all_attrs.get(args[1], {})
             print('\n'.join(["{}: {}".format(key, cluster_attrs[key]["type"]) for key in cluster_attrs.keys() if cluster_attrs[key].get("writable", False)]))
         elif len(args) == 6:
             if args[0] not in all_attrs:
                 raise exceptions.UnknownCluster(args[0])
             attribute_type = all_attrs.get(args[0], {}).get(
                 args[1], {}).get("type", None)
             self.devCtrl.ZCLWriteAttribute(args[0], args[1], int(
                 args[2]), int(args[3]), int(args[4]), ParseValueWithType(args[5], attribute_type))
         else:
             self.do_help("zclwrite")
     except exceptions.ChipStackException as ex:
         print("An exception occurred during writing ZCL attribute:")
         print(str(ex))
     except Exception as ex:
         print("An exception occurred during processing input:")
         print(str(ex))
 def do_zclconfigure(self, line):
     """
     To configure ZCL attribute reporting:
     zclconfigure <cluster> <attribute> <nodeid> <endpoint> <minInterval> <maxInterval> <change>
     """
     try:
         args = shlex.split(line)
         all_attrs = self.devCtrl.ZCLAttributeList()
         if len(args) == 1 and args[0] == '?':
             print('\n'.join(all_attrs.keys()))
         elif len(args) == 2 and args[0] == '?':
             if args[1] not in all_attrs:
                 raise exceptions.UnknownCluster(args[1])
             cluster_attrs = all_attrs.get(args[1], {})
             print('\n'.join([key for key in cluster_attrs.keys() if cluster_attrs[key].get("reportable", False)]))
         elif len(args) == 7:
             if args[0] not in all_attrs:
                 raise exceptions.UnknownCluster(args[0])
             self.devCtrl.ZCLConfigureAttribute(args[0], args[1], int(
                 args[2]), int(args[3]), int(args[4]), int(args[5]), int(args[6]))
         else:
             self.do_help("zclconfigure")
     except exceptions.ChipStackException as ex:
         print("An exception occurred during configuring reporting of ZCL attribute:")
         print(str(ex))
     except Exception as ex:
         print("An exception occurred during processing input:")
         print(str(ex))
 def do_zclread(self, line):
     """
     To read ZCL attribute:
     zclread <cluster> <attribute> <nodeid> <endpoint> <groupid>
     """
     try:
         args = shlex.split(line)
         all_attrs = self.devCtrl.ZCLAttributeList()
         if len(args) == 1 and args[0] == '?':
             print('\n'.join(all_attrs.keys()))
         elif len(args) == 2 and args[0] == '?':
             if args[1] not in all_attrs:
                 raise exceptions.UnknownCluster(args[1])
             print('\n'.join(all_attrs.get(args[1]).keys()))
         elif len(args) == 5:
             if args[0] not in all_attrs:
                 raise exceptions.UnknownCluster(args[0])
             res = self.devCtrl.ZCLReadAttribute(args[0], args[1], int(
                 args[2]), int(args[3]), int(args[4]))
             if res != None:
                 print(repr(res))
         else:
             self.do_help("zclread")
     except exceptions.ChipStackException as ex:
         print("An exception occurred during reading ZCL attribute:")
         print(str(ex))
     except Exception as ex:
         print("An exception occurred during processing input:")
         print(str(ex))
Ejemplo n.º 4
0
    def do_zcl(self, line):
        """
        To send ZCL message to device:
        zcl <cluster> <command> <nodeid> <endpoint> <groupid> [key=value]...
        To get a list of clusters:
        zcl ?
        To get a list of commands in cluster:
        zcl ? <cluster>

        Send ZCL command to device nodeid
        """
        try:
            args = shlex.split(line)
            all_commands = self.devCtrl.ZCLCommandList()
            if len(args) == 1 and args[0] == '?':
                print('\n'.join(all_commands.keys()))
            elif len(args) == 2 and args[0] == '?':
                if args[1] not in all_commands:
                    raise exceptions.UnknownCluster(args[1])
                for commands in all_commands.get(args[1]).items():
                    args = ", ".join([
                        "{}: {}".format(argName, argType)
                        for argName, argType in commands[1].items()
                    ])
                    print(commands[0])
                    if commands[1]:
                        print("  ", args)
                    else:
                        print("  <no arguments>")
            elif len(args) > 4:
                if args[0] not in all_commands:
                    raise exceptions.UnknownCluster(args[0])
                command = all_commands.get(args[0]).get(args[1], None)
                # When command takes no arguments, (not command) is True
                if command is None:
                    raise exceptions.UnknownCommand(args[0], args[1])
                err, res = self.devCtrl.ZCLSend(args[0],
                                                args[1],
                                                int(args[2]),
                                                int(args[3]),
                                                int(args[4]),
                                                FormatZCLArguments(
                                                    args[5:], command),
                                                blocking=True)
                if err != 0:
                    print("Failed to receive command response: {}".format(res))
                elif res != None:
                    print("Received command status response:")
                    print(res)
                else:
                    print("Success, no status code is attached with response.")
            else:
                self.do_help("zcl")
        except exceptions.ChipStackException as ex:
            print("An exception occurred during process ZCL command:")
            print(str(ex))
        except Exception as ex:
            print("An exception occurred during processing input:")
            traceback.print_exc()
            print(str(ex))
Ejemplo n.º 5
0
    def do_zcl(self, line):
        """
        To send ZCL message to device:
        zcl <cluster> <command> <nodeid> <endpoint> <groupid> [key=value]...
        To get a list of clusters:
        zcl ?
        To get a list of commands in cluster:
        zcl ? <cluster>

        Send ZCL command to device nodeid
        """
        try:
            args = shlex.split(line)
            if len(args) == 1 and args[0] == '?':
                print(self.devCtrl.ZCLList().keys())
            elif len(args) == 2 and args[0] == '?':
                cluster = self.devCtrl.ZCLList().get(args[1], None)
                if not cluster:
                    raise exceptions.UnknownCluster(args[1])
                for commands in cluster.items():
                    args = ", ".join([
                        "{}: {}".format(argName, argType)
                        for argName, argType in commands[1].items()
                    ])
                    print(commands[0])
                    if commands[1]:
                        print("  ", args)
                    else:
                        print("  <no arguments>")
            elif len(args) > 4:
                cluster = self.devCtrl.ZCLList().get(args[0], None)
                if not cluster:
                    raise exceptions.UnknownCluster(args[0])
                command = cluster.get(args[1], None)
                # When command takes no arguments, (not command) is True
                if command == None:
                    raise exceptions.UnknownCommand(args[0], args[1])
                self.devCtrl.ZCLSend(args[0], args[1], int(args[2]),
                                     int(args[3]), int(args[4]),
                                     FormatZCLArguments(args[5:], command))
            else:
                self.do_help("zcl")
        except exceptions.ChipStackException as ex:
            print("An exception occurred during process ZCL command:")
            print(str(ex))
        except Exception as ex:
            print("An exception occurred during processing input:")
            print(str(ex))
Ejemplo n.º 6
0
    def do_zclsubscribe(self, line):
        """
        To subscribe ZCL attribute reporting:
        zclsubscribe <cluster> <attribute> <nodeid> <endpoint> <minInterval> <maxInterval>

        To shut down a subscription:
        zclsubscribe -shutdown <subscriptionId>
        """
        try:
            args = shlex.split(line)
            all_attrs = self.devCtrl.ZCLAttributeList()
            if len(args) == 1 and args[0] == '?':
                print('\n'.join(all_attrs.keys()))
            elif len(args) == 2 and args[0] == '?':
                if args[1] not in all_attrs:
                    raise exceptions.UnknownCluster(args[1])
                cluster_attrs = all_attrs.get(args[1], {})
                print('\n'.join([
                    key for key in cluster_attrs.keys()
                    if cluster_attrs[key].get("reportable", False)
                ]))
            elif len(args) == 6:
                if args[0] not in all_attrs:
                    raise exceptions.UnknownCluster(args[0])
                res = self.devCtrl.ZCLSubscribeAttribute(
                    args[0], args[1], int(args[2]), int(args[3]), int(args[4]),
                    int(args[5]))
                self.replHint = f"sub = await devCtrl.ReadAttribute({int(args[2])}, [({int(args[3])}, Clusters.{args[0]}.Attributes.{args[1]})], reportInterval=({int(args[4])}, {int(args[5])}))"
                print(res.GetAllValues())
                print(f"Subscription Established: {res}")
            elif len(args) == 2 and args[0] == '-shutdown':
                subscriptionId = int(args[1], base=0)
                self.replHint = "You can call sub.Shutdown() (sub is the return value of ReadAttribute() called before)"
                self.devCtrl.ZCLShutdownSubscription(subscriptionId)
            else:
                self.do_help("zclsubscribe")
        except exceptions.ChipStackException as ex:
            print(
                "An exception occurred during configuring reporting of ZCL attribute:"
            )
            print(str(ex))
        except Exception as ex:
            print("An exception occurred during processing input:")
            print(str(ex))
Ejemplo n.º 7
0
def send_zcl_command(devCtrl, line):
    """
    Send ZCL message to device:
    <cluster> <command> <nodeid> <endpoint> <groupid> [key=value]...
    :param devCtrl: device controller instance
    :param line: command line
    :return: error code and command responde
    """
    res = None
    err = 0
    try:
        args = shlex.split(line)
        all_commands = devCtrl.ZCLCommandList()
        if len(args) < 5:
            raise exceptions.InvalidArgumentCount(5, len(args))

        if args[0] not in all_commands:
            raise exceptions.UnknownCluster(args[0])
        command = all_commands.get(args[0]).get(args[1], None)
        # When command takes no arguments, (not command) is True
        if command == None:
            raise exceptions.UnknownCommand(args[0], args[1])
        err, res = devCtrl.ZCLSend(args[0],
                                   args[1],
                                   int(args[2]),
                                   int(args[3]),
                                   int(args[4]),
                                   FormatZCLArguments(args[5:], command),
                                   blocking=True)
        if err != 0:
            log.error("Failed to send ZCL command [{}] {}.".format(err, res))
        elif res != None:
            log.info("Success, received command response:")
            log.info(res)
        else:
            log.info("Success, no command response.")
    except exceptions.ChipStackException as ex:
        log.error("An exception occurred during processing ZCL command:")
        log.error(str(ex))
        err = -1
    except Exception as ex:
        log.error("An exception occurred during processing input:")
        log.error(str(ex))
        err = -1

    return (err, res)