hass-core/homeassistant/components/overkiz/lock.py
Mick Vleeshouwer b4187540c0
Improve typing for Overkiz integration and address late feedback (#63483)
* Bump pyoverkiz to 1.0.2

* Remove cast for str enum.

* Address feedback on coordinator

* Change datatype to Callable

* Address feedback

* Move scenarios to seperate list

* Cast Device to avoid issues with DataUpdateCoordinator default

* Remove unnecessary casts and improve type notation

* Check if state.value exists

* Fix last mypy error (thanks @epenet)

* Remove extra string cast

* Improve sensor typing

* Update pyoverkiz and remove typing

* Small code improvement

* Fix assert to reflect real world

* Properly type Callable to not return Any

* Remove unnecessary cast

* Add OverkizStateType

* Bugfix

* Address feedback - multiline lambda

* Pylint fix

* Remove added binary sensor
2022-01-08 10:53:15 +01:00

50 lines
1.6 KiB
Python

"""Support for Overkiz locks."""
from __future__ import annotations
from typing import Any
from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
from homeassistant.components.lock import LockEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HomeAssistantOverkizData
from .const import DOMAIN
from .entity import OverkizEntity
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Overkiz locks from a config entry."""
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
async_add_entities(
OverkizLock(device.device_url, data.coordinator)
for device in data.platforms[Platform.LOCK]
)
class OverkizLock(OverkizEntity, LockEntity):
"""Representation of an Overkiz Lock."""
async def async_lock(self, **kwargs: Any) -> None:
"""Lock method."""
await self.executor.async_execute_command(OverkizCommand.LOCK)
async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock method."""
await self.executor.async_execute_command(OverkizCommand.UNLOCK)
@property
def is_locked(self) -> bool | None:
"""Return a boolean for the state of the lock."""
return (
self.executor.select_state(OverkizState.CORE_LOCKED_UNLOCKED)
== OverkizCommandParam.LOCKED
)