Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Lutron Powr Savr occupancy sensors."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Mapping
6 import logging
7 from typing import Any
8 
9 from pylutron import OccupancyGroup
10 
12  BinarySensorDeviceClass,
13  BinarySensorEntity,
14 )
15 from homeassistant.config_entries import ConfigEntry
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from . import DOMAIN, LutronData
20 from .entity import LutronDevice
21 
22 _LOGGER = logging.getLogger(__name__)
23 
24 
26  hass: HomeAssistant,
27  config_entry: ConfigEntry,
28  async_add_entities: AddEntitiesCallback,
29 ) -> None:
30  """Set up the Lutron binary_sensor platform.
31 
32  Adds occupancy groups from the Main Repeater associated with the
33  config_entry as binary_sensor entities.
34  """
35  entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
37  [
38  LutronOccupancySensor(area_name, device, entry_data.client)
39  for area_name, device in entry_data.binary_sensors
40  ],
41  True,
42  )
43 
44 
46  """Representation of a Lutron Occupancy Group.
47 
48  The Lutron integration API reports "occupancy groups" rather than
49  individual sensors. If two sensors are in the same room, they're
50  reported as a single occupancy group.
51  """
52 
53  _lutron_device: OccupancyGroup
54  _attr_device_class = BinarySensorDeviceClass.OCCUPANCY
55 
56  @property
57  def extra_state_attributes(self) -> Mapping[str, Any] | None:
58  """Return the state attributes."""
59  return {"lutron_integration_id": self._lutron_device_lutron_device.id}
60 
61  def _update_attrs(self) -> None:
62  """Update the state attributes."""
63  self._attr_is_on_attr_is_on = self._lutron_device_lutron_device.state == OccupancyGroup.State.OCCUPIED
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)