2022-01-02 20:36:14 +00:00
|
|
|
"""Support for Oncue binary sensors."""
|
2024-03-08 14:04:07 +00:00
|
|
|
|
2022-01-02 20:36:14 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from aiooncue import OncueDevice
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
BinarySensorDeviceClass,
|
|
|
|
BinarySensorEntity,
|
|
|
|
BinarySensorEntityDescription,
|
|
|
|
)
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2023-02-09 19:15:37 +00:00
|
|
|
from homeassistant.const import EntityCategory
|
2022-01-02 20:36:14 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
from .entity import OncueEntity
|
|
|
|
|
|
|
|
SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key="NetworkConnectionEstablished",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
SENSOR_MAP = {description.key: description for description in SENSOR_TYPES}
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
|
|
|
"""Set up sensors."""
|
2022-12-29 11:26:17 +00:00
|
|
|
coordinator: DataUpdateCoordinator[dict[str, OncueDevice]] = hass.data[DOMAIN][
|
|
|
|
config_entry.entry_id
|
|
|
|
]
|
2022-01-02 20:36:14 +00:00
|
|
|
entities: list[OncueBinarySensorEntity] = []
|
2022-12-29 11:26:17 +00:00
|
|
|
devices = coordinator.data
|
2022-01-02 20:36:14 +00:00
|
|
|
for device_id, device in devices.items():
|
|
|
|
entities.extend(
|
|
|
|
OncueBinarySensorEntity(
|
|
|
|
coordinator, device_id, device, sensor, SENSOR_MAP[key]
|
|
|
|
)
|
|
|
|
for key, sensor in device.sensors.items()
|
|
|
|
if key in SENSOR_MAP
|
|
|
|
)
|
|
|
|
|
|
|
|
async_add_entities(entities)
|
|
|
|
|
|
|
|
|
|
|
|
class OncueBinarySensorEntity(OncueEntity, BinarySensorEntity):
|
|
|
|
"""Representation of an Oncue binary sensor."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return the binary sensor state."""
|
|
|
|
return self._oncue_value == "true"
|