From ca022d7596ccd4f602a0978e93968209dcf3b71a Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Sat, 28 Oct 2023 20:21:11 +0200 Subject: [PATCH 1/6] upgrade to packet_receive, but not yet done --- Classes/ZigpyTransport/AppBellows.py | 9 ++- Classes/ZigpyTransport/AppDeconz.py | 3 + Classes/ZigpyTransport/AppGeneric.py | 84 ++++++++++++++-------------- Classes/ZigpyTransport/AppZnp.py | 3 + plugin.py | 2 +- requirements.txt | 2 +- 6 files changed, 56 insertions(+), 47 deletions(-) diff --git a/Classes/ZigpyTransport/AppBellows.py b/Classes/ZigpyTransport/AppBellows.py index e889497c4..ae51782ef 100644 --- a/Classes/ZigpyTransport/AppBellows.py +++ b/Classes/ZigpyTransport/AppBellows.py @@ -7,7 +7,8 @@ import logging import bellows.config as bellows_conf -import bellows.types as t +import bellows.types as bt +import zigpy.types as t import bellows.zigbee.application import zigpy.config as zigpy_conf import zigpy.device @@ -136,7 +137,7 @@ async def register_endpoints(self, endpoint=1): def get_device(self, ieee=None, nwk=None): return Classes.ZigpyTransport.AppGeneric.get_device(self, ieee, nwk) - def handle_join(self, nwk: t.EmberNodeId, ieee: t.EmberEUI64, parent_nwk: t.EmberNodeId, *, handle_rejoin: bool = True,) -> None: + def handle_join(self, nwk: bt.EmberNodeId, ieee: bt.EmberEUI64, parent_nwk: bt.EmberNodeId, *, handle_rejoin: bool = True,) -> None: return Classes.ZigpyTransport.AppGeneric.handle_join(self, nwk, ieee, parent_nwk) def get_device_ieee(self, nwk): @@ -161,6 +162,10 @@ def handle_message( )->None: return Classes.ZigpyTransport.AppGeneric.handle_message(self,sender,profile,cluster,src_ep,dst_ep,message, dst_addressing=dst_addressing) + + def packet_received(self, packet: t.ZigbeePacket) -> None: + return Classes.ZigpyTransport.AppGeneric.packet_received(self,packet) + async def set_zigpy_tx_power(self, power): # EmberConfigTxPowerMode - EZSP_CONFIG_TX_POWER_MODE in EzspConfigId # 0x00: Normal mode diff --git a/Classes/ZigpyTransport/AppDeconz.py b/Classes/ZigpyTransport/AppDeconz.py index 4b109fd8d..d922e3959 100644 --- a/Classes/ZigpyTransport/AppDeconz.py +++ b/Classes/ZigpyTransport/AppDeconz.py @@ -155,6 +155,9 @@ def handle_message( ) -> None: return Classes.ZigpyTransport.AppGeneric.handle_message(self,sender,profile,cluster,src_ep,dst_ep,message,dst_addressing=dst_addressing) + def packet_received(self, packet: t.ZigbeePacket) -> None: + return Classes.ZigpyTransport.AppGeneric.packet_received(self,packet) + async def set_zigpy_tx_power(self, power): pass #await self._api.set_tx_power(power) diff --git a/Classes/ZigpyTransport/AppGeneric.py b/Classes/ZigpyTransport/AppGeneric.py index 855f2daa2..76c3a7986 100644 --- a/Classes/ZigpyTransport/AppGeneric.py +++ b/Classes/ZigpyTransport/AppGeneric.py @@ -34,7 +34,7 @@ async def initialize(self, *, auto_form: bool = False, force_form: bool = False) Starts the network on a connected radio, optionally forming one with random settings if necessary. """ - self.log.logging("TransportZigpy", "Debug", "AppGeneric:initialize auto_form: %s force_form: %s Class: %s" %( auto_form, force_form, type(self))) + self.log.logging("TransportZigpy", "Log", "AppGeneric:initialize auto_form: %s force_form: %s Class: %s" %( auto_form, force_form, type(self))) _retreived_backup = None if "autoRestore" in self.pluginconf.pluginConf and self.pluginconf.pluginConf["autoRestore"]: @@ -45,7 +45,7 @@ async def initialize(self, *, auto_form: bool = False, force_form: bool = False) if _retreived_backup: if self.pluginconf.pluginConf[ "OverWriteCoordinatorIEEEOnlyOnce"]: - LOGGER.debug("Allow eui64 overwrite only once !!!") + LOGGER.debug("Allow eui64 overwrite only once !!!") _retreived_backup.network_info.stack_specific.setdefault("ezsp", {})[ "i_understand_i_can_update_eui64_only_once_and_i_still_want_to_do_it"] = True LOGGER.debug("Last backup retreived: %s" % _retreived_backup ) @@ -161,7 +161,7 @@ def get_device_ieee(self, nwk): return None def handle_leave(self, nwk, ieee): - self.log.logging("TransportZigpy", "Debug","handle_leave (0x%04x %s)" %(nwk, ieee)) + self.log.logging("TransportZigpy", "Log","handle_leave (0x%04x %s)" %(nwk, ieee)) plugin_frame = build_plugin_8048_frame_content(self, ieee) self.callBackFunction(plugin_frame) super(type(self),self).handle_leave(nwk, ieee) @@ -171,37 +171,48 @@ def get_zigpy_version(self): LOGGER.debug("get_zigpy_version ake version number. !!") return self.version -def handle_message( - self, - sender: zigpy.device.Device, - profile: int, - cluster: int, - src_ep: int, - dst_ep: int, - message: bytes, - dst_addressing=None, -) -> None: - +def packet_received(self, packet: t.ZigbeePacket) -> None: + """Notify zigpy of a received Zigbee packet.""" + + try: + device = self.get_device_with_address(packet.src) + self.log.logging("TransportZigpy", "Log", "identified device - %s (%s)" %(str(device), type(device)) ) + + except KeyError: + self.log.logging("TransportZigpy", "Log", "Unknown device %r", packet.src) + return + + sender=device + profile=packet.profile_id + cluster=packet.cluster_id + src_ep=packet.src_ep + dst_ep=packet.dst_ep + message=packet.data.serialize()[::-1] + dst_addressing=(packet.dst).addr_mode + write_capture_rx_frames( self, sender, profile, cluster, src_ep, dst_ep, message, binascii.hexlify(message).decode("utf-8"), dst_addressing) - + + self.log.logging("TransportZigpy", "Log", "packet_received - %s %s %s %s %s %s %s %s" %( + sender, profile, cluster, src_ep, dst_ep, message, binascii.hexlify(message).decode("utf-8"), dst_addressing)) + if sender.nwk == 0x0000: - self.log.logging("TransportZigpy", "Debug", "handle_message from Controller Sender: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( + # When coming from coordinator we have to send it back to zigpy + self.log.logging("TransportZigpy", "Log", "packet_received from Controller Sender: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) - #self.super().handle_message(sender, profile, cluster, src_ep, dst_ep, message) - super(type(self),self).handle_message(sender, profile, cluster, src_ep, dst_ep, message) + #super(type(self),self).packet_received(packet) if cluster == 0x8036: # This has been handle via on_zdo_mgmt_permitjoin_rsp() - self.log.logging("TransportZigpy", "Debug", "handle_message 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( + self.log.logging("TransportZigpy", "Log", "packet_received 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) self.callBackFunction( build_plugin_8014_frame_content(self, str(sender), binascii.hexlify(message).decode("utf-8") ) ) - super(type(self),self).handle_message(sender, profile, cluster, src_ep, dst_ep, message) + super(type(self),self).packet_received(packet) return if cluster == 0x8034: # This has been handle via on_zdo_mgmt_leave_rsp() - self.log.logging("TransportZigpy", "Debug", "handle_message 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( + self.log.logging("TransportZigpy", "Log", "packet_received 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) self.callBackFunction( build_plugin_8047_frame_content(self, str(sender), binascii.hexlify(message).decode("utf-8")) ) return @@ -211,21 +222,15 @@ def handle_message( addr_mode = 0x02 addr = sender.nwk.serialize()[::-1].hex() if profile and cluster: - self.log.logging( - "TransportZigpy", - "Debug", - "handle_message device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( - str(sender), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi)), + self.log.logging( "TransportZigpy", "Log", "packet_received device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( + str(sender), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi)), elif sender.ieee is not None: addr = "%016x" % t.uint64_t.deserialize(sender.ieee.serialize())[0] addr_mode = 0x03 if profile and cluster: - self.log.logging( - "TransportZigpy", - "Debug", - "handle_message device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( - str(sender), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi)), + self.log.logging( "TransportZigpy", "Log", "packet_received device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( + str(sender), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi)), if sender.lqi is None: sender.lqi = 0x00 @@ -234,23 +239,16 @@ def handle_message( profile = 0x0000 if profile and cluster: - self.log.logging( - "TransportZigpy", - "Debug", - "handle_message device 2: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( - str(addr), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi), - ) + self.log.logging( "TransportZigpy", "Log", "packet_received device 2: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( + str(addr), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi), ) if addr: plugin_frame = build_plugin_8002_frame_content(self, addr, profile, cluster, src_ep, dst_ep, message, sender.lqi, src_addrmode=addr_mode) - self.log.logging("TransportZigpy", "Debug", "handle_message Sender: %s frame for plugin: %s" % (addr, plugin_frame)) + self.log.logging("TransportZigpy", "Log", "packet_received Sender: %s frame for plugin: %s" % (addr, plugin_frame)) self.callBackFunction(plugin_frame) else: - self.log.logging( - "TransportZigpy", - "Error", - "handle_message - Issue with sender is %s %s" % (sender.nwk, sender.ieee), - ) + self.log.logging( "TransportZigpy", "Error", "packet_received - Issue with sender is %s %s" % ( + sender.nwk, sender.ieee), ) return diff --git a/Classes/ZigpyTransport/AppZnp.py b/Classes/ZigpyTransport/AppZnp.py index 609437e55..6df4b96a7 100644 --- a/Classes/ZigpyTransport/AppZnp.py +++ b/Classes/ZigpyTransport/AppZnp.py @@ -128,6 +128,9 @@ def handle_message( ) -> None: return Classes.ZigpyTransport.AppGeneric.handle_message(self,sender,profile,cluster,src_ep,dst_ep,message, dst_addressing=dst_addressing) + def packet_received(self, packet: t.ZigbeePacket) -> None: + return Classes.ZigpyTransport.AppGeneric.packet_received(self,packet) + async def set_zigpy_tx_power(self, power): self.log.logging("TransportZigpy", "Debug", "set_tx_power %s" %power) await self.set_tx_power(dbm=power) diff --git a/plugin.py b/plugin.py index b8ea0a818..58c09d6b1 100644 --- a/plugin.py +++ b/plugin.py @@ -1502,7 +1502,7 @@ def update_DB_device_status_to_reinit( self ): def check_python_modules_version( self ): MODULES_VERSION = { - "zigpy": "0.58.1", + "zigpy": "0.59.0", "zigpy_znp": "0.11.6", "zigpy_deconz": "0.21.1", "bellows": "0.36.8", diff --git a/requirements.txt b/requirements.txt index c265e1938..8c3ab80dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -zigpy==0.58.1 +zigpy==0.59.0 zigpy_deconz==0.21.1 zigpy-cli==1.0.4 zigpy_znp==0.11.6 From 25c6e8c77eff2790cfe1c369da64154b4a1e9c73 Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Sun, 29 Oct 2023 09:57:16 +0100 Subject: [PATCH 2/6] send 0x0000 message back to zigpy --- Classes/ZigpyTransport/AppGeneric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/ZigpyTransport/AppGeneric.py b/Classes/ZigpyTransport/AppGeneric.py index 76c3a7986..4f2fcaa5e 100644 --- a/Classes/ZigpyTransport/AppGeneric.py +++ b/Classes/ZigpyTransport/AppGeneric.py @@ -200,7 +200,7 @@ def packet_received(self, packet: t.ZigbeePacket) -> None: # When coming from coordinator we have to send it back to zigpy self.log.logging("TransportZigpy", "Log", "packet_received from Controller Sender: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) - #super(type(self),self).packet_received(packet) + super(type(self),self).packet_received(packet) if cluster == 0x8036: # This has been handle via on_zdo_mgmt_permitjoin_rsp() From 406393029c1305cb7679450df7e49c5ba86729d2 Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Sun, 29 Oct 2023 11:57:56 +0100 Subject: [PATCH 3/6] fix issue in decoding packet --- Classes/ZigpyTransport/AppGeneric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/ZigpyTransport/AppGeneric.py b/Classes/ZigpyTransport/AppGeneric.py index 4f2fcaa5e..f5c278525 100644 --- a/Classes/ZigpyTransport/AppGeneric.py +++ b/Classes/ZigpyTransport/AppGeneric.py @@ -188,7 +188,7 @@ def packet_received(self, packet: t.ZigbeePacket) -> None: cluster=packet.cluster_id src_ep=packet.src_ep dst_ep=packet.dst_ep - message=packet.data.serialize()[::-1] + message=packet.data.serialize() dst_addressing=(packet.dst).addr_mode write_capture_rx_frames( self, sender, profile, cluster, src_ep, dst_ep, message, binascii.hexlify(message).decode("utf-8"), dst_addressing) From da0c9f4b3ff23eb265c718c6dadeecffe09ef202 Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Sun, 29 Oct 2023 12:26:06 +0100 Subject: [PATCH 4/6] refactor --- Classes/ZigpyTransport/AppGeneric.py | 47 ++++++++++++++-------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/Classes/ZigpyTransport/AppGeneric.py b/Classes/ZigpyTransport/AppGeneric.py index f5c278525..07fce4794 100644 --- a/Classes/ZigpyTransport/AppGeneric.py +++ b/Classes/ZigpyTransport/AppGeneric.py @@ -174,37 +174,35 @@ def get_zigpy_version(self): def packet_received(self, packet: t.ZigbeePacket) -> None: """Notify zigpy of a received Zigbee packet.""" - try: - device = self.get_device_with_address(packet.src) - self.log.logging("TransportZigpy", "Log", "identified device - %s (%s)" %(str(device), type(device)) ) - + sender = self.get_device_with_address(packet.src) + self.log.logging("TransportZigpy", "Debug", "identified device - %s (%s)" %(str(sender), type(sender)) ) + except KeyError: - self.log.logging("TransportZigpy", "Log", "Unknown device %r", packet.src) + self.log.logging("TransportZigpy", "Debug", "Unknown device %r", packet.src) return - - sender=device - profile=packet.profile_id - cluster=packet.cluster_id - src_ep=packet.src_ep - dst_ep=packet.dst_ep - message=packet.data.serialize() - dst_addressing=(packet.dst).addr_mode - + + self.log.logging("TransportZigpy", "Debug", "identified device - %s (%s)" % (str(sender), type(sender))) + + profile, cluster, src_ep, dst_ep = packet.profile_id, packet.cluster_id, packet.src_ep, packet.dst_ep + message = packet.data.serialize() + hex_message = binascii.hexlify(message).decode("utf-8") + dst_addressing = packet.dst.addr_mode if packet.dst else None + write_capture_rx_frames( self, sender, profile, cluster, src_ep, dst_ep, message, binascii.hexlify(message).decode("utf-8"), dst_addressing) - self.log.logging("TransportZigpy", "Log", "packet_received - %s %s %s %s %s %s %s %s" %( + self.log.logging("TransportZigpy", "Debug", "packet_received - %s %s %s %s %s %s %s %s" %( sender, profile, cluster, src_ep, dst_ep, message, binascii.hexlify(message).decode("utf-8"), dst_addressing)) if sender.nwk == 0x0000: # When coming from coordinator we have to send it back to zigpy - self.log.logging("TransportZigpy", "Log", "packet_received from Controller Sender: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( + self.log.logging("TransportZigpy", "Debug", "packet_received from Controller Sender: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) super(type(self),self).packet_received(packet) if cluster == 0x8036: # This has been handle via on_zdo_mgmt_permitjoin_rsp() - self.log.logging("TransportZigpy", "Log", "packet_received 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( + self.log.logging("TransportZigpy", "Debug", "packet_received 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) self.callBackFunction( build_plugin_8014_frame_content(self, str(sender), binascii.hexlify(message).decode("utf-8") ) ) super(type(self),self).packet_received(packet) @@ -212,7 +210,7 @@ def packet_received(self, packet: t.ZigbeePacket) -> None: if cluster == 0x8034: # This has been handle via on_zdo_mgmt_leave_rsp() - self.log.logging("TransportZigpy", "Log", "packet_received 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( + self.log.logging("TransportZigpy", "Debug", "packet_received 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) self.callBackFunction( build_plugin_8047_frame_content(self, str(sender), binascii.hexlify(message).decode("utf-8")) ) return @@ -222,29 +220,30 @@ def packet_received(self, packet: t.ZigbeePacket) -> None: addr_mode = 0x02 addr = sender.nwk.serialize()[::-1].hex() if profile and cluster: - self.log.logging( "TransportZigpy", "Log", "packet_received device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( + self.log.logging( "TransportZigpy", "Debug", "packet_received device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( str(sender), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi)), elif sender.ieee is not None: addr = "%016x" % t.uint64_t.deserialize(sender.ieee.serialize())[0] addr_mode = 0x03 if profile and cluster: - self.log.logging( "TransportZigpy", "Log", "packet_received device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( + self.log.logging( "TransportZigpy", "Debug", "packet_received device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( str(sender), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi)), if sender.lqi is None: sender.lqi = 0x00 + # Let's force profile to ZDP if eps == 0x00 if src_ep == dst_ep == 0x00: profile = 0x0000 - if profile and cluster: - self.log.logging( "TransportZigpy", "Log", "packet_received device 2: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( + if profile is not None and cluster is not None: + self.log.logging( "TransportZigpy", "Debug", "packet_received device 2: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( str(addr), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi), ) - if addr: + if addr is not None: plugin_frame = build_plugin_8002_frame_content(self, addr, profile, cluster, src_ep, dst_ep, message, sender.lqi, src_addrmode=addr_mode) - self.log.logging("TransportZigpy", "Log", "packet_received Sender: %s frame for plugin: %s" % (addr, plugin_frame)) + self.log.logging("TransportZigpy", "Debug", "packet_received Sender: %s frame for plugin: %s" % (addr, plugin_frame)) self.callBackFunction(plugin_frame) else: self.log.logging( "TransportZigpy", "Error", "packet_received - Issue with sender is %s %s" % ( From 2ad4e4203f8d74f93091b6216521c9c369c9fe13 Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Sun, 29 Oct 2023 12:37:41 +0100 Subject: [PATCH 5/6] use zigpy type instead of ZNP type --- Classes/ZigpyTransport/AppZnp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/ZigpyTransport/AppZnp.py b/Classes/ZigpyTransport/AppZnp.py index 6df4b96a7..b9d2b408d 100644 --- a/Classes/ZigpyTransport/AppZnp.py +++ b/Classes/ZigpyTransport/AppZnp.py @@ -13,7 +13,8 @@ import zigpy.zdo.types as zdo_types import zigpy_znp.commands.util import zigpy_znp.config as znp_conf -import zigpy_znp.types as t +#import zigpy_znp.types as znp_t +import zigpy.types as t import zigpy_znp.zigbee.application from Classes.ZigpyTransport.firmwareversionHelper import \ znp_extract_versioning_for_plugin From d60261ae466ad4ce0a1e33f1dc8959e2c6d51b09 Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Sun, 29 Oct 2023 15:24:30 +0100 Subject: [PATCH 6/6] refactor --- Classes/ZigpyTransport/AppBellows.py | 14 ---------- Classes/ZigpyTransport/AppDeconz.py | 13 --------- Classes/ZigpyTransport/AppGeneric.py | 41 +++++++++++----------------- Classes/ZigpyTransport/AppZnp.py | 12 -------- 4 files changed, 16 insertions(+), 64 deletions(-) diff --git a/Classes/ZigpyTransport/AppBellows.py b/Classes/ZigpyTransport/AppBellows.py index ae51782ef..c0d6c5b7f 100644 --- a/Classes/ZigpyTransport/AppBellows.py +++ b/Classes/ZigpyTransport/AppBellows.py @@ -149,20 +149,6 @@ def handle_leave(self, nwk, ieee): def get_zigpy_version(self): return Classes.ZigpyTransport.AppGeneric.get_zigpy_version(self) - def handle_message( - self, - sender: zigpy.device.Device, - profile: int, - cluster: int, - src_ep: int, - dst_ep: int, - message: bytes, - * , - dst_addressing=None, - )->None: - return Classes.ZigpyTransport.AppGeneric.handle_message(self,sender,profile,cluster,src_ep,dst_ep,message, dst_addressing=dst_addressing) - - def packet_received(self, packet: t.ZigbeePacket) -> None: return Classes.ZigpyTransport.AppGeneric.packet_received(self,packet) diff --git a/Classes/ZigpyTransport/AppDeconz.py b/Classes/ZigpyTransport/AppDeconz.py index d922e3959..e7ace4f73 100644 --- a/Classes/ZigpyTransport/AppDeconz.py +++ b/Classes/ZigpyTransport/AppDeconz.py @@ -142,19 +142,6 @@ def get_device_ieee(self, nwk): def handle_leave(self, nwk, ieee): Classes.ZigpyTransport.AppGeneric.handle_leave(self, nwk, ieee) - def handle_message( - self, - sender: zigpy.device.Device, - profile: int, - cluster: int, - src_ep: int, - dst_ep: int, - message: bytes, - * , - dst_addressing=None, - ) -> None: - return Classes.ZigpyTransport.AppGeneric.handle_message(self,sender,profile,cluster,src_ep,dst_ep,message,dst_addressing=dst_addressing) - def packet_received(self, packet: t.ZigbeePacket) -> None: return Classes.ZigpyTransport.AppGeneric.packet_received(self,packet) diff --git a/Classes/ZigpyTransport/AppGeneric.py b/Classes/ZigpyTransport/AppGeneric.py index 07fce4794..a1d1911ba 100644 --- a/Classes/ZigpyTransport/AppGeneric.py +++ b/Classes/ZigpyTransport/AppGeneric.py @@ -189,65 +189,56 @@ def packet_received(self, packet: t.ZigbeePacket) -> None: hex_message = binascii.hexlify(message).decode("utf-8") dst_addressing = packet.dst.addr_mode if packet.dst else None - write_capture_rx_frames( self, sender, profile, cluster, src_ep, dst_ep, message, binascii.hexlify(message).decode("utf-8"), dst_addressing) + write_capture_rx_frames( self, sender, profile, cluster, src_ep, dst_ep, message, hex_message, dst_addressing) self.log.logging("TransportZigpy", "Debug", "packet_received - %s %s %s %s %s %s %s %s" %( - sender, profile, cluster, src_ep, dst_ep, message, binascii.hexlify(message).decode("utf-8"), dst_addressing)) + sender, profile, cluster, src_ep, dst_ep, message, hex_message, dst_addressing)) if sender.nwk == 0x0000: # When coming from coordinator we have to send it back to zigpy self.log.logging("TransportZigpy", "Debug", "packet_received from Controller Sender: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( - str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) + str(sender.nwk), profile, cluster, src_ep, dst_ep, hex_message)) super(type(self),self).packet_received(packet) if cluster == 0x8036: # This has been handle via on_zdo_mgmt_permitjoin_rsp() self.log.logging("TransportZigpy", "Debug", "packet_received 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( - str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) - self.callBackFunction( build_plugin_8014_frame_content(self, str(sender), binascii.hexlify(message).decode("utf-8") ) ) + str(sender.nwk), profile, cluster, src_ep, dst_ep, hex_message)) + self.callBackFunction( build_plugin_8014_frame_content(self, str(sender), hex_message ) ) super(type(self),self).packet_received(packet) return if cluster == 0x8034: # This has been handle via on_zdo_mgmt_leave_rsp() self.log.logging("TransportZigpy", "Debug", "packet_received 0x8036: %s Profile: %04x Cluster: %04x srcEp: %02x dstEp: %02x message: %s" %( - str(sender.nwk), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"))) - self.callBackFunction( build_plugin_8047_frame_content(self, str(sender), binascii.hexlify(message).decode("utf-8")) ) + str(sender.nwk), profile, cluster, src_ep, dst_ep, hex_message)) + self.callBackFunction( build_plugin_8047_frame_content(self, str(sender), hex_message) ) return addr = None if sender.nwk is not None: - addr_mode = 0x02 addr = sender.nwk.serialize()[::-1].hex() - if profile and cluster: - self.log.logging( "TransportZigpy", "Debug", "packet_received device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( - str(sender), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi)), - elif sender.ieee is not None: addr = "%016x" % t.uint64_t.deserialize(sender.ieee.serialize())[0] - addr_mode = 0x03 - if profile and cluster: - self.log.logging( "TransportZigpy", "Debug", "packet_received device 1: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( - str(sender), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi)), - - if sender.lqi is None: - sender.lqi = 0x00 + + addr_mode = 0x02 if sender.nwk is not None else 0x03 + sender.lqi = sender.lqi or 0x00 # Let's force profile to ZDP if eps == 0x00 if src_ep == dst_ep == 0x00: profile = 0x0000 if profile is not None and cluster is not None: - self.log.logging( "TransportZigpy", "Debug", "packet_received device 2: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( - str(addr), profile, cluster, src_ep, dst_ep, binascii.hexlify(message).decode("utf-8"), sender.lqi), ) + self.log.logging( "TransportZigpy", "Debug", "packet_received device: %s Profile: %04x Cluster: %04x sEP: %s dEp: %s message: %s lqi: %s" % ( + str(addr), profile, cluster, src_ep, dst_ep, hex_message, sender.lqi), ) if addr is not None: plugin_frame = build_plugin_8002_frame_content(self, addr, profile, cluster, src_ep, dst_ep, message, sender.lqi, src_addrmode=addr_mode) self.log.logging("TransportZigpy", "Debug", "packet_received Sender: %s frame for plugin: %s" % (addr, plugin_frame)) - self.callBackFunction(plugin_frame) - else: - self.log.logging( "TransportZigpy", "Error", "packet_received - Issue with sender is %s %s" % ( - sender.nwk, sender.ieee), ) + return self.callBackFunction(plugin_frame) + + self.log.logging( "TransportZigpy", "Error", "packet_received - Issue with sender is %s %s" % ( + sender.nwk, sender.ieee), ) return diff --git a/Classes/ZigpyTransport/AppZnp.py b/Classes/ZigpyTransport/AppZnp.py index b9d2b408d..b6de747e8 100644 --- a/Classes/ZigpyTransport/AppZnp.py +++ b/Classes/ZigpyTransport/AppZnp.py @@ -117,18 +117,6 @@ def handle_leave(self, nwk, ieee): def get_zigpy_version(self): return Classes.ZigpyTransport.AppGeneric.get_zigpy_version(self) - def handle_message( - self, - sender: zigpy.device.Device, - profile: int, - cluster: int, - src_ep: int, - dst_ep: int, - message: bytes, - dst_addressing=None, - ) -> None: - return Classes.ZigpyTransport.AppGeneric.handle_message(self,sender,profile,cluster,src_ep,dst_ep,message, dst_addressing=dst_addressing) - def packet_received(self, packet: t.ZigbeePacket) -> None: return Classes.ZigpyTransport.AppGeneric.packet_received(self,packet)