Skip to content

Commit

Permalink
Refactor ping devices functions and fix problem with devices not on n…
Browse files Browse the repository at this point in the history
…etwork (#1805)

* rename pingDevices parameter into CheckDeviceHealth
* fix issue introduced by zigpy which provides error code > 255
* remove time stamping, as this is coming from the coordinator (or router) and not then device itself
* refactor timeStamped and updLQI
  • Loading branch information
pipiche38 authored Dec 2, 2024
1 parent 3632731 commit c67caa0
Show file tree
Hide file tree
Showing 10 changed files with 495 additions and 402 deletions.
5 changes: 3 additions & 2 deletions Classes/PluginConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"internetAccess": { "type": "bool", "default": 1, "current": None, "restart": 1, "hidden": False, "Advanced": False, },
"CheckSSLCertificateValidity": { "type": "bool", "default": 0, "current": None, "restart": 1, "hidden": False, "Advanced": False, },
"allowOTA": { "type": "bool", "default": 1, "current": None, "restart": 1, "hidden": True, "Advanced": False, },
"pingDevices": { "type": "bool", "default": 1, "current": None, "restart": 1, "hidden": False, "Advanced": True, },
"CheckDeviceHealth": { "type": "bool", "default": 1, "current": None, "restart": 1, "hidden": False, "Advanced": True, },
"PluginAnalytics": { "type": "bool", "default": -1, "current": None, "restart": 0, "hidden": False, "Advanced": False, },
"DomoticzCustomMenu": { "type": "bool", "default": 1, "current": None, "restart": 1, "hidden": False, "Advanced": False, },
"NightShift": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": False, }
Expand Down Expand Up @@ -127,6 +127,7 @@
"Order": 8,
"param": {
"deviceOffWhenTimeOut": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True, },
"pingDevicesFeq": { "type": "int", "default": 3600, "current": None, "restart": 0, "hidden": False, "Advanced": True, },
"forcePollingAfterAction": { "type": "bool", "default": 1, "current": None, "restart": 0, "hidden": False, "Advanced": True, },
"forcePassiveWidget": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True, },
"allowForceCreationDomoDevice": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": True, "Advanced": True, },
Expand All @@ -146,7 +147,6 @@
"Order": 9,
"param": {
"blueLedOnOff": { "type": "bool", "default": 1, "current": None, "restart": 0, "hidden": False, "Advanced": False, },
"pingDevicesFeq": { "type": "int", "default": 3600, "current": None, "restart": 0, "hidden": False, "Advanced": True, },
"resetPermit2Join": { "type": "bool", "default": 1, "current": None, "restart": 0, "hidden": False, "Advanced": True, },
"Ping": {"type": "bool", "default": 1, "current": None, "restart": 0, "hidden": False, "Advanced": True},
"allowRemoveZigateDevice": { "type": "bool", "default": 1, "current": None, "restart": 0, "hidden": True, "Advanced": True, "ZigpyRadio": "" },
Expand Down Expand Up @@ -266,6 +266,7 @@
"PDM": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True },
"Pairing": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True },
"Philips": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True },
"PingDevices": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True },
"PiZigate": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True },
"Plugin": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True },
"PluginTools": { "type": "bool", "default": 0, "current": None, "restart": 0, "hidden": False, "Advanced": True },
Expand Down
3 changes: 2 additions & 1 deletion Classes/ZigpyTransport/plugin_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def build_plugin_8011_frame_content(self, nwkid, status, lqi):
# MsgSEQ = MsgData[12:14] if MsgLen > 12 else None

lqi = lqi or 0x00
frame_payload = "%02x" % status + nwkid
frame_payload = "%02x" % status
frame_payload += nwkid
return encapsulate_plugin_frame("8011", frame_payload, "%02x" % lqi)

def build_plugin_8014_frame_content(self, nwkid, payload):
Expand Down
12 changes: 5 additions & 7 deletions Classes/ZigpyTransport/zigpyThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,16 +827,16 @@ async def _send_and_retry(self, Function, destination, Profile, Cluster, _nwkid,
result, _ = await zigpy_request(self, destination, Profile, Cluster, sEp, dEp, sequence, payload, ack_is_disable=ack_is_disable, use_ieee=use_ieee, extended_timeout=extended_timeout)

except (asyncio.exceptions.TimeoutError, asyncio.exceptions.CancelledError, AttributeError, DeliveryError) as e:
error_log_message = f"Warning while submitting - {Function} {_ieee}/0x{_nwkid} 0x{Profile:X} 0x{Cluster:X} payload: {payload} AckIsDisable: {ack_is_disable} Retry: {attempt}/{max_retry} with exception ({e})"
error_log_message = f"Warning while submitting - {Function} {_ieee}/0x{_nwkid} 0x{Profile:X} 0x{Cluster:X} payload: {payload} AckIsDisable: {ack_is_disable} Retry: {attempt}/{max_retry} with exception: '{e}' ({type(e)}))"
self.log.logging("TransportZigpy", "Log", error_log_message)

if await _retry_or_not(self, attempt, max_retry, Function, sequence, ack_is_disable, _ieee, _nwkid, destination, e):
self.statistics._reTx += 1
if isinstance(e, asyncio.exceptions.TimeoutError):
self.statistics._TOdata += 1
continue
else:
self.statistics._ackKO += 1
result = 0xB6
break

except Exception as error:
Expand All @@ -848,7 +848,7 @@ async def _send_and_retry(self, Function, destination, Profile, Cluster, _nwkid,
else:
# Success
if delay_after_command_sent:
self.log.logging("TransportZigpy", "Log", f"sleeping {delay_after_command_sent} as per configured!!")
self.log.logging("TransportZigpy", "Debug", f"sleeping {delay_after_command_sent} as per configured!!")
await asyncio.sleep( delay_after_command_sent )

handle_transport_result(self, Function, sequence, result, ack_is_disable, _ieee, _nwkid, destination.lqi)
Expand Down Expand Up @@ -953,14 +953,14 @@ async def _retry_or_not(self, attempt, max_retry, Function, sequence,ack_is_disa
return True

# Stop here as we have exceed the max retrys
result = int(e.status) if hasattr(e, 'status') else 0xB6
self.log.logging("TransportZigpy", "Log", f"_retry_or_not: result: {e} ({(type(e))})")
result = min(int(e.status) if hasattr(e, 'status') else 0xB6, 0xB6)

handle_transport_result(self, Function, sequence, result, ack_is_disable, _ieee, _nwkid, destination.lqi)
return False


def handle_transport_result(self, Function, sequence, result, ack_is_disable, _ieee, _nwkid, lqi):
self.log.logging("TransportZigpy", "Debug", f"handle_transport_result - {Function} - {_nwkid} - AckIsDisable: {ack_is_disable} Result: {result}")
if ack_is_disable:
# As Ack is disable, we cannot conclude that the target device is in trouble.
# this could be the coordinator itself, or the next hop.
Expand All @@ -970,11 +970,9 @@ def handle_transport_result(self, Function, sequence, result, ack_is_disable, _i

if result == 0x00 and _ieee in self._currently_not_reachable:
self._currently_not_reachable.remove(_ieee)
self.log.logging("TransportZigpy", "Debug", f"handle_transport_result -removing {_ieee} to not_reachable queue")

elif result != 0x00 and _ieee not in self._currently_not_reachable:
# Mark the ieee has not reachable.
self.log.logging("TransportZigpy", "Debug", f"handle_transport_result -adding {_ieee} to not_reachable queue")
self._currently_not_reachable.append(_ieee)


Expand Down
Loading

0 comments on commit c67caa0

Please sign in to comment.