2021-12-23 23:28:01 +00:00
|
|
|
"""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,
|
|
|
|
):
|
|
|
|
"""Set up the Overkiz locks from a config entry."""
|
|
|
|
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
|
2021-12-27 17:26:55 +00:00
|
|
|
async_add_entities(
|
2021-12-23 23:28:01 +00:00
|
|
|
OverkizLock(device.device_url, data.coordinator)
|
|
|
|
for device in data.platforms[Platform.LOCK]
|
2021-12-27 17:26:55 +00:00
|
|
|
)
|
2021-12-23 23:28:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OverkizLock(OverkizEntity, LockEntity):
|
|
|
|
"""Representation of an Overkiz Lock."""
|
|
|
|
|
2021-12-27 17:26:55 +00:00
|
|
|
async def async_lock(self, **kwargs: Any) -> None:
|
2021-12-23 23:28:01 +00:00
|
|
|
"""Lock method."""
|
|
|
|
await self.executor.async_execute_command(OverkizCommand.LOCK)
|
|
|
|
|
2021-12-27 17:26:55 +00:00
|
|
|
async def async_unlock(self, **kwargs: Any) -> None:
|
2021-12-23 23:28:01 +00:00
|
|
|
"""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
|
|
|
|
)
|