mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Cancel entity timers. (#55141)
This commit is contained in:
parent
2271f3b5f9
commit
d4064e7044
@ -87,9 +87,10 @@ class BasePlatform(Entity):
|
|||||||
async def async_base_added_to_hass(self):
|
async def async_base_added_to_hass(self):
|
||||||
"""Handle entity which will be added."""
|
"""Handle entity which will be added."""
|
||||||
if self._scan_interval > 0:
|
if self._scan_interval > 0:
|
||||||
async_track_time_interval(
|
cancel_func = async_track_time_interval(
|
||||||
self.hass, self.async_update, timedelta(seconds=self._scan_interval)
|
self.hass, self.async_update, timedelta(seconds=self._scan_interval)
|
||||||
)
|
)
|
||||||
|
self._hub.entity_timers.append(cancel_func)
|
||||||
|
|
||||||
|
|
||||||
class BaseStructPlatform(BasePlatform, RestoreEntity):
|
class BaseStructPlatform(BasePlatform, RestoreEntity):
|
||||||
|
@ -20,7 +20,7 @@ from homeassistant.const import (
|
|||||||
CONF_TYPE,
|
CONF_TYPE,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import CALLBACK_TYPE, callback
|
||||||
from homeassistant.helpers.discovery import async_load_platform
|
from homeassistant.helpers.discovery import async_load_platform
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
@ -189,6 +189,8 @@ class ModbusHub:
|
|||||||
|
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
entity_timers: list[CALLBACK_TYPE] = []
|
||||||
|
|
||||||
def __init__(self, hass, client_config):
|
def __init__(self, hass, client_config):
|
||||||
"""Initialize the Modbus hub."""
|
"""Initialize the Modbus hub."""
|
||||||
|
|
||||||
@ -288,6 +290,9 @@ class ModbusHub:
|
|||||||
if self._async_cancel_listener:
|
if self._async_cancel_listener:
|
||||||
self._async_cancel_listener()
|
self._async_cancel_listener()
|
||||||
self._async_cancel_listener = None
|
self._async_cancel_listener = None
|
||||||
|
for call in self.entity_timers:
|
||||||
|
call()
|
||||||
|
self.entity_timers = []
|
||||||
if self._client:
|
if self._client:
|
||||||
try:
|
try:
|
||||||
self._client.close()
|
self._client.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user