Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Stookalert Binary Sensor."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 
7 import stookalert
8 
10  BinarySensorDeviceClass,
11  BinarySensorEntity,
12 )
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.core import HomeAssistant
15 from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
16 from homeassistant.helpers.entity_platform import AddEntitiesCallback
17 
18 from .const import CONF_PROVINCE, DOMAIN
19 
20 SCAN_INTERVAL = timedelta(minutes=60)
21 
22 
24  hass: HomeAssistant,
25  entry: ConfigEntry,
26  async_add_entities: AddEntitiesCallback,
27 ) -> None:
28  """Set up Stookalert binary sensor from a config entry."""
29  client = hass.data[DOMAIN][entry.entry_id]
30  async_add_entities([StookalertBinarySensor(client, entry)], update_before_add=True)
31 
32 
34  """Defines a Stookalert binary sensor."""
35 
36  _attr_attribution = "Data provided by rivm.nl"
37  _attr_device_class = BinarySensorDeviceClass.SAFETY
38  _attr_has_entity_name = True
39  _attr_name = None
40 
41  def __init__(self, client: stookalert.stookalert, entry: ConfigEntry) -> None:
42  """Initialize a Stookalert device."""
43  self._client_client = client
44  self._attr_unique_id_attr_unique_id = entry.unique_id
45  self._attr_device_info_attr_device_info = DeviceInfo(
46  identifiers={(DOMAIN, f"{entry.entry_id}")},
47  name=f"Stookalert {entry.data[CONF_PROVINCE]}",
48  manufacturer="RIVM",
49  model="Stookalert",
50  entry_type=DeviceEntryType.SERVICE,
51  configuration_url="https://www.rivm.nl/stookalert",
52  )
53 
54  def update(self) -> None:
55  """Update the data from the Stookalert handler."""
56  self._client_client.get_alerts()
57  self._attr_is_on_attr_is_on = self._client_client.state == 1
None __init__(self, stookalert.stookalert client, ConfigEntry entry)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)