1 """Support for Minut Point binary sensors."""
3 from __future__
import annotations
7 from pypoint
import EVENTS
10 DOMAIN
as BINARY_SENSOR_DOMAIN,
11 BinarySensorDeviceClass,
19 from .const
import DOMAIN
as POINT_DOMAIN, POINT_DISCOVERY_NEW, SIGNAL_WEBHOOK
20 from .entity
import MinutPointEntity
22 _LOGGER = logging.getLogger(__name__)
26 "alarm": {
"icon":
"mdi:alarm-bell"},
27 "battery": {
"device_class": BinarySensorDeviceClass.BATTERY},
28 "button_press": {
"icon":
"mdi:gesture-tap-button"},
29 "cold": {
"device_class": BinarySensorDeviceClass.COLD},
30 "connectivity": {
"device_class": BinarySensorDeviceClass.CONNECTIVITY},
31 "dry": {
"icon":
"mdi:water"},
32 "glass": {
"icon":
"mdi:window-closed-variant"},
33 "heat": {
"device_class": BinarySensorDeviceClass.HEAT},
34 "moisture": {
"device_class": BinarySensorDeviceClass.MOISTURE},
35 "motion": {
"device_class": BinarySensorDeviceClass.MOTION},
36 "noise": {
"icon":
"mdi:volume-high"},
37 "sound": {
"device_class": BinarySensorDeviceClass.SOUND},
38 "tamper_old": {
"icon":
"mdi:shield-alert"},
39 "tamper": {
"icon":
"mdi:shield-alert"},
45 config_entry: ConfigEntry,
46 async_add_entities: AddEntitiesCallback,
48 """Set up a Point's binary sensors based on a config entry."""
51 """Discover and add a discovered sensor."""
52 client = config_entry.runtime_data.client
56 for device_name
in DEVICES
57 if device_name
in EVENTS
64 POINT_DISCOVERY_NEW.format(BINARY_SENSOR_DOMAIN, POINT_DOMAIN),
65 async_discover_sensor,
70 """The platform class required by Home Assistant."""
72 def __init__(self, point_client, device_id, device_name):
73 """Initialize the binary sensor."""
77 DEVICES[device_name].
get(
"device_class", device_name),
86 """Call when entity is added to HOme Assistant."""
93 """Disconnect dispatcher listener when removed."""
99 """Update the value of the sensor."""
111 """Process new event from the webhook."""
112 if self.
devicedevice.webhook != webhook:
114 _type = data.get(
"event", {}).
get(
"type")
115 _device_id = data.get(
"event", {}).
get(
"device_id")
116 if _type
not in self.
_events_events
or _device_id != self.
devicedevice.device_id:
118 _LOGGER.debug(
"Received webhook: %s", _type)
119 if _type == self.
_events_events[0]:
121 elif _type == self.
_events_events[1]:
None async_will_remove_from_hass(self)
None async_added_to_hass(self)
_async_unsub_hook_dispatcher_connect
def _update_callback(self)
def _webhook_event(self, data, webhook)
def __init__(self, point_client, device_id, device_name)
str|None device_class(self)
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
def async_discover_sensor(device_id)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)