Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Abode Security System binary sensors."""
2 
3 from __future__ import annotations
4 
5 from typing import cast
6 
7 from jaraco.abode.devices.binary_sensor import BinarySensor
8 
10  BinarySensorDeviceClass,
11  BinarySensorEntity,
12 )
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.core import HomeAssistant
15 from homeassistant.helpers.entity_platform import AddEntitiesCallback
16 from homeassistant.util.enum import try_parse_enum
17 
18 from . import AbodeSystem
19 from .const import DOMAIN
20 from .entity import AbodeDevice
21 
22 
24  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
25 ) -> None:
26  """Set up Abode binary sensor devices."""
27  data: AbodeSystem = hass.data[DOMAIN]
28 
29  device_types = [
30  "connectivity",
31  "moisture",
32  "motion",
33  "occupancy",
34  "door",
35  ]
36 
38  AbodeBinarySensor(data, device)
39  for device in data.abode.get_devices(generic_type=device_types)
40  )
41 
42 
44  """A binary sensor implementation for Abode device."""
45 
46  _attr_name = None
47  _device: BinarySensor
48 
49  @property
50  def is_on(self) -> bool:
51  """Return True if the binary sensor is on."""
52  return cast(bool, self._device_device.is_on)
53 
54  @property
55  def device_class(self) -> BinarySensorDeviceClass | None:
56  """Return the class of the binary sensor."""
57  if self._device_device.get_value("is_window") == "1":
58  return BinarySensorDeviceClass.WINDOW
59  return try_parse_enum(BinarySensorDeviceClass, self._device_device.generic_type)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
float|int|str|None get_value(Sensor sensor, str field)
Definition: sensor.py:46