mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix exception when shutting down DSMR (#55441)
* Fix exception when shutting down DSMR * Update homeassistant/components/dsmr/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
8faec3da8d
commit
7e9f8de7e0
@ -25,7 +25,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import CoreState, 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, EventType, StateType
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -146,8 +146,15 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
if transport:
|
if transport:
|
||||||
# Register listener to close transport on HA shutdown
|
# Register listener to close transport on HA shutdown
|
||||||
|
@callback
|
||||||
|
def close_transport(_event: EventType) -> None:
|
||||||
|
"""Close the transport on HA shutdown."""
|
||||||
|
if not transport:
|
||||||
|
return
|
||||||
|
transport.close()
|
||||||
|
|
||||||
stop_listener = hass.bus.async_listen_once(
|
stop_listener = hass.bus.async_listen_once(
|
||||||
EVENT_HOMEASSISTANT_STOP, transport.close
|
EVENT_HOMEASSISTANT_STOP, close_transport
|
||||||
)
|
)
|
||||||
|
|
||||||
# Wait for reader to close
|
# Wait for reader to close
|
||||||
|
Loading…
x
Reference in New Issue
Block a user