mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Guard unbound var for DSMR (#44673)
This commit is contained in:
parent
508d33a220
commit
a2ca08905f
@ -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:
|
||||||
@ -211,10 +215,9 @@ async def async_setup_entry(
|
|||||||
# Wait for reader to close
|
# Wait for reader to close
|
||||||
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
|
||||||
protocol = None
|
protocol = 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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user