Home Assistant Unofficial Reference 2024.12.1
lock.py
Go to the documentation of this file.
1 """Representation of a doorlock."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from zwave_me_ws import ZWaveMeData
8 
9 from homeassistant.components.lock import LockEntity
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.core import HomeAssistant, callback
12 from homeassistant.helpers.dispatcher import async_dispatcher_connect
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 from .const import DOMAIN, ZWaveMePlatform
16 from .entity import ZWaveMeEntity
17 
18 DEVICE_NAME = ZWaveMePlatform.LOCK
19 
20 
22  hass: HomeAssistant,
23  config_entry: ConfigEntry,
24  async_add_entities: AddEntitiesCallback,
25 ) -> None:
26  """Set up the lock platform."""
27 
28  @callback
29  def add_new_device(new_device: ZWaveMeData) -> None:
30  """Add a new device."""
31  controller = hass.data[DOMAIN][config_entry.entry_id]
32  lock = ZWaveMeLock(controller, new_device)
33 
35  [
36  lock,
37  ]
38  )
39 
40  config_entry.async_on_unload(
42  hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
43  )
44  )
45 
46 
48  """Representation of a ZWaveMe lock."""
49 
50  @property
51  def is_locked(self) -> bool:
52  """Return the state of the lock."""
53  return self.devicedevice.level == "close"
54 
55  def unlock(self, **kwargs: Any) -> None:
56  """Send command to unlock the lock."""
57  self.controllercontroller.zwave_api.send_command(self.devicedevice.id, "open")
58 
59  def lock(self, **kwargs: Any) -> None:
60  """Send command to lock the lock."""
61  self.controllercontroller.zwave_api.send_command(self.devicedevice.id, "close")
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: lock.py:25
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103