Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for ZoneMinder binary sensors."""
2 
3 from __future__ import annotations
4 
5 from zoneminder.zm import ZoneMinder
6 
8  BinarySensorDeviceClass,
9  BinarySensorEntity,
10 )
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
14 
15 from . import DOMAIN as ZONEMINDER_DOMAIN
16 
17 
19  hass: HomeAssistant,
20  config: ConfigType,
21  add_entities: AddEntitiesCallback,
22  discovery_info: DiscoveryInfoType | None = None,
23 ) -> None:
24  """Set up the ZoneMinder binary sensor platform."""
25  sensors = []
26  for host_name, zm_client in hass.data[ZONEMINDER_DOMAIN].items():
27  sensors.append(ZMAvailabilitySensor(host_name, zm_client))
28  add_entities(sensors)
29 
30 
32  """Representation of the availability of ZoneMinder as a binary sensor."""
33 
34  _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
35 
36  def __init__(self, host_name: str, client: ZoneMinder) -> None:
37  """Initialize availability sensor."""
38  self._attr_name_attr_name = host_name
39  self._client_client = client
40 
41  def update(self) -> None:
42  """Update the state of this sensor (availability of ZoneMinder)."""
43  self._attr_is_on_attr_is_on = self._client_client.is_available
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)