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
|
|
|
|
|
|
|
|
from typing import Any, Callable
|
|
|
|
|
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-06 00:37:56 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
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-14 10:38:09 +01:00
|
|
|
from . import CONF_DOOR_WINDOW, DOMAIN
|
|
|
|
from .coordinator import VerisureDataUpdateCoordinator
|
2017-06-26 22:30:25 +02:00
|
|
|
|
|
|
|
|
2021-03-06 00:37:56 +01:00
|
|
|
def setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: dict[str, Any],
|
2021-03-14 10:38:09 +01:00
|
|
|
add_entities: Callable[[list[CoordinatorEntity]], None],
|
2021-03-06 00:37:56 +01:00
|
|
|
discovery_info: dict[str, Any] | None = None,
|
|
|
|
) -> None:
|
2018-01-21 07:35:38 +01:00
|
|
|
"""Set up the Verisure binary sensors."""
|
2021-03-11 19:41:01 +01:00
|
|
|
coordinator = hass.data[DOMAIN]
|
2017-06-26 22:30:25 +02:00
|
|
|
|
2021-03-14 10:38:09 +01:00
|
|
|
sensors: list[CoordinatorEntity] = [VerisureEthernetStatus(coordinator)]
|
2021-03-11 19:41:01 +01:00
|
|
|
|
|
|
|
if int(coordinator.config.get(CONF_DOOR_WINDOW, 1)):
|
2019-07-31 12:25:30 -07:00
|
|
|
sensors.extend(
|
|
|
|
[
|
2021-03-14 10:38:09 +01:00
|
|
|
VerisureDoorWindowSensor(coordinator, serial_number)
|
|
|
|
for serial_number in coordinator.data["door_window"]
|
2019-07-31 12:25:30 -07:00
|
|
|
]
|
|
|
|
)
|
2019-11-13 14:12:36 +01:00
|
|
|
|
2018-08-24 16:37:30 +02:00
|
|
|
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"
|
|
|
|
|
|
|
|
@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"
|
|
|
|
|
|
|
|
@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
|