Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """mütesync binary sensor entities."""
2 
3 from homeassistant.components.binary_sensor import BinarySensorEntity
4 from homeassistant.config_entries import ConfigEntry
5 from homeassistant.core import HomeAssistant
6 from homeassistant.helpers import update_coordinator
7 from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
8 from homeassistant.helpers.entity_platform import AddEntitiesCallback
9 
10 from .const import DOMAIN
11 
12 SENSORS = (
13  "in_meeting",
14  "muted",
15 )
16 
17 
19  hass: HomeAssistant,
20  config_entry: ConfigEntry,
21  async_add_entities: AddEntitiesCallback,
22 ) -> None:
23  """Set up the mütesync button."""
24  coordinator = hass.data[DOMAIN][config_entry.entry_id]
26  [MuteStatus(coordinator, sensor_type) for sensor_type in SENSORS], True
27  )
28 
29 
30 class MuteStatus(update_coordinator.CoordinatorEntity, BinarySensorEntity):
31  """Mütesync binary sensors."""
32 
33  _attr_has_entity_name = True
34 
35  def __init__(self, coordinator, sensor_type):
36  """Initialize our sensor."""
37  super().__init__(coordinator)
38  self._sensor_type_sensor_type = sensor_type
39  self._attr_translation_key_attr_translation_key = sensor_type
40  user_id = coordinator.data["user-id"]
41  self._attr_unique_id_attr_unique_id = f"{user_id}-{sensor_type}"
42  self._attr_device_info_attr_device_info = DeviceInfo(
43  entry_type=DeviceEntryType.SERVICE,
44  identifiers={(DOMAIN, user_id)},
45  manufacturer="mütesync",
46  model="mutesync app",
47  name="mutesync",
48  )
49 
50  @property
51  def is_on(self):
52  """Return the state of the sensor."""
53  return self.coordinator.data[self._sensor_type_sensor_type]
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)