wyzeapy.services.lock_service

 1#  Copyright (c) 2021. Mulliken, LLC - All Rights Reserved
 2#  You may use, distribute and modify this code under the terms
 3#  of the attached license. You should have received a copy of
 4#  the license with this file. If not, please write to:
 5#  katie@mulliken.net to receive a copy
 6from .base_service import BaseService
 7from ..const import FORD_APP_SECRET
 8from ..types import Device, DeviceTypes
 9from ..utils import wyze_decrypt_cbc
10
11
12class Lock(Device):
13    unlocked = False
14    locking = False
15    unlocking = False
16    door_open = False
17    trash_mode = False
18    ble_id = None
19    ble_token = None
20
21
22class LockService(BaseService):
23    async def update(self, lock: Lock):
24        device_info = await self._get_lock_info(lock)
25        lock.raw_dict = device_info["device"]
26        if lock.product_model == "YD_BT1":
27            ble_token_info = await self._get_lock_ble_token(lock)
28            lock.raw_dict["token"] = ble_token_info["token"]
29            lock.ble_id = ble_token_info["token"]["id"]
30            lock.ble_token = wyze_decrypt_cbc(FORD_APP_SECRET[:16], ble_token_info["token"]["token"])
31
32        lock.available = lock.raw_dict.get("onoff_line") == 1
33        lock.door_open = lock.raw_dict.get("door_open_status") == 1
34        lock.trash_mode = lock.raw_dict.get("trash_mode") == 1
35
36        # store the nested dict for easier reference below
37        locker_status = lock.raw_dict.get("locker_status")
38        # Check if the door is locked
39        lock.unlocked = locker_status.get("hardlock") == 2
40        
41        # Reset unlocking and locking if needed
42        if lock.unlocked and lock.unlocking:
43            lock.unlocking = False
44        if not lock.unlocked and lock.locking:
45            lock.locking = False
46        
47        return lock
48
49    async def get_locks(self):
50        if self._devices is None:
51            self._devices = await self.get_object_list()
52
53        locks = [device for device in self._devices if device.type is DeviceTypes.LOCK]
54
55        return [Lock(device.raw_dict) for device in locks]
56
57    async def lock(self, lock: Lock):
58        await self._lock_control(lock, "remoteLock")
59
60    async def unlock(self, lock: Lock):
61        await self._lock_control(lock, "remoteUnlock")
class Lock(wyzeapy.types.Device):
13class Lock(Device):
14    unlocked = False
15    locking = False
16    unlocking = False
17    door_open = False
18    trash_mode = False
19    ble_id = None
20    ble_token = None
unlocked = False
locking = False
unlocking = False
door_open = False
trash_mode = False
ble_id = None
ble_token = None
class LockService(wyzeapy.services.base_service.BaseService):
23class LockService(BaseService):
24    async def update(self, lock: Lock):
25        device_info = await self._get_lock_info(lock)
26        lock.raw_dict = device_info["device"]
27        if lock.product_model == "YD_BT1":
28            ble_token_info = await self._get_lock_ble_token(lock)
29            lock.raw_dict["token"] = ble_token_info["token"]
30            lock.ble_id = ble_token_info["token"]["id"]
31            lock.ble_token = wyze_decrypt_cbc(FORD_APP_SECRET[:16], ble_token_info["token"]["token"])
32
33        lock.available = lock.raw_dict.get("onoff_line") == 1
34        lock.door_open = lock.raw_dict.get("door_open_status") == 1
35        lock.trash_mode = lock.raw_dict.get("trash_mode") == 1
36
37        # store the nested dict for easier reference below
38        locker_status = lock.raw_dict.get("locker_status")
39        # Check if the door is locked
40        lock.unlocked = locker_status.get("hardlock") == 2
41        
42        # Reset unlocking and locking if needed
43        if lock.unlocked and lock.unlocking:
44            lock.unlocking = False
45        if not lock.unlocked and lock.locking:
46            lock.locking = False
47        
48        return lock
49
50    async def get_locks(self):
51        if self._devices is None:
52            self._devices = await self.get_object_list()
53
54        locks = [device for device in self._devices if device.type is DeviceTypes.LOCK]
55
56        return [Lock(device.raw_dict) for device in locks]
57
58    async def lock(self, lock: Lock):
59        await self._lock_control(lock, "remoteLock")
60
61    async def unlock(self, lock: Lock):
62        await self._lock_control(lock, "remoteUnlock")

Base service class for interacting with Wyze devices.

async def update(self, lock: Lock):
24    async def update(self, lock: Lock):
25        device_info = await self._get_lock_info(lock)
26        lock.raw_dict = device_info["device"]
27        if lock.product_model == "YD_BT1":
28            ble_token_info = await self._get_lock_ble_token(lock)
29            lock.raw_dict["token"] = ble_token_info["token"]
30            lock.ble_id = ble_token_info["token"]["id"]
31            lock.ble_token = wyze_decrypt_cbc(FORD_APP_SECRET[:16], ble_token_info["token"]["token"])
32
33        lock.available = lock.raw_dict.get("onoff_line") == 1
34        lock.door_open = lock.raw_dict.get("door_open_status") == 1
35        lock.trash_mode = lock.raw_dict.get("trash_mode") == 1
36
37        # store the nested dict for easier reference below
38        locker_status = lock.raw_dict.get("locker_status")
39        # Check if the door is locked
40        lock.unlocked = locker_status.get("hardlock") == 2
41        
42        # Reset unlocking and locking if needed
43        if lock.unlocked and lock.unlocking:
44            lock.unlocking = False
45        if not lock.unlocked and lock.locking:
46            lock.locking = False
47        
48        return lock
async def get_locks(self):
50    async def get_locks(self):
51        if self._devices is None:
52            self._devices = await self.get_object_list()
53
54        locks = [device for device in self._devices if device.type is DeviceTypes.LOCK]
55
56        return [Lock(device.raw_dict) for device in locks]
async def lock(self, lock: Lock):
58    async def lock(self, lock: Lock):
59        await self._lock_control(lock, "remoteLock")
async def unlock(self, lock: Lock):
61    async def unlock(self, lock: Lock):
62        await self._lock_control(lock, "remoteUnlock")