Пример #1
0
 def __init__(self, meta, commands, parent=None):
     super().__init__()
     self.main = parent
     self.commands = commands
     self.port = meta['port']
     self.zigbee_id = meta['zigbee_id']
     self.channel = meta['channel']
     self.driver = ZigBeeDriver(self.port, self.channel, self.zigbee_id)
Пример #2
0
    def func_btn_zigbee_dongle_disconnect(self):
        port = self.comboBox_port.currentText()
        channel = int(self.lineEdit_zigbee_channel.text())
        zigbee_id = int(self.comboBox_zigbee_ids.currentText().split(':')[1],
                        16)
        driver = ZigBeeDriver(port, channel, zigbee_id)

        isConnected = True
        while isConnected:
            short_addr = driver.disconnect()
            if short_addr < 0:
                isConnected = False
                print(short_addr)
                break
            time.sleep(1)

        self.set_cmd_gen_enable(False)
        del driver
Пример #3
0
class Worker(QThread):
    signal_command_complete = pyqtSignal(
        str
    )  # signal for letting the main thread know that the command is done

    def __init__(self, meta, commands, parent=None):
        super().__init__()
        self.main = parent
        self.commands = commands
        self.port = meta['port']
        self.zigbee_id = meta['zigbee_id']
        self.channel = meta['channel']
        self.driver = ZigBeeDriver(self.port, self.channel, self.zigbee_id)

    def run(self):  # communicate to zigbee driver class
        # TODO: make new routine for new structure
        # for task_cmd in self.commands:
        #     pass
        # Original code
        for command in self.commands:
            currents = []
            prevs = []
            command['timestamp'] = datetime.datetime.now().strftime(
                '%m-%d %H:%M:%S.%f')  # add time stamp

            if not "CONNECT" in command['command']:
                try:
                    # get current value of attributes
                    attrs = self.create_attribute(command)
                    for attr in attrs:
                        prevs.append(self.driver.read_attr_command(attr))

                    # write command
                    self.driver.write_attr_command(command)

                    if command['cluster'] != 'ON_OFF_CLUSTER':
                        # then, wait until remaining_time == 0
                        while True:
                            attribute = self.create_attribute(command,
                                                              isRemain=True)
                            remain_time = self.driver.read_attr_command(
                                attribute)
                            time.sleep(0.1)
                            if remain_time.value == 0:
                                break

                    attrs = self.create_attribute(command)
                    for attr in attrs:
                        currents.append(self.driver.read_attr_command(attr))

                    # result validation and then, update result into the table
                    for prev, current in list(zip(prevs, currents)):
                        validator = Validator(command, prev, current)
                        result = validator.vaildate_attribute()
                        self.signal_command_complete.emit(result)
                except:
                    print("read attr is none")

        print("현재 명령셋 종료")
        del self.driver

    def create_attribute(self, command, isRemain=False):
        # just get attribute from pre-defined command - attribute
        cluster = clusters[command['cluster']]
        cmd = commands[command['cluster']][command['command']]

        if isRemain:  # read remaining time
            if cluster == LVL_CTRL_CLUSTER:
                attribute_id, attribute_type = attributes[
                    'LVL_CTRL_REMAIN_TIME_ATTR']
            elif cluster == COLOR_CTRL_CLUSTER:
                attribute_id, attribute_type = attributes[
                    'COLOR_CTRL_REMAIN_TIME_ATTR']

            attr_name = "remain_time"
            attribute = Attribute(cluster=cluster,
                                  id=attribute_id,
                                  type=attribute_type,
                                  name=attr_name)
            return attribute

        else:  # read value
            attrs = []
            if cluster == ON_OFF_CLUSTER:  # onoff cluster only need on_off_attr
                attribute_id, attribute_type = attributes['ON_OFF_ONOFF_ATTR']
                attr_name = "ON/OFF"
                attrs.append(
                    Attribute(cluster=cluster,
                              id=attribute_id,
                              type=attribute_type,
                              name=attr_name))
            elif cluster == LVL_CTRL_CLUSTER:  # update here
                attribute_id, attribute_type = attributes[
                    'LVL_CTRL_CURR_LVL_ATTR']
                attr_name = "밝기"
                attrs.append(
                    Attribute(cluster=cluster,
                              id=attribute_id,
                              type=attribute_type,
                              name=attr_name))
            elif cluster == COLOR_CTRL_CLUSTER:
                if cmd == COLOR_CTRL_MV_TO_COLOR_TEMP_CMD:
                    attribute_id, attribute_type = attributes[
                        'COLOR_CTRL_COLOR_TEMP_MIRED_ATTR']
                    attr_name = "온도"
                    attrs.append(
                        Attribute(cluster=cluster,
                                  id=attribute_id,
                                  type=attribute_type,
                                  name=attr_name))
                elif cmd == COLOR_CTRL_MV_TO_COLOR_CMD:
                    attribute_id, attribute_type = attributes[
                        'COLOR_CTRL_CURR_X_ATTR']
                    attr_name = "Color X"
                    attrs.append(
                        Attribute(cluster=cluster,
                                  id=attribute_id,
                                  type=attribute_type,
                                  name=attr_name))

                    attr_name = "Color Y"
                    attribute_id, attribute_type = attributes[
                        'COLOR_CTRL_CURR_Y_ATTR']
                    attrs.append(
                        Attribute(cluster=cluster,
                                  id=attribute_id,
                                  type=attribute_type,
                                  name=attr_name))

            # @hipiphock
            # attrs = command.attr_list

    def stop(self):
        del self
Пример #4
0
# print(zb.get_short_address())

# zb.disconnect()

# print(zb.get_short_address())

# cmd_gen = CmdGenerator()
# on = cmd_gen.cmd_onoff(on=True, off=False, toggle=False)
# move_to = cmd_gen.cmd_level(command='MOVE_TO', level=254, transition=65534)
# toggle = cmd_gen.cmd_onoff(on=False, off=False, toggle=True)
# zb.write_attr_command(on)
# time.sleep(1)
# zb.write_attr_command(move_to)
# time.sleep(1)
# zb.write_attr_command(toggle)
import logging
from CommandGenerator.command_generator import CmdGenerator
from Handler.Zigbee.zigbee_driver import ZigBeeDriver
from Handler.Zigbee.structures import CLUSTER_TABLE, TaskCmd

logging.basicConfig(level=logging.DEBUG)

if __name__ == "__main__":
    task_cmd_list = []
    cmdgen = CmdGenerator()
    zigbeedriver = ZigBeeDriver('COM14', 24, 9824354097448244232)
    task_cmd_list.append(cmdgen.new_cmd('ON_OFF_CLUSTER', 'TOGGLE', 20, None))
    task_cmd_list.append(cmdgen.new_cmd('ON_OFF_CLUSTER', 'TOGGLE', 20, None))
    task_cmd_list.append(cmdgen.new_cmd('ON_OFF_CLUSTER', 'TOGGLE', 20, None))
    for task_cmd in task_cmd_list:
        zigbeedriver.new_run_command(0, task_cmd)