Improve nuki type hints (#73891)
This commit is contained in:
parent
10b083bbf5
commit
a3ce80baed
2 changed files with 16 additions and 12 deletions
|
@ -3,8 +3,9 @@ from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
from pynuki import NukiBridge
|
from pynuki import NukiBridge, NukiLock, NukiOpener
|
||||||
from pynuki.bridge import InvalidCredentialsException
|
from pynuki.bridge import InvalidCredentialsException
|
||||||
|
from pynuki.device import NukiDevice
|
||||||
from requests.exceptions import RequestException
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
from homeassistant import exceptions
|
from homeassistant import exceptions
|
||||||
|
@ -34,11 +35,11 @@ PLATFORMS = [Platform.BINARY_SENSOR, Platform.LOCK]
|
||||||
UPDATE_INTERVAL = timedelta(seconds=30)
|
UPDATE_INTERVAL = timedelta(seconds=30)
|
||||||
|
|
||||||
|
|
||||||
def _get_bridge_devices(bridge):
|
def _get_bridge_devices(bridge: NukiBridge) -> tuple[list[NukiLock], list[NukiOpener]]:
|
||||||
return bridge.locks, bridge.openers
|
return bridge.locks, bridge.openers
|
||||||
|
|
||||||
|
|
||||||
def _update_devices(devices):
|
def _update_devices(devices: list[NukiDevice]) -> None:
|
||||||
for device in devices:
|
for device in devices:
|
||||||
for level in (False, True):
|
for level in (False, True):
|
||||||
try:
|
try:
|
||||||
|
@ -136,7 +137,9 @@ class NukiEntity(CoordinatorEntity):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, coordinator, nuki_device):
|
def __init__(
|
||||||
|
self, coordinator: DataUpdateCoordinator[None], nuki_device: NukiDevice
|
||||||
|
) -> None:
|
||||||
"""Pass coordinator to CoordinatorEntity."""
|
"""Pass coordinator to CoordinatorEntity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._nuki_device = nuki_device
|
self._nuki_device = nuki_device
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Nuki.io lock platform."""
|
"""Nuki.io lock platform."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
@ -65,23 +67,22 @@ class NukiDeviceEntity(NukiEntity, LockEntity, ABC):
|
||||||
_attr_supported_features = LockEntityFeature.OPEN
|
_attr_supported_features = LockEntityFeature.OPEN
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str | None:
|
||||||
"""Return the name of the lock."""
|
"""Return the name of the lock."""
|
||||||
return self._nuki_device.name
|
return self._nuki_device.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str | None:
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
return self._nuki_device.nuki_id
|
return self._nuki_device.nuki_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the device specific state attributes."""
|
"""Return the device specific state attributes."""
|
||||||
data = {
|
return {
|
||||||
ATTR_BATTERY_CRITICAL: self._nuki_device.battery_critical,
|
ATTR_BATTERY_CRITICAL: self._nuki_device.battery_critical,
|
||||||
ATTR_NUKI_ID: self._nuki_device.nuki_id,
|
ATTR_NUKI_ID: self._nuki_device.nuki_id,
|
||||||
}
|
}
|
||||||
return data
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
@ -123,7 +124,7 @@ class NukiLockEntity(NukiDeviceEntity):
|
||||||
"""Open the door latch."""
|
"""Open the door latch."""
|
||||||
self._nuki_device.unlatch()
|
self._nuki_device.unlatch()
|
||||||
|
|
||||||
def lock_n_go(self, unlatch):
|
def lock_n_go(self, unlatch: bool) -> None:
|
||||||
"""Lock and go.
|
"""Lock and go.
|
||||||
|
|
||||||
This will first unlock the door, then wait for 20 seconds (or another
|
This will first unlock the door, then wait for 20 seconds (or another
|
||||||
|
@ -157,10 +158,10 @@ class NukiOpenerEntity(NukiDeviceEntity):
|
||||||
"""Buzz open the door."""
|
"""Buzz open the door."""
|
||||||
self._nuki_device.electric_strike_actuation()
|
self._nuki_device.electric_strike_actuation()
|
||||||
|
|
||||||
def lock_n_go(self, unlatch):
|
def lock_n_go(self, unlatch: bool) -> None:
|
||||||
"""Stub service."""
|
"""Stub service."""
|
||||||
|
|
||||||
def set_continuous_mode(self, enable):
|
def set_continuous_mode(self, enable: bool) -> None:
|
||||||
"""Continuous Mode.
|
"""Continuous Mode.
|
||||||
|
|
||||||
This feature will cause the door to automatically open when anyone
|
This feature will cause the door to automatically open when anyone
|
||||||
|
|
Loading…
Add table
Reference in a new issue