Complete typing on Verisure integration (#47482)
This commit is contained in:
parent
4c181bbfe5
commit
10dae253e5
7 changed files with 159 additions and 90 deletions
|
@ -1,13 +1,24 @@
|
|||
"""Support for Verisure binary sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_CONNECTIVITY,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import CONF_DOOR_WINDOW, HUB as hub
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
def setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, Any],
|
||||
add_entities: Callable[[list[Entity], bool], None],
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""Set up the Verisure binary sensors."""
|
||||
sensors = []
|
||||
hub.update_overview()
|
||||
|
@ -29,12 +40,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
class VerisureDoorWindowSensor(BinarySensorEntity):
|
||||
"""Representation of a Verisure door window sensor."""
|
||||
|
||||
def __init__(self, device_label):
|
||||
def __init__(self, device_label: str):
|
||||
"""Initialize the Verisure door window sensor."""
|
||||
self._device_label = device_label
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Return the name of the binary sensor."""
|
||||
return hub.get_first(
|
||||
"$.doorWindow.doorWindowDevice[?(@.deviceLabel=='%s')].area",
|
||||
|
@ -42,7 +53,7 @@ class VerisureDoorWindowSensor(BinarySensorEntity):
|
|||
)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state of the sensor."""
|
||||
return (
|
||||
hub.get_first(
|
||||
|
@ -53,7 +64,7 @@ class VerisureDoorWindowSensor(BinarySensorEntity):
|
|||
)
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return (
|
||||
hub.get_first(
|
||||
|
@ -64,7 +75,7 @@ class VerisureDoorWindowSensor(BinarySensorEntity):
|
|||
)
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update the state of the sensor."""
|
||||
hub.update_overview()
|
||||
|
||||
|
@ -73,26 +84,26 @@ class VerisureEthernetStatus(BinarySensorEntity):
|
|||
"""Representation of a Verisure VBOX internet status."""
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Return the name of the binary sensor."""
|
||||
return "Verisure Ethernet status"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state of the sensor."""
|
||||
return hub.get_first("$.ethernetConnectedNow")
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return hub.get_first("$.ethernetConnectedNow") is not None
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update the state of the sensor."""
|
||||
hub.update_overview()
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
def device_class(self) -> str:
|
||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||
return DEVICE_CLASS_CONNECTIVITY
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue