Home Assistant Unofficial Reference 2024.12.1
lock.py
Go to the documentation of this file.
1 """Support for Overkiz locks."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
8 
9 from homeassistant.components.lock import LockEntity
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.const import Platform
12 from homeassistant.core import HomeAssistant
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 from . import HomeAssistantOverkizData
16 from .const import DOMAIN
17 from .entity import OverkizEntity
18 
19 
21  hass: HomeAssistant,
22  entry: ConfigEntry,
23  async_add_entities: AddEntitiesCallback,
24 ) -> None:
25  """Set up the Overkiz locks from a config entry."""
26  data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
27 
29  OverkizLock(device.device_url, data.coordinator)
30  for device in data.platforms[Platform.LOCK]
31  )
32 
33 
35  """Representation of an Overkiz Lock."""
36 
37  async def async_lock(self, **kwargs: Any) -> None:
38  """Lock method."""
39  await self.executorexecutor.async_execute_command(OverkizCommand.LOCK)
40 
41  async def async_unlock(self, **kwargs: Any) -> None:
42  """Unlock method."""
43  await self.executorexecutor.async_execute_command(OverkizCommand.UNLOCK)
44 
45  @property
46  def is_locked(self) -> bool | None:
47  """Return a boolean for the state of the lock."""
48  return (
49  self.executorexecutor.select_state(OverkizState.CORE_LOCKED_UNLOCKED)
50  == OverkizCommandParam.LOCKED
51  )
None async_unlock(self, **Any kwargs)
Definition: __init__.py:245
None async_lock(self, **Any kwargs)
Definition: lock.py:37
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: lock.py:24