Skip to content

Commit e98096c

Browse files
committed
enable / disable
1 parent 5dc39a2 commit e98096c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

zha/application/platforms/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ def extra_state_attribute_names(self) -> set[str] | None:
192192
def enable(self) -> None:
193193
"""Enable the entity."""
194194
self.enabled = True
195+
self.maybe_emit_state_changed_event()
195196

196197
def disable(self) -> None:
197198
"""Disable the entity."""
198199
self.enabled = False
200+
self.maybe_emit_state_changed_event()
199201

200202
async def on_remove(self) -> None:
201203
"""Cancel tasks and timers this entity owns."""
@@ -501,6 +503,7 @@ def __init__(
501503
)
502504
self._attr_device_class = self._entity_info.device_class
503505
self._attr_state_class = self._entity_info.state_class
506+
self._tasks: list[asyncio.Task] = []
504507

505508
@functools.cached_property
506509
def info_object(self) -> BaseEntityInfoType:
@@ -516,6 +519,23 @@ def state(self) -> dict[str, Any]:
516519
def state(self, value: dict[str, Any]) -> None:
517520
"""Set the state of the entity."""
518521
self._entity_info.state = value
522+
self._attr_enabled = self._entity_info.enabled
523+
524+
def enable(self) -> None:
525+
"""Enable the entity."""
526+
task = asyncio.create_task(
527+
self._device.gateway.entities.enable(self._entity_info)
528+
)
529+
self._tasks.append(task)
530+
task.add_done_callback(self._tasks.remove)
531+
532+
def disable(self) -> None:
533+
"""Disable the entity."""
534+
task = asyncio.create_task(
535+
self._device.gateway.entities.disable(self._entity_info)
536+
)
537+
self._tasks.append(task)
538+
task.add_done_callback(self._tasks.remove)
519539

520540
async def async_update(self) -> None:
521541
"""Retrieve latest state."""

0 commit comments

Comments
 (0)