Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Genius Hub binary_sensor devices."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components.binary_sensor import BinarySensorEntity
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers.entity_platform import AddEntitiesCallback
8 
9 from . import GeniusHubConfigEntry
10 from .entity import GeniusDevice
11 
12 GH_STATE_ATTR = "outputOnOff"
13 GH_TYPE = "Receiver"
14 
15 
17  hass: HomeAssistant,
18  entry: GeniusHubConfigEntry,
19  async_add_entities: AddEntitiesCallback,
20 ) -> None:
21  """Set up the Genius Hub binary sensor entities."""
22 
23  broker = entry.runtime_data
24 
26  GeniusBinarySensor(broker, d, GH_STATE_ATTR)
27  for d in broker.client.device_objs
28  if GH_TYPE in d.data["type"]
29  )
30 
31 
33  """Representation of a Genius Hub binary_sensor."""
34 
35  def __init__(self, broker, device, state_attr) -> None:
36  """Initialize the binary sensor."""
37  super().__init__(broker, device)
38 
39  self._state_attr_state_attr_state_attr = state_attr
40 
41  if device.type[:21] == "Dual Channel Receiver":
42  self._attr_name_attr_name = f"{device.type[:21]} {device.id}"
43  else:
44  self._attr_name_attr_name = f"{device.type} {device.id}"
45 
46  @property
47  def is_on(self) -> bool:
48  """Return the status of the sensor."""
49  return self._device_device.data["state"][self._state_attr_state_attr_state_attr]
None async_setup_entry(HomeAssistant hass, GeniusHubConfigEntry entry, AddEntitiesCallback async_add_entities)