mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix DSMR startup logic (#55051)
This commit is contained in:
parent
2dd4de060b
commit
ee009cc332
@ -22,7 +22,7 @@ from homeassistant.const import (
|
|||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
VOLUME_CUBIC_METERS,
|
VOLUME_CUBIC_METERS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import CoreState, HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, StateType
|
from homeassistant.helpers.typing import ConfigType, StateType
|
||||||
@ -139,7 +139,7 @@ async def async_setup_entry(
|
|||||||
transport = None
|
transport = None
|
||||||
protocol = None
|
protocol = None
|
||||||
|
|
||||||
while hass.is_running:
|
while hass.state == CoreState.not_running or hass.is_running:
|
||||||
# Start DSMR asyncio.Protocol reader
|
# Start DSMR asyncio.Protocol reader
|
||||||
try:
|
try:
|
||||||
transport, protocol = await hass.loop.create_task(reader_factory())
|
transport, protocol = await hass.loop.create_task(reader_factory())
|
||||||
@ -154,7 +154,7 @@ async def async_setup_entry(
|
|||||||
await protocol.wait_closed()
|
await protocol.wait_closed()
|
||||||
|
|
||||||
# Unexpected disconnect
|
# Unexpected disconnect
|
||||||
if hass.is_running:
|
if hass.state == CoreState.not_running or hass.is_running:
|
||||||
stop_listener()
|
stop_listener()
|
||||||
|
|
||||||
transport = None
|
transport = None
|
||||||
@ -181,7 +181,9 @@ async def async_setup_entry(
|
|||||||
entry.data.get(CONF_RECONNECT_INTERVAL, DEFAULT_RECONNECT_INTERVAL)
|
entry.data.get(CONF_RECONNECT_INTERVAL, DEFAULT_RECONNECT_INTERVAL)
|
||||||
)
|
)
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
if stop_listener and hass.is_running:
|
if stop_listener and (
|
||||||
|
hass.state == CoreState.not_running or hass.is_running
|
||||||
|
):
|
||||||
stop_listener() # pylint: disable=not-callable
|
stop_listener() # pylint: disable=not-callable
|
||||||
|
|
||||||
if transport:
|
if transport:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user