Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Representation of a sensorBinary."""
2 
3 from __future__ import annotations
4 
5 from zwave_me_ws import ZWaveMeData
6 
8  BinarySensorDeviceClass,
9  BinarySensorEntity,
10  BinarySensorEntityDescription,
11 )
12 from homeassistant.config_entries import ConfigEntry
13 from homeassistant.core import HomeAssistant, callback
14 from homeassistant.helpers.dispatcher import async_dispatcher_connect
15 from homeassistant.helpers.entity_platform import AddEntitiesCallback
16 
17 from . import ZWaveMeController
18 from .const import DOMAIN, ZWaveMePlatform
19 from .entity import ZWaveMeEntity
20 
21 BINARY_SENSORS_MAP: dict[str, BinarySensorEntityDescription] = {
23  key="generic",
24  ),
26  key="motion",
27  device_class=BinarySensorDeviceClass.MOTION,
28  ),
29 }
30 DEVICE_NAME = ZWaveMePlatform.BINARY_SENSOR
31 
32 
34  hass: HomeAssistant,
35  config_entry: ConfigEntry,
36  async_add_entities: AddEntitiesCallback,
37 ) -> None:
38  """Set up the binary sensor platform."""
39 
40  @callback
41  def add_new_device(new_device: ZWaveMeData) -> None:
42  controller: ZWaveMeController = hass.data[DOMAIN][config_entry.entry_id]
43  description = BINARY_SENSORS_MAP.get(
44  new_device.probeType, BINARY_SENSORS_MAP["generic"]
45  )
46  sensor = ZWaveMeBinarySensor(controller, new_device, description)
47 
49  [
50  sensor,
51  ]
52  )
53 
54  config_entry.async_on_unload(
56  hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
57  )
58  )
59 
60 
62  """Representation of a ZWaveMe binary sensor."""
63 
64  def __init__(
65  self,
66  controller: ZWaveMeController,
67  device: ZWaveMeData,
68  description: BinarySensorEntityDescription,
69  ) -> None:
70  """Initialize the device."""
71  super().__init__(controller=controller, device=device)
72  self.entity_descriptionentity_description = description
73 
74  @property
75  def is_on(self) -> bool:
76  """Return the state of the sensor."""
77  return self.devicedevice.level == "on"
None __init__(self, ZWaveMeController controller, ZWaveMeData device, BinarySensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103