Add lock typing in components (#73539)
* Add lock typing in components * Revert freedompro amendspull/73544/head
parent
8c0ae545c9
commit
f8f1bfde21
|
@ -1,5 +1,6 @@
|
|||
"""Support for August lock."""
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from aiohttp import ClientResponseError
|
||||
from yalexs.activity import SOURCE_PUBNUB, ActivityType
|
||||
|
@ -44,14 +45,14 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
|
|||
self._attr_unique_id = f"{self._device_id:s}_lock"
|
||||
self._update_from_data()
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the device."""
|
||||
if self._data.activity_stream.pubnub.connected:
|
||||
await self._data.async_lock_async(self._device_id, self._hyper_bridge)
|
||||
return
|
||||
await self._call_lock_operation(self._data.async_lock)
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device."""
|
||||
if self._data.activity_stream.pubnub.connected:
|
||||
await self._data.async_unlock_async(self._device_id, self._hyper_bridge)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.lock import LockEntity, LockEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -66,26 +67,26 @@ class DemoLock(LockEntity):
|
|||
self._jam_on_operation = jam_on_operation
|
||||
|
||||
@property
|
||||
def is_locking(self):
|
||||
def is_locking(self) -> bool:
|
||||
"""Return true if lock is locking."""
|
||||
return self._state == STATE_LOCKING
|
||||
|
||||
@property
|
||||
def is_unlocking(self):
|
||||
def is_unlocking(self) -> bool:
|
||||
"""Return true if lock is unlocking."""
|
||||
return self._state == STATE_UNLOCKING
|
||||
|
||||
@property
|
||||
def is_jammed(self):
|
||||
def is_jammed(self) -> bool:
|
||||
"""Return true if lock is jammed."""
|
||||
return self._state == STATE_JAMMED
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool:
|
||||
"""Return true if lock is locked."""
|
||||
return self._state == STATE_LOCKED
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the device."""
|
||||
self._state = STATE_LOCKING
|
||||
self.async_write_ha_state()
|
||||
|
@ -96,7 +97,7 @@ class DemoLock(LockEntity):
|
|||
self._state = STATE_LOCKED
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device."""
|
||||
self._state = STATE_UNLOCKING
|
||||
self.async_write_ha_state()
|
||||
|
@ -104,7 +105,7 @@ class DemoLock(LockEntity):
|
|||
self._state = STATE_UNLOCKED
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_open(self, **kwargs):
|
||||
async def async_open(self, **kwargs: Any) -> None:
|
||||
"""Open the door latch."""
|
||||
self._state = STATE_UNLOCKED
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for Fibaro locks."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.lock import ENTITY_ID_FORMAT, LockEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
|
@ -37,18 +39,18 @@ class FibaroLock(FibaroDevice, LockEntity):
|
|||
super().__init__(fibaro_device)
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id)
|
||||
|
||||
def lock(self, **kwargs):
|
||||
def lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the device."""
|
||||
self.action("secure")
|
||||
self._state = True
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
def unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device."""
|
||||
self.action("unsecure")
|
||||
self._state = False
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool:
|
||||
"""Return true if device is locked."""
|
||||
return self._state
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for Homematic locks."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.lock import LockEntity, LockEntityFeature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -33,19 +35,19 @@ class HMLock(HMDevice, LockEntity):
|
|||
_attr_supported_features = LockEntityFeature.OPEN
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool:
|
||||
"""Return true if the lock is locked."""
|
||||
return not bool(self._hm_get_state())
|
||||
|
||||
def lock(self, **kwargs):
|
||||
def lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the lock."""
|
||||
self._hmdevice.lock()
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
def unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the lock."""
|
||||
self._hmdevice.unlock()
|
||||
|
||||
def open(self, **kwargs):
|
||||
def open(self, **kwargs: Any) -> None:
|
||||
"""Open the door latch."""
|
||||
self._hmdevice.open()
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for KEBA charging station switch."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -51,15 +53,15 @@ class KebaLock(LockEntity):
|
|||
return f"{self._keba.device_name} {self._name}"
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool:
|
||||
"""Return true if lock is locked."""
|
||||
return self._state
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock wallbox."""
|
||||
await self._keba.async_stop()
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock wallbox."""
|
||||
await self._keba.async_start()
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from kiwiki import KiwiClient, KiwiException
|
||||
import voluptuous as vol
|
||||
|
@ -89,7 +90,7 @@ class KiwiLock(LockEntity):
|
|||
return name or specifier
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool:
|
||||
"""Return true if lock is locked."""
|
||||
return self._state == STATE_LOCKED
|
||||
|
||||
|
@ -104,7 +105,7 @@ class KiwiLock(LockEntity):
|
|||
self._state = STATE_LOCKED
|
||||
self.async_write_ha_state()
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
def unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device."""
|
||||
|
||||
try:
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
"""Platform for Mazda lock integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -36,17 +40,17 @@ class MazdaLock(MazdaEntity, LockEntity):
|
|||
self._attr_unique_id = self.vin
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool | None:
|
||||
"""Return true if lock is locked."""
|
||||
return self.client.get_assumed_lock_state(self.vehicle_id)
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the vehicle doors."""
|
||||
await self.client.lock_doors(self.vehicle_id)
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the vehicle doors."""
|
||||
await self.client.unlock_doors(self.vehicle_id)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -183,7 +184,7 @@ class MqttLock(MqttEntity, LockEntity):
|
|||
await subscription.async_subscribe_topics(self.hass, self._sub_state)
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool:
|
||||
"""Return true if lock is locked."""
|
||||
return self._state
|
||||
|
||||
|
@ -197,7 +198,7 @@ class MqttLock(MqttEntity, LockEntity):
|
|||
"""Flag supported features."""
|
||||
return LockEntityFeature.OPEN if CONF_PAYLOAD_OPEN in self._config else 0
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the device.
|
||||
|
||||
This method is a coroutine.
|
||||
|
@ -214,7 +215,7 @@ class MqttLock(MqttEntity, LockEntity):
|
|||
self._state = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device.
|
||||
|
||||
This method is a coroutine.
|
||||
|
@ -231,7 +232,7 @@ class MqttLock(MqttEntity, LockEntity):
|
|||
self._state = False
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_open(self, **kwargs):
|
||||
async def async_open(self, **kwargs: Any) -> None:
|
||||
"""Open the door latch.
|
||||
|
||||
This method is a coroutine.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Nuki.io lock platform."""
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any
|
||||
|
||||
from pynuki.constants import MODE_OPENER_CONTINUOUS
|
||||
import voluptuous as vol
|
||||
|
@ -92,15 +93,15 @@ class NukiDeviceEntity(NukiEntity, LockEntity, ABC):
|
|||
return super().available and self._nuki_device.state not in ERROR_STATES
|
||||
|
||||
@abstractmethod
|
||||
def lock(self, **kwargs):
|
||||
def lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the device."""
|
||||
|
||||
@abstractmethod
|
||||
def unlock(self, **kwargs):
|
||||
def unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device."""
|
||||
|
||||
@abstractmethod
|
||||
def open(self, **kwargs):
|
||||
def open(self, **kwargs: Any) -> None:
|
||||
"""Open the door latch."""
|
||||
|
||||
|
||||
|
@ -112,15 +113,15 @@ class NukiLockEntity(NukiDeviceEntity):
|
|||
"""Return true if lock is locked."""
|
||||
return self._nuki_device.is_locked
|
||||
|
||||
def lock(self, **kwargs):
|
||||
def lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the device."""
|
||||
self._nuki_device.lock()
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
def unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device."""
|
||||
self._nuki_device.unlock()
|
||||
|
||||
def open(self, **kwargs):
|
||||
def open(self, **kwargs: Any) -> None:
|
||||
"""Open the door latch."""
|
||||
self._nuki_device.unlatch()
|
||||
|
||||
|
@ -144,15 +145,15 @@ class NukiOpenerEntity(NukiDeviceEntity):
|
|||
or self._nuki_device.mode == MODE_OPENER_CONTINUOUS
|
||||
)
|
||||
|
||||
def lock(self, **kwargs):
|
||||
def lock(self, **kwargs: Any) -> None:
|
||||
"""Disable ring-to-open."""
|
||||
self._nuki_device.deactivate_rto()
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
def unlock(self, **kwargs: Any) -> None:
|
||||
"""Enable ring-to-open."""
|
||||
self._nuki_device.activate_rto()
|
||||
|
||||
def open(self, **kwargs):
|
||||
def open(self, **kwargs: Any) -> None:
|
||||
"""Buzz open the door."""
|
||||
self._nuki_device.electric_strike_actuation()
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
from typing import Any
|
||||
|
||||
from pysmartthings import Attribute, Capability
|
||||
|
||||
|
@ -50,18 +51,18 @@ def get_capabilities(capabilities: Sequence[str]) -> Sequence[str] | None:
|
|||
class SmartThingsLock(SmartThingsEntity, LockEntity):
|
||||
"""Define a SmartThings lock."""
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the device."""
|
||||
await self._device.lock(set_status=True)
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device."""
|
||||
await self._device.unlock(set_status=True)
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool:
|
||||
"""Return true if lock is locked."""
|
||||
return self._device.status.lock == ST_STATE_LOCKED
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Support for StarLine lock."""
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -68,10 +70,10 @@ class StarlineLock(StarlineEntity, LockEntity):
|
|||
"""Return true if lock is locked."""
|
||||
return self._device.car_state.get("arm")
|
||||
|
||||
def lock(self, **kwargs):
|
||||
def lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the car."""
|
||||
self._account.api.set_car_state(self._device.device_id, "arm", True)
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
def unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the car."""
|
||||
self._account.api.set_car_state(self._device.device_id, "arm", False)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Support for Subaru door locks."""
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -68,7 +69,7 @@ class SubaruLock(LockEntity):
|
|||
self._attr_unique_id = f"{vin}_door_locks"
|
||||
self._attr_device_info = get_device_info(vehicle_info)
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Send the lock command."""
|
||||
_LOGGER.debug("Locking doors for: %s", self.car_name)
|
||||
await async_call_remote_service(
|
||||
|
@ -77,7 +78,7 @@ class SubaruLock(LockEntity):
|
|||
self.vehicle_info,
|
||||
)
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Send the unlock command."""
|
||||
_LOGGER.debug("Unlocking doors for: %s", self.car_name)
|
||||
await async_call_remote_service(
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for locks which integrates with other components."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.lock import (
|
||||
|
@ -95,22 +97,22 @@ class TemplateLock(TemplateEntity, LockEntity):
|
|||
return self._optimistic
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
def is_locked(self) -> bool:
|
||||
"""Return true if lock is locked."""
|
||||
return self._state in ("true", STATE_ON, STATE_LOCKED)
|
||||
|
||||
@property
|
||||
def is_jammed(self):
|
||||
def is_jammed(self) -> bool:
|
||||
"""Return true if lock is jammed."""
|
||||
return self._state == STATE_JAMMED
|
||||
|
||||
@property
|
||||
def is_unlocking(self):
|
||||
def is_unlocking(self) -> bool:
|
||||
"""Return true if lock is unlocking."""
|
||||
return self._state == STATE_UNLOCKING
|
||||
|
||||
@property
|
||||
def is_locking(self):
|
||||
def is_locking(self) -> bool:
|
||||
"""Return true if lock is locking."""
|
||||
return self._state == STATE_LOCKING
|
||||
|
||||
|
@ -138,14 +140,14 @@ class TemplateLock(TemplateEntity, LockEntity):
|
|||
)
|
||||
await super().async_added_to_hass()
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the device."""
|
||||
if self._optimistic:
|
||||
self._state = True
|
||||
self.async_write_ha_state()
|
||||
await self.async_run_script(self._command_lock, context=self._context)
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the device."""
|
||||
if self._optimistic:
|
||||
self._state = False
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for Volvo On Call locks."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -30,10 +32,10 @@ class VolvoLock(VolvoEntity, LockEntity):
|
|||
"""Return true if lock is locked."""
|
||||
return self.instrument.is_locked
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the car."""
|
||||
await self.instrument.lock()
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the car."""
|
||||
await self.instrument.unlock()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Locks on Zigbee Home Automation networks."""
|
||||
import functools
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
from zigpy.zcl.foundation import Status
|
||||
|
@ -119,7 +120,7 @@ class ZhaDoorLock(ZhaEntity, LockEntity):
|
|||
"""Return state attributes."""
|
||||
return self.state_attributes
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock the lock."""
|
||||
result = await self._doorlock_channel.lock_door()
|
||||
if isinstance(result, Exception) or result[0] is not Status.SUCCESS:
|
||||
|
@ -127,7 +128,7 @@ class ZhaDoorLock(ZhaEntity, LockEntity):
|
|||
return
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the lock."""
|
||||
result = await self._doorlock_channel.unlock_door()
|
||||
if isinstance(result, Exception) or result[0] is not Status.SUCCESS:
|
||||
|
|
Loading…
Reference in New Issue