Skip to content

Binary Sensor

A single connectivity binary sensor derived from whether the last GET /state succeeded. It does not make an independent GET /ok request — the coordinator's existing poll result is reused.

The sensor becomes off (disconnected) after _FAILURE_GRACE (3) consecutive poll failures.

Reference

binary_sensor

Classes

SunRiserConnectivitySensor

Bases: CoordinatorEntity[SunRiserCoordinator], BinarySensorEntity

Reports whether the most recent GET /ok refresh returned OK.

Source code in custom_components/sunriser/binary_sensor.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class SunRiserConnectivitySensor(
    CoordinatorEntity[SunRiserCoordinator], BinarySensorEntity
):
    """Reports whether the most recent GET /ok refresh returned OK."""

    _attr_has_entity_name = True
    _attr_translation_key = "connectivity"
    _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
    _attr_entity_category = EntityCategory.DIAGNOSTIC

    def __init__(self, coordinator: SunRiserCoordinator, entry: ConfigEntry) -> None:
        super().__init__(coordinator)
        self._attr_unique_id = f"{entry.entry_id}_connectivity"
        self._attr_device_info = coordinator.device_info

    @property
    def is_on(self) -> bool:
        if self.coordinator.data is None:
            return False
        return bool(self.coordinator.data.get("ok"))