Guard unbound var for DSMR (#44673)

This commit is contained in:
Paulus Schoutsen 2021-01-02 01:34:10 +01:00 committed by GitHub
parent 508d33a220
commit a2ca08905f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,6 +197,10 @@ async def async_setup_entry(
async def connect_and_reconnect(): async def connect_and_reconnect():
"""Connect to DSMR and keep reconnecting until Home Assistant stops.""" """Connect to DSMR and keep reconnecting until Home Assistant stops."""
stop_listener = None
transport = None
protocol = None
while hass.state != CoreState.stopping: while hass.state != CoreState.stopping:
# Start DSMR asyncio.Protocol reader # Start DSMR asyncio.Protocol reader
try: try:
@ -212,8 +216,7 @@ async def async_setup_entry(
await protocol.wait_closed() await protocol.wait_closed()
# Unexpected disconnect # Unexpected disconnect
if transport: if not hass.is_stopping:
# remove listener
stop_listener() stop_listener()
transport = None transport = None
@ -234,7 +237,7 @@ async def async_setup_entry(
protocol = None protocol = None
except CancelledError: except CancelledError:
if stop_listener: if stop_listener:
stop_listener() stop_listener() # pylint: disable=not-callable
if transport: if transport:
transport.close() transport.close()