From 5d7ac9c9f2302599c1276889b641b40a09e3e607 Mon Sep 17 00:00:00 2001 From: Roman Bazalevskiy Date: Mon, 2 Apr 2018 18:01:38 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=B0=20=D0=BD=D0=B5=D1=87=D1=83=D0=B2=D1=81=D1=82=D0=B2=D0=B8?= =?utf8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BA?= =?utf8?q?=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D1=83=20ID/=D1=80?= =?utf8?q?=D0=B5=D0=B6=D0=B8=D0=BC=D0=BE=D0=B2=20=D1=83=D1=81=D1=82=D1=80?= =?utf8?q?=D0=BE=D0=B9=D1=81=D1=82=D0=B2.=20=D0=94=D0=BE=D1=80=D0=B0=D0=B1?= =?utf8?q?=D0=BE=D1=82=D0=B0=D0=BD=D0=BE=20=D0=BF=D1=80=D0=BE=D1=82=D0=BE?= =?utf8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?utf8?q?=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- nmd/nl_mqtt.py | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) 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: -- 2.34.1