Cancel entity timers. (#55141)

pull/55215/head
jan iversen 2021-08-25 14:49:37 +02:00 committed by GitHub
parent 2271f3b5f9
commit d4064e7044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -87,9 +87,10 @@ class BasePlatform(Entity):
async def async_base_added_to_hass(self):
"""Handle entity which will be added."""
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._hub.entity_timers.append(cancel_func)
class BaseStructPlatform(BasePlatform, RestoreEntity):

View File

@ -20,7 +20,7 @@ from homeassistant.const import (
CONF_TYPE,
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.event import async_call_later
@ -189,6 +189,8 @@ class ModbusHub:
name: str
entity_timers: list[CALLBACK_TYPE] = []
def __init__(self, hass, client_config):
"""Initialize the Modbus hub."""
@ -288,6 +290,9 @@ class ModbusHub:
if self._async_cancel_listener:
self._async_cancel_listener()
self._async_cancel_listener = None
for call in self.entity_timers:
call()
self.entity_timers = []
if self._client:
try:
self._client.close()