From dda5094610cb182ba33ab5035b47c4856b93ad43 Mon Sep 17 00:00:00 2001 From: Roman Bazalevskiy Date: Mon, 2 Apr 2018 17:15:49 +0300 Subject: [PATCH 1/1] =?utf8?q?=D0=A7=D0=B5=D0=BB=D0=BE=D0=B2=D0=B5=D0=BA?= =?utf8?q?=D0=BE=D1=87=D0=B8=D1=82=D0=B0=D0=B5=D0=BC=D1=8B=D0=B5=20=D0=BA?= =?utf8?q?=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20=D0=B4=D0=BB=D1=8F=20?= =?utf8?q?=D0=BF=D1=80=D0=B8=D0=B2=D1=8F=D0=B7=D0=BA=D0=B8-=D0=BE=D1=82?= =?utf8?q?=D0=B2=D1=8F=D0=B7=D0=BA=D0=B8=20(=D0=BF=D0=B5=D1=80=D0=B2=D1=8B?= =?utf8?q?=D0=B9=20=D0=BF=D0=BE=D0=B4=D1=85=D0=BE=D0=B4=20=D0=BA=20=D1=81?= =?utf8?q?=D0=BD=D0=B0=D1=80=D1=8F=D0=B4=D1=83).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- nmd/nl_mqtt.py | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/nmd/nl_mqtt.py b/nmd/nl_mqtt.py index 5261d43..25f96da 100644 --- a/nmd/nl_mqtt.py +++ b/nmd/nl_mqtt.py @@ -60,6 +60,7 @@ class MqttDriver(metaclass=Singleton): await self.commands_to_send_queue.put(payload) else: try: + mtrf_command = None address = subtopic.split('/') if len(address)==2: channel = int(address[0]) @@ -77,14 +78,14 @@ class MqttDriver(metaclass=Singleton): print("%s: %s (%s)" % (command,channel,id)) if command == "on": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 2 } + 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 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 2 } elif command == "off": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 0 } + 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 } else: @@ -92,26 +93,26 @@ class MqttDriver(metaclass=Singleton): elif command == "brightness": brightness = int(payload) if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 6, "d0": brightness } + 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 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 6, "d0": brightness } elif command == "state": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 128 } + 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 == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 7 } + 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 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 7 } elif command == "save_preset": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 8 } + 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 } else: @@ -121,13 +122,41 @@ class MqttDriver(metaclass=Singleton): d0 = delay % 256 d1 = delay // 256 if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1 } + 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 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1 } + elif command == "bind": + if id == 'tx-f': + mtrf_command = { "mode": 2, "ch": channel, "cmd": 15 } + elif id == 'tx': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 15 } + elif id == 'rx': + mtrf_command = { "mode": 1, "ch": channel, "cmd": 15 } + 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': + mtrf_command = { "mode": 2, "ch": channel, "cmd": 9 } + elif id == 'tx': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 9 } + elif id == 'rx': + mtrf_command = { "mode": 1, "ch": channel, "cmd": 9, "ctr": 5 } + 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 == '.': + 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 } - await self.commands_to_send_queue.put(mtrf_command) + if mtrf_command: + await self.commands_to_send_queue.put(mtrf_command) except Exception as e: logger.exception(e) -- 2.34.1