2020-09-27 13:44:21 -04:00
|
|
|
"""Support for Goal Zero Yeti Sensors."""
|
2024-03-08 14:52:48 +01:00
|
|
|
|
2021-08-18 22:24:44 -04:00
|
|
|
from __future__ import annotations
|
2020-09-27 13:44:21 -04:00
|
|
|
|
2021-10-14 18:20:08 -04:00
|
|
|
from typing import cast
|
|
|
|
|
|
2021-08-18 22:24:44 -04:00
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-13 05:24:57 +01:00
|
|
|
BinarySensorDeviceClass,
|
2021-08-18 22:24:44 -04:00
|
|
|
BinarySensorEntity,
|
|
|
|
|
BinarySensorEntityDescription,
|
|
|
|
|
)
|
2023-02-09 20:15:37 +01:00
|
|
|
from homeassistant.const import EntityCategory
|
2021-08-18 22:24:44 -04:00
|
|
|
from homeassistant.core import HomeAssistant
|
2025-02-10 21:08:03 +01:00
|
|
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
2021-08-18 22:24:44 -04:00
|
|
|
|
2024-06-12 10:52:18 -04:00
|
|
|
from .coordinator import GoalZeroConfigEntry
|
2022-06-04 21:50:38 -04:00
|
|
|
from .entity import GoalZeroEntity
|
2020-09-27 13:44:21 -04:00
|
|
|
|
|
|
|
|
PARALLEL_UPDATES = 0
|
|
|
|
|
|
2021-08-18 22:24:44 -04:00
|
|
|
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
|
key="backlight",
|
2023-10-06 08:01:21 -04:00
|
|
|
translation_key="backlight",
|
2021-08-18 22:24:44 -04:00
|
|
|
),
|
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
|
key="app_online",
|
2023-10-06 08:01:21 -04:00
|
|
|
translation_key="app_online",
|
2021-12-13 05:24:57 +01:00
|
|
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
2021-08-18 22:24:44 -04:00
|
|
|
),
|
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
|
key="isCharging",
|
2021-12-13 05:24:57 +01:00
|
|
|
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
|
2021-08-18 22:24:44 -04:00
|
|
|
),
|
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
|
key="inputDetected",
|
2023-10-06 08:01:21 -04:00
|
|
|
translation_key="input_detected",
|
2021-12-13 05:24:57 +01:00
|
|
|
device_class=BinarySensorDeviceClass.POWER,
|
2021-08-18 22:24:44 -04:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
2020-09-27 13:44:21 -04:00
|
|
|
|
2021-08-18 22:24:44 -04:00
|
|
|
async def async_setup_entry(
|
2024-06-12 10:52:18 -04:00
|
|
|
hass: HomeAssistant,
|
|
|
|
|
entry: GoalZeroConfigEntry,
|
2025-02-10 21:08:03 +01:00
|
|
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
2021-08-18 22:24:44 -04:00
|
|
|
) -> None:
|
2020-09-27 13:44:21 -04:00
|
|
|
"""Set up the Goal Zero Yeti sensor."""
|
2021-07-21 02:53:53 -04:00
|
|
|
async_add_entities(
|
2024-06-12 10:52:18 -04:00
|
|
|
GoalZeroBinarySensor(entry.runtime_data, description)
|
2021-08-18 22:24:44 -04:00
|
|
|
for description in BINARY_SENSOR_TYPES
|
2021-07-21 02:53:53 -04:00
|
|
|
)
|
2020-09-27 13:44:21 -04:00
|
|
|
|
|
|
|
|
|
2022-06-04 21:50:38 -04:00
|
|
|
class GoalZeroBinarySensor(GoalZeroEntity, BinarySensorEntity):
|
2020-09-27 13:44:21 -04:00
|
|
|
"""Representation of a Goal Zero Yeti sensor."""
|
|
|
|
|
|
|
|
|
|
@property
|
2021-07-21 02:53:53 -04:00
|
|
|
def is_on(self) -> bool:
|
2021-10-15 17:34:13 -04:00
|
|
|
"""Return True if the service is on."""
|
2022-06-04 21:50:38 -04:00
|
|
|
return cast(bool, self._api.data[self.entity_description.key] == 1)
|