Home Assistant Unofficial Reference 2024.12.1
lock.py
Go to the documentation of this file.
1 """Support for KEBA charging station switch."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from homeassistant.components.lock import LockEntity
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.entity_platform import AddEntitiesCallback
10 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
11 
12 from . import DOMAIN, KebaHandler
13 
14 
16  hass: HomeAssistant,
17  config: ConfigType,
18  async_add_entities: AddEntitiesCallback,
19  discovery_info: DiscoveryInfoType | None = None,
20 ) -> None:
21  """Set up the KEBA charging station platform."""
22  if discovery_info is None:
23  return
24 
25  keba: KebaHandler = hass.data[DOMAIN]
26 
27  locks = [KebaLock(keba, "Authentication", "authentication")]
28  async_add_entities(locks)
29 
30 
32  """The entity class for KEBA charging stations switch."""
33 
34  _attr_should_poll = False
35 
36  def __init__(self, keba: KebaHandler, name: str, entity_type: str) -> None:
37  """Initialize the KEBA switch."""
38  self._keba_keba = keba
39  self._attr_is_locked_attr_is_locked = True
40  self._attr_name_attr_name = f"{keba.device_name} {name}"
41  self._attr_unique_id_attr_unique_id = f"{keba.device_id}_{entity_type}"
42 
43  async def async_lock(self, **kwargs: Any) -> None:
44  """Lock wallbox."""
45  await self._keba_keba.async_stop()
46 
47  async def async_unlock(self, **kwargs: Any) -> None:
48  """Unlock wallbox."""
49  await self._keba_keba.async_start()
50 
51  async def async_update(self) -> None:
52  """Attempt to retrieve on off state from the switch."""
53  self._attr_is_locked_attr_is_locked = self._keba_keba.get_value("Authreq") == 1
54 
55  def update_callback(self) -> None:
56  """Schedule a state update."""
57  self.async_schedule_update_ha_stateasync_schedule_update_ha_state(True)
58 
59  async def async_added_to_hass(self) -> None:
60  """Add update callback after being added to hass."""
61  self._keba_keba.add_update_listener(self.update_callbackupdate_callback)
None async_unlock(self, **Any kwargs)
Definition: lock.py:47
None async_lock(self, **Any kwargs)
Definition: lock.py:43
None __init__(self, KebaHandler keba, str name, str entity_type)
Definition: lock.py:36
None async_schedule_update_ha_state(self, bool force_refresh=False)
Definition: entity.py:1265
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
Definition: lock.py:20
float|int|str|None get_value(Sensor sensor, str field)
Definition: sensor.py:46
None async_stop(HomeAssistant hass)
Definition: discovery.py:694
None async_start(HomeAssistant hass, str discovery_topic, ConfigEntry config_entry)
Definition: discovery.py:356