Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Oct 29, 2023
1 parent 2ad4e42 commit d60261a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 64 deletions.
14 changes: 0 additions & 14 deletions Classes/ZigpyTransport/AppBellows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 0 additions & 13 deletions Classes/ZigpyTransport/AppDeconz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
41 changes: 16 additions & 25 deletions Classes/ZigpyTransport/AppGeneric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 0 additions & 12 deletions Classes/ZigpyTransport/AppZnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d60261a

Please sign in to comment.