2019-02-13 21:21:14 +01:00
|
|
|
"""Support for Verisure binary sensors."""
|
2021-03-06 00:37:56 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-03-15 23:59:41 +01:00
|
|
|
from typing import Any, Callable, Iterable
|
2021-03-06 00:37:56 +01:00
|
|
|
|
2019-11-13 14:12:36 +01:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
DEVICE_CLASS_CONNECTIVITY,
|
2021-03-14 10:38:09 +01:00
|
|
|
DEVICE_CLASS_OPENING,
|
2020-04-23 21:57:07 +02:00
|
|
|
BinarySensorEntity,
|
2019-11-13 14:12:36 +01:00
|
|
|
)
|
2021-03-15 20:30:44 +01:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-03-06 00:37:56 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-03-15 20:30:44 +01:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2021-03-11 19:41:01 +01:00
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
2019-03-20 22:56:46 -07:00
|
|
|
|
2021-03-15 23:59:41 +01:00
|
|
|
from .const import CONF_GIID, DOMAIN
|
2021-03-14 10:38:09 +01:00
|
|
|
from .coordinator import VerisureDataUpdateCoordinator
|
2017-06-26 22:30:25 +02:00
|
|
|
|
|
|
|
|
2021-03-15 20:30:44 +01:00
|
|
|
async def async_setup_entry(
|
2021-03-06 00:37:56 +01:00
|
|
|
hass: HomeAssistant,
|
2021-03-15 20:30:44 +01:00
|
|
|
entry: ConfigEntry,
|
|
|
|
async_add_entities: Callable[[Iterable[Entity]], None],
|
2021-03-06 00:37:56 +01:00
|
|
|
) -> None:
|
2021-03-15 20:30:44 +01:00
|
|
|
"""Set up Verisure sensors based on a config entry."""
|
|
|
|
coordinator: VerisureDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
2017-06-26 22:30:25 +02:00
|
|
|
|
2021-03-15 20:30:44 +01:00
|
|
|
sensors: list[Entity] = [VerisureEthernetStatus(coordinator)]
|
2021-03-11 19:41:01 +01:00
|
|
|
|
2021-03-15 20:30:44 +01:00
|
|
|
sensors.extend(
|
|
|
|
VerisureDoorWindowSensor(coordinator, serial_number)
|
|
|
|
for serial_number in coordinator.data["door_window"]
|
|
|
|
)
|
2019-11-13 14:12:36 +01:00
|
|
|
|
2021-03-15 20:30:44 +01:00
|
|
|
async_add_entities(sensors)
|
2017-06-26 22:30:25 +02:00
|
|
|
|
|
|
|
|
2021-03-11 19:41:01 +01:00
|
|
|
class VerisureDoorWindowSensor(CoordinatorEntity, BinarySensorEntity):
|
2018-01-21 07:35:38 +01:00
|
|
|
"""Representation of a Verisure door window sensor."""
|
2017-06-26 22:30:25 +02:00
|
|
|
|
2021-03-11 19:41:01 +01:00
|
|
|
coordinator: VerisureDataUpdateCoordinator
|
|
|
|
|
|
|
|
def __init__(
|
2021-03-14 10:38:09 +01:00
|
|
|
self, coordinator: VerisureDataUpdateCoordinator, serial_number: str
|
2021-03-11 19:41:01 +01:00
|
|
|
) -> None:
|
2018-01-21 07:35:38 +01:00
|
|
|
"""Initialize the Verisure door window sensor."""
|
2021-03-11 19:41:01 +01:00
|
|
|
super().__init__(coordinator)
|
2021-03-14 10:38:09 +01:00
|
|
|
self.serial_number = serial_number
|
2017-06-26 22:30:25 +02:00
|
|
|
|
|
|
|
@property
|
2021-03-06 00:37:56 +01:00
|
|
|
def name(self) -> str:
|
2017-06-26 22:30:25 +02:00
|
|
|
"""Return the name of the binary sensor."""
|
2021-03-14 10:38:09 +01:00
|
|
|
return self.coordinator.data["door_window"][self.serial_number]["area"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self) -> str:
|
|
|
|
"""Return the unique ID for this alarm control panel."""
|
|
|
|
return f"{self.serial_number}_door_window"
|
|
|
|
|
2021-03-15 23:59:41 +01:00
|
|
|
@property
|
|
|
|
def device_info(self) -> dict[str, Any]:
|
|
|
|
"""Return device information about this entity."""
|
|
|
|
area = self.coordinator.data["door_window"][self.serial_number]["area"]
|
|
|
|
return {
|
|
|
|
"name": area,
|
|
|
|
"suggested_area": area,
|
|
|
|
"manufacturer": "Verisure",
|
|
|
|
"model": "Shock Sensor Detector",
|
|
|
|
"identifiers": {(DOMAIN, self.serial_number)},
|
|
|
|
"via_device": (DOMAIN, self.coordinator.entry.data[CONF_GIID]),
|
|
|
|
}
|
|
|
|
|
2021-03-14 10:38:09 +01:00
|
|
|
@property
|
|
|
|
def device_class(self) -> str:
|
|
|
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
|
|
return DEVICE_CLASS_OPENING
|
2017-06-26 22:30:25 +02:00
|
|
|
|
|
|
|
@property
|
2021-03-06 00:37:56 +01:00
|
|
|
def is_on(self) -> bool:
|
2017-06-26 22:30:25 +02:00
|
|
|
"""Return the state of the sensor."""
|
2019-07-31 12:25:30 -07:00
|
|
|
return (
|
2021-03-14 10:38:09 +01:00
|
|
|
self.coordinator.data["door_window"][self.serial_number]["state"] == "OPEN"
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2017-06-26 22:30:25 +02:00
|
|
|
|
|
|
|
@property
|
2021-03-06 00:37:56 +01:00
|
|
|
def available(self) -> bool:
|
2017-06-26 22:30:25 +02:00
|
|
|
"""Return True if entity is available."""
|
2019-07-31 12:25:30 -07:00
|
|
|
return (
|
2021-03-14 10:38:09 +01:00
|
|
|
super().available
|
|
|
|
and self.serial_number in self.coordinator.data["door_window"]
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2017-06-26 22:30:25 +02:00
|
|
|
|
2019-11-13 14:12:36 +01:00
|
|
|
|
2021-03-11 19:41:01 +01:00
|
|
|
class VerisureEthernetStatus(CoordinatorEntity, BinarySensorEntity):
|
2019-11-13 14:12:36 +01:00
|
|
|
"""Representation of a Verisure VBOX internet status."""
|
|
|
|
|
2021-03-11 19:41:01 +01:00
|
|
|
coordinator: VerisureDataUpdateCoordinator
|
|
|
|
|
2019-11-13 14:12:36 +01:00
|
|
|
@property
|
2021-03-06 00:37:56 +01:00
|
|
|
def name(self) -> str:
|
2019-11-13 14:12:36 +01:00
|
|
|
"""Return the name of the binary sensor."""
|
|
|
|
return "Verisure Ethernet status"
|
|
|
|
|
2021-03-15 23:59:41 +01:00
|
|
|
@property
|
|
|
|
def unique_id(self) -> str:
|
|
|
|
"""Return the unique ID for this binary sensor."""
|
|
|
|
return f"{self.coordinator.entry.data[CONF_GIID]}_ethernet"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_info(self) -> dict[str, Any]:
|
|
|
|
"""Return device information about this entity."""
|
|
|
|
return {
|
|
|
|
"name": "Verisure Alarm",
|
|
|
|
"manufacturer": "Verisure",
|
|
|
|
"model": "VBox",
|
|
|
|
"identifiers": {(DOMAIN, self.coordinator.entry.data[CONF_GIID])},
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:12:36 +01:00
|
|
|
@property
|
2021-03-06 00:37:56 +01:00
|
|
|
def is_on(self) -> bool:
|
2019-11-13 14:12:36 +01:00
|
|
|
"""Return the state of the sensor."""
|
2021-03-14 10:38:09 +01:00
|
|
|
return self.coordinator.data["ethernet"]
|
2019-11-13 14:12:36 +01:00
|
|
|
|
|
|
|
@property
|
2021-03-06 00:37:56 +01:00
|
|
|
def available(self) -> bool:
|
2019-11-13 14:12:36 +01:00
|
|
|
"""Return True if entity is available."""
|
2021-03-14 10:38:09 +01:00
|
|
|
return super().available and self.coordinator.data["ethernet"] is not None
|
2019-11-13 14:12:36 +01:00
|
|
|
|
|
|
|
@property
|
2021-03-06 00:37:56 +01:00
|
|
|
def device_class(self) -> str:
|
2019-11-13 14:12:36 +01:00
|
|
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
|
|
return DEVICE_CLASS_CONNECTIVITY
|