Skip to content

Commit

Permalink
Block client switches should rely only on events for state changes (#…
Browse files Browse the repository at this point in the history
…81883)

fixes undefined
  • Loading branch information
Kane610 committed Nov 15, 2022
1 parent c65f894 commit 1331a37
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions homeassistant/components/unifi/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class UnifiEntityDescription(SwitchEntityDescription, UnifiEntityLoader[Handler,
"""Class describing UniFi switch entity."""

custom_subscribe: Callable[[aiounifi.Controller], Subscription] | None = None
only_event_for_state_change: bool = False


ENTITY_DESCRIPTIONS: tuple[UnifiEntityDescription, ...] = (
Expand All @@ -198,6 +199,7 @@ class UnifiEntityDescription(SwitchEntityDescription, UnifiEntityLoader[Handler,
is_on_fn=lambda api, client: not client.blocked,
name_fn=lambda client: None,
object_fn=lambda api, obj_id: api.clients[obj_id],
only_event_for_state_change=True,
supported_fn=lambda api, obj_id: True,
unique_id_fn=lambda obj_id: f"block-{obj_id}",
),
Expand Down Expand Up @@ -400,8 +402,9 @@ def async_signalling_callback(self, event: ItemEvent, obj_id: str) -> None:
self.hass.async_create_task(self.remove_item({self._obj_id}))
return

obj = description.object_fn(self.controller.api, self._obj_id)
self._attr_is_on = description.is_on_fn(self.controller.api, obj)
if not description.only_event_for_state_change:
obj = description.object_fn(self.controller.api, self._obj_id)
self._attr_is_on = description.is_on_fn(self.controller.api, obj)
self._attr_available = description.available_fn(self.controller, self._obj_id)
self.async_write_ha_state()

Expand Down

0 comments on commit 1331a37

Please sign in to comment.