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
|
|
|
|
|
2019-11-13 14:12:36 +01:00
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-01 10:24:58 +01:00
|
|
|
BinarySensorDeviceClass,
|
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
|
2023-03-27 00:17:12 +02:00
|
|
|
from homeassistant.const import ATTR_LAST_TRIP_TIME, EntityCategory
|
2021-03-06 00:37:56 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
2023-02-09 20:15:37 +01:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo, Entity
|
2021-05-04 22:36:48 +01:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-03-11 19:41:01 +01:00
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
2023-03-27 00:17:12 +02:00
|
|
|
from homeassistant.util import dt as dt_util
|
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,
|
2021-05-04 22:36:48 +01:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2021-03-06 00:37:56 +01:00
|
|
|
) -> None:
|
2021-03-16 16:30:04 +01:00
|
|
|
"""Set up Verisure binary sensors based on a config entry."""
|
2021-03-15 20:30:44 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
2022-03-21 14:20:35 +01:00
|
|
|
class VerisureDoorWindowSensor(
|
|
|
|
CoordinatorEntity[VerisureDataUpdateCoordinator], 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-12-01 10:24:58 +01:00
|
|
|
_attr_device_class = BinarySensorDeviceClass.OPENING
|
2022-07-11 18:14:17 +02:00
|
|
|
_attr_has_entity_name = True
|
2021-05-22 18:13:50 +02:00
|
|
|
|
2021-03-11 19:41:01 +01:00
|
|
|
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-05-22 18:13:50 +02:00
|
|
|
self._attr_unique_id = f"{serial_number}_door_window"
|
2021-03-14 10:38:09 +01:00
|
|
|
self.serial_number = serial_number
|
2017-06-26 22:30:25 +02:00
|
|
|
|
2021-03-15 23:59:41 +01:00
|
|
|
@property
|
2021-05-02 00:37:19 +02:00
|
|
|
def device_info(self) -> DeviceInfo:
|
2021-03-15 23:59:41 +01:00
|
|
|
"""Return device information about this entity."""
|
|
|
|
area = self.coordinator.data["door_window"][self.serial_number]["area"]
|
2021-10-15 00:35:09 +02:00
|
|
|
return DeviceInfo(
|
|
|
|
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]),
|
|
|
|
configuration_url="https://mypages.verisure.com",
|
|
|
|
)
|
2021-03-15 23:59:41 +01:00
|
|
|
|
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
|
|
|
|
2023-03-27 00:17:12 +02:00
|
|
|
@property
|
|
|
|
def extra_state_attributes(self):
|
|
|
|
"""Return the state attributes of the sensor."""
|
|
|
|
return {
|
|
|
|
ATTR_LAST_TRIP_TIME: dt_util.parse_datetime(
|
|
|
|
self.coordinator.data["door_window"][self.serial_number]["reportTime"]
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:12:36 +01:00
|
|
|
|
2022-03-21 14:20:35 +01:00
|
|
|
class VerisureEthernetStatus(
|
|
|
|
CoordinatorEntity[VerisureDataUpdateCoordinator], BinarySensorEntity
|
|
|
|
):
|
2019-11-13 14:12:36 +01:00
|
|
|
"""Representation of a Verisure VBOX internet status."""
|
|
|
|
|
2021-12-01 10:24:58 +01:00
|
|
|
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
|
2021-12-20 20:56:33 +01:00
|
|
|
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
2022-07-11 18:14:17 +02:00
|
|
|
_attr_has_entity_name = True
|
2023-03-27 16:55:10 +02:00
|
|
|
_attr_translation_key = "ethernet"
|
2019-11-13 14:12:36 +01:00
|
|
|
|
2021-03-15 23:59:41 +01:00
|
|
|
@property
|
|
|
|
def unique_id(self) -> str:
|
2021-03-16 16:30:04 +01:00
|
|
|
"""Return the unique ID for this entity."""
|
2021-03-15 23:59:41 +01:00
|
|
|
return f"{self.coordinator.entry.data[CONF_GIID]}_ethernet"
|
|
|
|
|
|
|
|
@property
|
2021-05-02 00:37:19 +02:00
|
|
|
def device_info(self) -> DeviceInfo:
|
2021-03-15 23:59:41 +01:00
|
|
|
"""Return device information about this entity."""
|
2021-10-15 00:35:09 +02:00
|
|
|
return DeviceInfo(
|
|
|
|
name="Verisure Alarm",
|
|
|
|
manufacturer="Verisure",
|
|
|
|
model="VBox",
|
|
|
|
identifiers={(DOMAIN, self.coordinator.entry.data[CONF_GIID])},
|
|
|
|
configuration_url="https://mypages.verisure.com",
|
|
|
|
)
|
2021-03-15 23:59:41 +01:00
|
|
|
|
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."""
|
2023-03-26 19:32:25 +02:00
|
|
|
return self.coordinator.data["broadband"]["isBroadbandConnected"]
|
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."""
|
2023-03-26 19:32:25 +02:00
|
|
|
return super().available and self.coordinator.data["broadband"] is not None
|