Switchbot Cloud: Fixed binary sensors didn't update automatically (#158434)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Samuel Xiao
2025-12-12 17:18:56 +00:00
committed by Franck Nijhof
co-authored by Joost Lekkerkerker
parent 70786a1d90
commit 1d289c0083
@@ -147,16 +147,16 @@ class SwitchBotCloudBinarySensor(SwitchBotCloudEntity, BinarySensorEntity):
self.entity_description = description
self._attr_unique_id = f"{device.device_id}_{description.key}"
@property
def is_on(self) -> bool | None:
def _set_attributes(self) -> None:
"""Set attributes from coordinator data."""
if not self.coordinator.data:
return None
return
if self.entity_description.value_fn:
return self.entity_description.value_fn(self.coordinator.data)
self._attr_is_on = self.entity_description.value_fn(self.coordinator.data)
return
return (
self._attr_is_on = (
self.coordinator.data.get(self.entity_description.key)
== self.entity_description.on_value
)