Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Binary sensor platform for Squeezebox integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
8  BinarySensorDeviceClass,
9  BinarySensorEntity,
10  BinarySensorEntityDescription,
11 )
12 from homeassistant.const import EntityCategory
13 from homeassistant.core import HomeAssistant
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 
16 from . import SqueezeboxConfigEntry
17 from .const import STATUS_SENSOR_NEEDSRESTART, STATUS_SENSOR_RESCAN
18 from .entity import LMSStatusEntity
19 
20 SENSORS: tuple[BinarySensorEntityDescription, ...] = (
22  key=STATUS_SENSOR_RESCAN,
23  device_class=BinarySensorDeviceClass.RUNNING,
24  ),
26  key=STATUS_SENSOR_NEEDSRESTART,
27  device_class=BinarySensorDeviceClass.UPDATE,
28  entity_category=EntityCategory.DIAGNOSTIC,
29  ),
30 )
31 
32 _LOGGER = logging.getLogger(__name__)
33 
34 
36  hass: HomeAssistant,
37  entry: SqueezeboxConfigEntry,
38  async_add_entities: AddEntitiesCallback,
39 ) -> None:
40  """Platform setup using common elements."""
41 
43  ServerStatusBinarySensor(entry.runtime_data.coordinator, description)
44  for description in SENSORS
45  )
46 
47 
49  """LMS Status based sensor from LMS via cooridnatior."""
50 
51  @property
52  def is_on(self) -> bool:
53  """LMS Status directly from coordinator data."""
54  return bool(self.coordinator.data[self.entity_descriptionentity_description.key])
None async_setup_entry(HomeAssistant hass, SqueezeboxConfigEntry entry, AddEntitiesCallback async_add_entities)