Skip to content

Commit

Permalink
Restart plugin when NcpFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Jan 26, 2025
1 parent c2298f5 commit 4f2f45c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Classes/ZigpyTransport/AppGeneric.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ 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) )

super(type(self),self).connection_lost(exc)
import bellows.ash # pylint: disable=import-outside-toplevel

LOGGER.warning( "+ Connection to the radio was lost (trying to recover): %s %r" %(type(exc), exc) )

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

if isinstance( exc, (serial.serialutil.SerialException, TimeoutError, bellows.ash.NcpFailure)):
LOGGER.error( "++++++++++++++++++++++ Connection to coordinator lost, plugin restart required")
self.restarting = True
self.callBackRestartPlugin()

Expand Down

0 comments on commit 4f2f45c

Please sign in to comment.