From: Roman Bazalevskiy Date: Mon, 2 Apr 2018 15:01:38 +0000 (+0300) Subject: Добавлена нечувствительность к регистру ID/режимов устройств. Доработано протоколиров... X-Git-Url: https://git.rvb.name/mqtt-noolite.git/commitdiff_plain/5d7ac9c9f2302599c1276889b641b40a09e3e607?ds=sidebyside;hp=dda5094610cb182ba33ab5035b47c4856b93ad43 Добавлена нечувствительность к регистру ID/режимов устройств. Доработано протоколирование операций. --- diff --git a/nmd/nl_mqtt.py b/nmd/nl_mqtt.py index 25f96da..4a0ccb4 100644 --- a/nmd/nl_mqtt.py +++ b/nmd/nl_mqtt.py @@ -45,7 +45,7 @@ class MqttDriver(metaclass=Singleton): topic = message.topic payload = message.publish_packet.payload.data - logger.info('In message: {}\n{}'.format(topic, payload)) + logger.info('In message: {} -> {}'.format(topic, payload.decode('utf-8'))) if topic.startswith(self.read_topic): subtopic = topic[len(self.read_topic)+1:] @@ -75,82 +75,95 @@ class MqttDriver(metaclass=Singleton): channel = None id = None command = command.lower() + id = id.upper() print("%s: %s (%s)" % (command,channel,id)) if command == "on": - if id == '.': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 2, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 2, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } + elif id == 'TX': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 2 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 2 } elif command == "off": - if id == '.': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 0, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 0, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } + elif id == 'TX': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 0 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 0 } elif command == "brightness": brightness = int(payload) - if id == '.': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 6, "d0": brightness, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 6, "d0": brightness, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } + elif id == 'TX': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 6, "d0": brightness } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 6, "d0": brightness } elif command == "state": - if id == '.': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 128, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 128, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } elif command == "load_preset": - if id == '.': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 7, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 7, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } + elif id == 'TX': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 7 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 7 } elif command == "save_preset": - if id == '.': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 8, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 8, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } + elif id == 'TX': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 8 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 8 } elif command == "temp_on": delay = (int(payload) + 3)//5 d0 = delay % 256 d1 = delay // 256 - if id == '.': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } + elif id == 'TX': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1 } elif command == "bind": - if id == 'tx-f': + if id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 15 } - elif id == 'tx': + elif id == 'TX': mtrf_command = { "mode": 0, "ch": channel, "cmd": 15 } - elif id == 'rx': + elif id == 'RX': mtrf_command = { "mode": 1, "ch": channel, "cmd": 15 } - elif id == 'rx-f': + elif id == 'RX-F': mtrf_command = { "mode": 3, "ch": channel, "cmd": 15 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 15 } elif command == "unbind": - if id == '.' or id == 'tx-f': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 9 } - elif id == 'tx': + elif id == 'TX': mtrf_command = { "mode": 0, "ch": channel, "cmd": 9 } - elif id == 'rx': + elif id == 'RX': mtrf_command = { "mode": 1, "ch": channel, "cmd": 9, "ctr": 5 } - elif id == 'rx-f': + elif id == 'RX-F': mtrf_command = { "mode": 3, "ch": channel, "cmd": 9, "ctr": 5 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 9 } elif command == "service": - if id == '.': + if id == '.' or id == 'TX-F': mtrf_command = { "mode": 2, "ch": channel, "cmd": 131, "d0": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 131, "d0": 1, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } @@ -185,8 +198,8 @@ class MqttDriver(metaclass=Singleton): last_command_send_time = time.time() async def input_serial_data(self, command): - logger.info('Pub command: {}'.format(command)) command = self.noolite_response_to_payload(command.to_list()) + logger.info('Pub command: {}'.format(command)) try: topic = "%s/%s/%s" % (self.write_topic, command['ch'], command['id']) except: