Files
core/homeassistant/components/overkiz/lock.py
T

53 lines
1.5 KiB
Python

"""Support for Overkiz locks."""
from typing import Any, override
from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
from homeassistant.components.lock import LockEntity
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import OverkizDataConfigEntry
from .entity import OverkizEntity
PARALLEL_UPDATES = 0
async def async_setup_entry(
hass: HomeAssistant,
entry: OverkizDataConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the Overkiz locks from a config entry."""
data = entry.runtime_data
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."""
@override
async def async_lock(self, **kwargs: Any) -> None:
"""Lock method."""
await self.executor.async_execute_command(OverkizCommand.LOCK)
@override
async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock method."""
await self.executor.async_execute_command(OverkizCommand.UNLOCK)
@property
@override
def is_locked(self) -> bool | None:
"""Return a boolean for the state of the lock."""
return (
self.device.states.get_value(OverkizState.CORE_LOCKED_UNLOCKED)
== OverkizCommandParam.LOCKED
)