From a3ce80baed4ced985a39e7cfc7d5bf6cb52eb3cc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 23 Jun 2022 11:44:25 +0200 Subject: [PATCH] Improve nuki type hints (#73891) --- homeassistant/components/nuki/__init__.py | 11 +++++++---- homeassistant/components/nuki/lock.py | 17 +++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/nuki/__init__.py b/homeassistant/components/nuki/__init__.py index 6976c2dc682..e9cef7aa6cd 100644 --- a/homeassistant/components/nuki/__init__.py +++ b/homeassistant/components/nuki/__init__.py @@ -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 diff --git a/homeassistant/components/nuki/lock.py b/homeassistant/components/nuki/lock.py index 33d7465e12d..8b6c843f48a 100644 --- a/homeassistant/components/nuki/lock.py +++ b/homeassistant/components/nuki/lock.py @@ -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