"""Binary sensor for Midea Lan.""" from typing import override from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, BinarySensorEntity, BinarySensorEntityDescription, ) from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .entity import MideaConfigEntry, MideaEntity PARALLEL_UPDATES = 0 BINARY_SENSORS: list[BinarySensorEntityDescription] = [ BinarySensorEntityDescription( key="current_radar", device_class=BinarySensorDeviceClass.MOTION, ), BinarySensorEntityDescription( key="door", device_class=BinarySensorDeviceClass.OPENING, ), BinarySensorEntityDescription( key="rinse_aid", translation_key="rinse_aid", device_class=BinarySensorDeviceClass.PROBLEM, entity_category=EntityCategory.DIAGNOSTIC, ), BinarySensorEntityDescription( key="salt", translation_key="salt", device_class=BinarySensorDeviceClass.PROBLEM, entity_category=EntityCategory.DIAGNOSTIC, ), BinarySensorEntityDescription( key="tank_full", translation_key="tank_full", device_class=BinarySensorDeviceClass.PROBLEM, entity_category=EntityCategory.DIAGNOSTIC, ), BinarySensorEntityDescription( key="filter_cleaning_reminder", translation_key="filter_cleaning_reminder", device_class=BinarySensorDeviceClass.PROBLEM, entity_category=EntityCategory.DIAGNOSTIC, ), BinarySensorEntityDescription( key="full_dust", translation_key="full_dust", device_class=BinarySensorDeviceClass.PROBLEM, entity_category=EntityCategory.DIAGNOSTIC, ), BinarySensorEntityDescription( key="fall_asleep_status", translation_key="fall_asleep_status", device_class=BinarySensorDeviceClass.RUNNING, entity_category=EntityCategory.DIAGNOSTIC, ), BinarySensorEntityDescription( key="night_mode", translation_key="night_mode", device_class=BinarySensorDeviceClass.RUNNING, ), BinarySensorEntityDescription( key="screen_status", translation_key="screen_status", device_class=BinarySensorDeviceClass.RUNNING, entity_category=EntityCategory.DIAGNOSTIC, ), BinarySensorEntityDescription( key="led_status", translation_key="led_status", device_class=BinarySensorDeviceClass.RUNNING, entity_category=EntityCategory.DIAGNOSTIC, ), BinarySensorEntityDescription( key="arofene_link", translation_key="arofene_link", device_class=BinarySensorDeviceClass.PLUG, ), BinarySensorEntityDescription( key="header_exist", translation_key="header_exist", device_class=BinarySensorDeviceClass.PLUG, entity_category=EntityCategory.DIAGNOSTIC, ), ] async def async_setup_entry( hass: HomeAssistant, config_entry: MideaConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up sensors for device.""" device = config_entry.runtime_data binary_sensors = [ MideaBinarySensor(device, description) for description in BINARY_SENSORS if description.key in device.attributes ] async_add_entities(binary_sensors) class MideaBinarySensor(MideaEntity, BinarySensorEntity): """Represent a Midea binary sensor.""" @property @override def is_on(self) -> bool | None: """Return true if sensor state is on.""" value = self._device.get_attribute(self.entity_description.key) if not isinstance(value, bool): return None return value