Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Binary Sensor platform for CoolMasterNet integration."""
2 
3 from __future__ import annotations
4 
6  BinarySensorDeviceClass,
7  BinarySensorEntity,
8  BinarySensorEntityDescription,
9 )
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.const import EntityCategory
12 from homeassistant.core import HomeAssistant
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 from .const import DATA_COORDINATOR, DATA_INFO, DOMAIN
16 from .entity import CoolmasterEntity
17 
18 
20  hass: HomeAssistant,
21  config_entry: ConfigEntry,
22  async_add_entities: AddEntitiesCallback,
23 ) -> None:
24  """Set up the CoolMasterNet binary_sensor platform."""
25  info = hass.data[DOMAIN][config_entry.entry_id][DATA_INFO]
26  coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR]
28  CoolmasterCleanFilter(coordinator, unit_id, info)
29  for unit_id in coordinator.data
30  )
31 
32 
34  """Representation of a unit's filter state (true means need to be cleaned)."""
35 
36  entity_description = BinarySensorEntityDescription(
37  key="clean_filter",
38  translation_key="clean_filter",
39  device_class=BinarySensorDeviceClass.PROBLEM,
40  entity_category=EntityCategory.DIAGNOSTIC,
41  )
42 
43  @property
44  def is_on(self) -> bool | None:
45  """Return true if the binary sensor is on."""
46  return self._unit_unit.clean_filter
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)