Improve DSMR shutdown (#54922)

This commit is contained in:
Erik Montnemery 2021-08-20 15:54:05 +02:00 committed by GitHub
parent fe6c896754
commit e134246cbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,7 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP,
VOLUME_CUBIC_METERS,
)
from homeassistant.core import CoreState, HomeAssistant, callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, StateType
@ -139,7 +139,7 @@ async def async_setup_entry(
transport = None
protocol = None
while hass.state != CoreState.stopping:
while hass.is_running:
# Start DSMR asyncio.Protocol reader
try:
transport, protocol = await hass.loop.create_task(reader_factory())
@ -154,7 +154,7 @@ async def async_setup_entry(
await protocol.wait_closed()
# Unexpected disconnect
if not hass.is_stopping:
if hass.is_running:
stop_listener()
transport = None
@ -181,7 +181,7 @@ async def async_setup_entry(
entry.data.get(CONF_RECONNECT_INTERVAL, DEFAULT_RECONNECT_INTERVAL)
)
except CancelledError:
if stop_listener:
if stop_listener and hass.is_running:
stop_listener() # pylint: disable=not-callable
if transport: