forked from marthoc/homeseer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock.py
45 lines (30 loc) · 1.2 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
"""
Support for HomeSeer lock-type devices.
"""
from .hoomseer import HomeseerEntity
from .pyhs3.device import GenericDoorLock
from homeassistant.components.lock import LockEntity
from .const import DATA_CLIENT, _LOGGER, DOMAIN
DEPENDENCIES = ["homeseer"]
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up HomeSeer lock-type devices."""
lock_devices = []
homeseer = hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id]
for device in homeseer.devices:
if issubclass(type(device), GenericDoorLock):
dev = HSLock(device, homeseer)
lock_devices.append(dev)
_LOGGER.info(f"Added HomeSeer lock-type device: {dev.name}")
async_add_entities(lock_devices)
class HSLock(HomeseerEntity, LockEntity):
"""Representation of a HomeSeer lock device."""
def __init__(self, device, connection):
HomeseerEntity.__init__(self, device, connection)
@property
def is_locked(self):
"""Return true if device is locked."""
return self._device.is_locked
async def async_lock(self, **kwargs):
await self._device.lock()
async def async_unlock(self, **kwargs):
await self._device.unlock()