Home Assistant Unofficial Reference 2024.12.1
lock.py
Go to the documentation of this file.
1 """Support for StarLine lock."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from homeassistant.components.lock import LockEntity
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from .account import StarlineAccount, StarlineDevice
13 from .const import DOMAIN
14 from .entity import StarlineEntity
15 
16 
18  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
19 ) -> None:
20  """Set up the StarLine lock."""
21  account: StarlineAccount = hass.data[DOMAIN][entry.entry_id]
22  entities = []
23  for device in account.api.devices.values():
24  if device.support_state:
25  lock = StarlineLock(account, device)
26  if lock.is_locked is not None:
27  entities.append(lock)
28  async_add_entities(entities)
29 
30 
32  """Representation of a StarLine lock."""
33 
34  _attr_translation_key = "security"
35 
36  def __init__(self, account: StarlineAccount, device: StarlineDevice) -> None:
37  """Initialize the lock."""
38  super().__init__(account, device, "lock")
39 
40  @property
41  def available(self) -> bool:
42  """Return True if entity is available."""
43  return super().available and self._device_device.online
44 
45  @property
46  def extra_state_attributes(self) -> dict[str, bool]:
47  """Return the state attributes of the lock.
48 
49  Possible dictionary keys:
50  add_h - Additional sensor alarm status (high level)
51  add_l - Additional channel alarm status (low level)
52  door - Doors alarm status
53  hbrake - Hand brake alarm status
54  hijack - Hijack mode status
55  hood - Hood alarm status
56  ign - Ignition alarm status
57  pbrake - Brake pedal alarm status
58  shock_h - Shock sensor alarm status (high level)
59  shock_l - Shock sensor alarm status (low level)
60  tilt - Tilt sensor alarm status
61  trunk - Trunk alarm status
62  Documentation: https://developer.starline.ru/#api-Device-DeviceState
63  """
64  return self._device_device.alarm_state
65 
66  @property
67  def is_locked(self) -> bool | None:
68  """Return true if lock is locked."""
69  return self._device_device.car_state.get("arm")
70 
71  def lock(self, **kwargs: Any) -> None:
72  """Lock the car."""
73  self._account_account.api.set_car_state(self._device_device.device_id, "arm", True)
74 
75  def unlock(self, **kwargs: Any) -> None:
76  """Unlock the car."""
77  self._account_account.api.set_car_state(self._device_device.device_id, "arm", False)
None __init__(self, StarlineAccount account, StarlineDevice device)
Definition: lock.py:36
dict[str, bool] extra_state_attributes(self)
Definition: lock.py:46
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: lock.py:19