Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Hue binary sensor entities."""
2 
3 from aiohue.v1.sensors import TYPE_ZLL_PRESENCE
4 
6  BinarySensorDeviceClass,
7  BinarySensorEntity,
8 )
9 
10 from ..const import DOMAIN as HUE_DOMAIN
11 from .sensor_base import SENSOR_CONFIG_MAP, GenericZLLSensor
12 
13 PRESENCE_NAME_FORMAT = "{} motion"
14 
15 
16 async def async_setup_entry(hass, config_entry, async_add_entities):
17  """Defer binary sensor setup to the shared sensor module."""
18  bridge = hass.data[HUE_DOMAIN][config_entry.entry_id]
19 
20  if not bridge.sensor_manager:
21  return
22 
23  await bridge.sensor_manager.async_register_component(
24  "binary_sensor", async_add_entities
25  )
26 
27 
28 # pylint: disable-next=hass-enforce-class-module
30  """The presence sensor entity for a Hue motion sensor device."""
31 
32  _attr_device_class = BinarySensorDeviceClass.MOTION
33 
34  @property
35  def is_on(self):
36  """Return true if the binary sensor is on."""
37  return self.sensorsensor.presence
38 
39  @property
41  """Return the device state attributes."""
42  attributes = super().extra_state_attributes
43  if "sensitivity" in self.sensorsensor.config:
44  attributes["sensitivity"] = self.sensorsensor.config["sensitivity"]
45  if "sensitivitymax" in self.sensorsensor.config:
46  attributes["sensitivity_max"] = self.sensorsensor.config["sensitivitymax"]
47  return attributes
48 
49 
50 SENSOR_CONFIG_MAP.update(
51  {
52  TYPE_ZLL_PRESENCE: {
53  "platform": "binary_sensor",
54  "name_format": PRESENCE_NAME_FORMAT,
55  "class": HuePresence,
56  }
57  }
58 )
def async_setup_entry(hass, config_entry, async_add_entities)