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
1 changed files with 9 additions and 2 deletions
|
@ -25,7 +25,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import CoreState, HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
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 .const import (
|
||||
|
@ -146,8 +146,15 @@ async def async_setup_entry(
|
|||
|
||||
if transport:
|
||||
# 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(
|
||||
EVENT_HOMEASSISTANT_STOP, transport.close
|
||||
EVENT_HOMEASSISTANT_STOP, close_transport
|
||||
)
|
||||
|
||||
# Wait for reader to close
|
||||
|
|
Loading…
Add table
Reference in a new issue