Fix lingering timer in lifx (#92476)

* Fix lingering timer in lifx

* Remove duplicate code
This commit is contained in:
epenet 2023-05-04 14:06:38 +02:00 committed by GitHub
parent a73a66bb0c
commit 8a9b9c35e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -170,9 +170,7 @@ class LIFXLight(LIFXEntity, LightEntity):
async def update_during_transition(self, when: int) -> None:
"""Update state at the start and end of a transition."""
if self.postponed_update:
self.postponed_update()
self.postponed_update = None
self._cancel_postponed_update()
# Transition has started
self.async_write_ha_state()
@ -327,6 +325,17 @@ class LIFXLight(LIFXEntity, LightEntity):
)
return await super().async_added_to_hass()
def _cancel_postponed_update(self) -> None:
"""Cancel postponed update, if applicable."""
if self.postponed_update:
self.postponed_update()
self.postponed_update = None
async def async_will_remove_from_hass(self) -> None:
"""Run when entity will be removed from hass."""
self._cancel_postponed_update()
return await super().async_will_remove_from_hass()
class LIFXWhite(LIFXLight):
"""Representation of a white-only LIFX light."""