From 7cb25e971094da7872e77cd2068b0c9cac38f40a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 7 May 2023 01:28:10 +0200 Subject: [PATCH] Fix lingering timer in generic_hygrostat (#92575) --- .../components/generic_hygrostat/humidifier.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/generic_hygrostat/humidifier.py b/homeassistant/components/generic_hygrostat/humidifier.py index c1ebc948b94..a6e76330f29 100644 --- a/homeassistant/components/generic_hygrostat/humidifier.py +++ b/homeassistant/components/generic_hygrostat/humidifier.py @@ -172,7 +172,11 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity): ) if self._keep_alive: - async_track_time_interval(self.hass, self._async_operate, self._keep_alive) + self.async_on_remove( + async_track_time_interval( + self.hass, self._async_operate, self._keep_alive + ) + ) async def _async_startup(event): """Init on startup.""" @@ -216,6 +220,12 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity): await _async_startup(None) # init the sensor + async def async_will_remove_from_hass(self) -> None: + """Run when entity will be removed from hass.""" + if self._remove_stale_tracking: + self._remove_stale_tracking() + return await super().async_will_remove_from_hass() + @property def available(self): """Return True if entity is available."""