Skip to content

Commit 765324b

Browse files
committed
Ensure cover state restore and transition timer handles are cancelled upon entity removal
1 parent 8a251dd commit 765324b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

zha/application/platforms/cover/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ def on_add(self) -> None:
209209
)
210210
)
211211

212+
async def on_remove(self) -> None:
213+
"""Cancel tasks and timers this entity owns."""
214+
await super().on_remove()
215+
if self._lift_transition_timer:
216+
self._lift_transition_timer.cancel()
217+
if self._tilt_transition_timer:
218+
self._tilt_transition_timer.cancel()
219+
212220
def restore_external_state_attributes(
213221
self,
214222
*,
@@ -233,10 +241,11 @@ def restore_external_state_attributes(
233241
return
234242

235243
self._state = state
236-
self._loop.call_later(
244+
restored_state_timer = self._loop.call_later(
237245
DEFAULT_MOVEMENT_TIMEOUT,
238246
functools.partial(self._determine_cover_state, refresh=True),
239247
)
248+
self._on_remove_callbacks.append(restored_state_timer.cancel)
240249

241250
@property
242251
def supported_features(self) -> CoverEntityFeature:

0 commit comments

Comments
 (0)