"""Support for Smart Home binary sensors.""" from __future__ import annotations import logging from typing import Any from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN, DATA_COORDINATOR from .coordinator import SmartHomeDataUpdateCoordinator from .entity import SmartHomeEntity _LOGGER = logging.getLogger(__name__) async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up Smart Home binary sensors.""" coordinator: SmartHomeDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR] entities = [] for device_id, device in coordinator._devices.items(): if device["device_type"] == "binary_sensor": entities.append(SmartHomeBinarySensor(coordinator, device_id)) async_add_entities(entities) class SmartHomeBinarySensor(SmartHomeEntity, BinarySensorEntity): """Representation of a Smart Home binary sensor.""" @property def is_on(self) -> bool | None: """Return true if the binary sensor is on.""" return self.device_state.get("state", False)