Skip to content

Commit

Permalink
request a plugin restart after 8 communication lost (#1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 authored Dec 5, 2024
1 parent 397247b commit 48ffa43
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions Classes/ZigpyTransport/AppBellows.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async def startup(self, statistics, HardwareID, pluginconf, use_of_zigpy_persist

self.shutting_down = False
self.restarting = False
self.radio_lost_cnt = 0

try:
await self.connect()
Expand Down
1 change: 1 addition & 0 deletions Classes/ZigpyTransport/AppDeconz.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async def startup(self, statistics, HardwareID, pluginconf, use_of_zigpy_persist

self.shutting_down = False
self.restarting = False
self.radio_lost_cnt = 0

await asyncio.sleep( 3 )

Expand Down
7 changes: 6 additions & 1 deletion Classes/ZigpyTransport/AppGeneric.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,15 @@ async def _create_backup(self) -> None:
def connection_lost(self, exc: Exception) -> None:
"""Handle connection lost event."""
LOGGER.warning( "+ Connection to the radio was lost (trying to recover): %s %r" %(type(exc), exc) )
self.radio_lost_cnt += 1

super(type(self),self).connection_lost(exc)

if not self.shutting_down and not self.restarting and isinstance( exc, serial.serialutil.SerialException):
if self.radio_lost_cnt > 8:
LOGGER.error( "++++++++++++++++++++++ Connection to coordinator failed too many errors, let's restart the plugin")
self.callBackRestartPlugin()

elif not self.shutting_down and not self.restarting and isinstance( exc, serial.serialutil.SerialException):
LOGGER.error( "++++++++++++++++++++++ Connection to coordinator failed on Serial, let's restart the plugin")
LOGGER.warning( f"--> : self.shutting_down: {self.shutting_down}, {self.restarting}")

Expand Down
1 change: 1 addition & 0 deletions Classes/ZigpyTransport/AppZnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async def startup(self, statistics, HardwareID, pluginconf, use_of_zigpy_persist

self.shutting_down = False
self.restarting = False
self.radio_lost_cnt = 0

# Pipiche : 24-Oct-2022 Disabling CONF_MAX_CONCURRENT_REQUESTS so the default will be used ( 16 )
# self.znp_config[znp_conf.CONF_MAX_CONCURRENT_REQUESTS] = 2
Expand Down
2 changes: 2 additions & 0 deletions Classes/ZigpyTransport/zigpyThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ async def _send_and_retry(self, Function, destination, Profile, Cluster, _nwkid,
try:
self.log.logging("TransportZigpy", "Debug", f"_send_and_retry: {_ieee} {Profile:X} {Cluster:X} - AckIsDisable: {ack_is_disable} extended_timeout: {extended_timeout} Attempts: {attempt}/{max_retry}")
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)
self.radio_lost_cnt = 0

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}' ({type(e)}))"
Expand All @@ -844,6 +845,7 @@ async def _send_and_retry(self, Function, destination, Profile, Cluster, _nwkid,
error_log_message = f"_send_and_retry - Unexpected Exception - {Function} {_ieee}/0x{_nwkid} 0x{Profile:X} 0x{Cluster:X} payload: {payload} AckIsDisable: {ack_is_disable} RETRY: {attempt}/{max_retry} ({error})"
self.log.logging("TransportZigpy", "Error", error_log_message)
result = 0xB6
break

else:
# Success
Expand Down

0 comments on commit 48ffa43

Please sign in to comment.