Improve nuki type hints (#73891)

This commit is contained in:
epenet 2022-06-23 11:44:25 +02:00 committed by GitHub
parent 10b083bbf5
commit a3ce80baed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 12 deletions

View file

@ -3,8 +3,9 @@ from datetime import timedelta
import logging
import async_timeout
from pynuki import NukiBridge
from pynuki import NukiBridge, NukiLock, NukiOpener
from pynuki.bridge import InvalidCredentialsException
from pynuki.device import NukiDevice
from requests.exceptions import RequestException
from homeassistant import exceptions
@ -34,11 +35,11 @@ PLATFORMS = [Platform.BINARY_SENSOR, Platform.LOCK]
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
def _update_devices(devices):
def _update_devices(devices: list[NukiDevice]) -> None:
for device in devices:
for level in (False, True):
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."""
super().__init__(coordinator)
self._nuki_device = nuki_device

View file

@ -1,4 +1,6 @@
"""Nuki.io lock platform."""
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Any
@ -65,23 +67,22 @@ class NukiDeviceEntity(NukiEntity, LockEntity, ABC):
_attr_supported_features = LockEntityFeature.OPEN
@property
def name(self):
def name(self) -> str | None:
"""Return the name of the lock."""
return self._nuki_device.name
@property
def unique_id(self) -> str:
def unique_id(self) -> str | None:
"""Return a unique ID."""
return self._nuki_device.nuki_id
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the device specific state attributes."""
data = {
return {
ATTR_BATTERY_CRITICAL: self._nuki_device.battery_critical,
ATTR_NUKI_ID: self._nuki_device.nuki_id,
}
return data
@property
def available(self) -> bool:
@ -123,7 +124,7 @@ class NukiLockEntity(NukiDeviceEntity):
"""Open the door latch."""
self._nuki_device.unlatch()
def lock_n_go(self, unlatch):
def lock_n_go(self, unlatch: bool) -> None:
"""Lock and go.
This will first unlock the door, then wait for 20 seconds (or another
@ -157,10 +158,10 @@ class NukiOpenerEntity(NukiDeviceEntity):
"""Buzz open the door."""
self._nuki_device.electric_strike_actuation()
def lock_n_go(self, unlatch):
def lock_n_go(self, unlatch: bool) -> None:
"""Stub service."""
def set_continuous_mode(self, enable):
def set_continuous_mode(self, enable: bool) -> None:
"""Continuous Mode.
This feature will cause the door to automatically open when anyone