Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for INSTEON dimmers via PowerLinc Modem."""
2 
3 from pyinsteon.groups import (
4  CO_SENSOR,
5  DOOR_SENSOR,
6  HEARTBEAT,
7  LEAK_SENSOR_WET,
8  LIGHT_SENSOR,
9  LOW_BATTERY,
10  MOTION_SENSOR,
11  OPEN_CLOSE_SENSOR,
12  SENSOR_MALFUNCTION,
13  SMOKE_SENSOR,
14  TEST_SENSOR,
15 )
16 
18  BinarySensorDeviceClass,
19  BinarySensorEntity,
20 )
21 from homeassistant.config_entries import ConfigEntry
22 from homeassistant.const import Platform
23 from homeassistant.core import HomeAssistant, callback
24 from homeassistant.helpers.dispatcher import async_dispatcher_connect
25 from homeassistant.helpers.entity_platform import AddEntitiesCallback
26 
27 from .const import SIGNAL_ADD_ENTITIES
28 from .entity import InsteonEntity
29 from .utils import async_add_insteon_devices, async_add_insteon_entities
30 
31 SENSOR_TYPES = {
32  OPEN_CLOSE_SENSOR: BinarySensorDeviceClass.OPENING,
33  MOTION_SENSOR: BinarySensorDeviceClass.MOTION,
34  DOOR_SENSOR: BinarySensorDeviceClass.DOOR,
35  LEAK_SENSOR_WET: BinarySensorDeviceClass.MOISTURE,
36  LIGHT_SENSOR: BinarySensorDeviceClass.LIGHT,
37  LOW_BATTERY: BinarySensorDeviceClass.BATTERY,
38  CO_SENSOR: BinarySensorDeviceClass.GAS,
39  SMOKE_SENSOR: BinarySensorDeviceClass.SMOKE,
40  TEST_SENSOR: BinarySensorDeviceClass.SAFETY,
41  SENSOR_MALFUNCTION: BinarySensorDeviceClass.PROBLEM,
42  HEARTBEAT: BinarySensorDeviceClass.PROBLEM,
43 }
44 
45 
47  hass: HomeAssistant,
48  config_entry: ConfigEntry,
49  async_add_entities: AddEntitiesCallback,
50 ) -> None:
51  """Set up the Insteon binary sensors from a config entry."""
52 
53  @callback
54  def async_add_insteon_binary_sensor_entities(discovery_info=None):
55  """Add the Insteon entities for the platform."""
57  hass,
58  Platform.BINARY_SENSOR,
59  InsteonBinarySensorEntity,
60  async_add_entities,
61  discovery_info,
62  )
63 
64  signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.BINARY_SENSOR}"
65  async_dispatcher_connect(hass, signal, async_add_insteon_binary_sensor_entities)
67  hass,
68  Platform.BINARY_SENSOR,
69  InsteonBinarySensorEntity,
70  async_add_entities,
71  )
72 
73 
75  """A Class for an Insteon binary sensor entity."""
76 
77  def __init__(self, device, group):
78  """Initialize the INSTEON binary sensor."""
79  super().__init__(device, group)
80  self._attr_device_class_attr_device_class = SENSOR_TYPES.get(self._insteon_device_group_insteon_device_group.name)
81 
82  @property
83  def is_on(self):
84  """Return the boolean response if the node is on."""
85  return bool(self._insteon_device_group_insteon_device_group.value)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_add_insteon_devices(HomeAssistant hass, Platform platform, type[InsteonEntity] entity_type, AddEntitiesCallback async_add_entities)
Definition: utils.py:436
None async_add_insteon_entities(HomeAssistant hass, Platform platform, type[InsteonEntity] entity_type, AddEntitiesCallback async_add_entities, dict[str, Any] discovery_info)
Definition: utils.py:420
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103