Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Oncue binary sensors."""
2 
3 from __future__ import annotations
4 
6  BinarySensorDeviceClass,
7  BinarySensorEntity,
8  BinarySensorEntityDescription,
9 )
10 from homeassistant.const import EntityCategory
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from .entity import OncueEntity
15 from .types import OncueConfigEntry
16 
17 SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
19  key="NetworkConnectionEstablished",
20  entity_category=EntityCategory.DIAGNOSTIC,
21  device_class=BinarySensorDeviceClass.CONNECTIVITY,
22  ),
23 )
24 
25 SENSOR_MAP = {description.key: description for description in SENSOR_TYPES}
26 
27 
29  hass: HomeAssistant,
30  config_entry: OncueConfigEntry,
31  async_add_entities: AddEntitiesCallback,
32 ) -> None:
33  """Set up binary sensors."""
34  coordinator = config_entry.runtime_data
35  devices = coordinator.data
37  OncueBinarySensorEntity(coordinator, device_id, device, sensor, SENSOR_MAP[key])
38  for device_id, device in devices.items()
39  for key, sensor in device.sensors.items()
40  if key in SENSOR_MAP
41  )
42 
43 
45  """Representation of an Oncue binary sensor."""
46 
47  @property
48  def is_on(self) -> bool:
49  """Return the binary sensor state."""
50  return self._oncue_value_oncue_value_oncue_value_oncue_value == "true"
None async_setup_entry(HomeAssistant hass, OncueConfigEntry config_entry, AddEntitiesCallback async_add_entities)