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