-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlocks.py
More file actions
182 lines (156 loc) · 6.49 KB
/
locks.py
File metadata and controls
182 lines (156 loc) · 6.49 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from typing import Optional, Any, List, Dict, Union
from ..client import SeamHttpClient
from .models import AbstractLocks, ActionAttempt, Device
from .locks_simulate import LocksSimulate
from ..modules.action_attempts import resolve_action_attempt
class Locks(AbstractLocks):
def __init__(self, client: SeamHttpClient, defaults: Dict[str, Any]):
self.client = client
self.defaults = defaults
self._simulate = LocksSimulate(client=client, defaults=defaults)
@property
def simulate(self) -> LocksSimulate:
return self._simulate
def configure_auto_lock(
self,
*,
auto_lock_enabled: bool,
device_id: str,
auto_lock_delay_seconds: Optional[float] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if auto_lock_enabled is not None:
json_payload["auto_lock_enabled"] = auto_lock_enabled
if device_id is not None:
json_payload["device_id"] = device_id
if auto_lock_delay_seconds is not None:
json_payload["auto_lock_delay_seconds"] = auto_lock_delay_seconds
res = self.client.post("/locks/configure_auto_lock", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def get(
self, *, device_id: Optional[str] = None, name: Optional[str] = None
) -> Device:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if name is not None:
json_payload["name"] = name
res = self.client.post("/locks/get", json=json_payload)
return Device.from_dict(res["device"])
def list(
self,
*,
connect_webview_id: Optional[str] = None,
connected_account_id: Optional[str] = None,
connected_account_ids: Optional[List[str]] = None,
created_before: Optional[str] = None,
custom_metadata_has: Optional[Dict[str, Any]] = None,
customer_key: Optional[str] = None,
device_ids: Optional[List[str]] = None,
device_type: Optional[str] = None,
device_types: Optional[List[str]] = None,
exclude_if: Optional[List[str]] = None,
include_if: Optional[List[str]] = None,
limit: Optional[float] = None,
manufacturer: Optional[str] = None,
page_cursor: Optional[str] = None,
search: Optional[str] = None,
space_id: Optional[str] = None,
unstable_location_id: Optional[str] = None,
user_identifier_key: Optional[str] = None
) -> List[Device]:
json_payload = {}
if connect_webview_id is not None:
json_payload["connect_webview_id"] = connect_webview_id
if connected_account_id is not None:
json_payload["connected_account_id"] = connected_account_id
if connected_account_ids is not None:
json_payload["connected_account_ids"] = connected_account_ids
if created_before is not None:
json_payload["created_before"] = created_before
if custom_metadata_has is not None:
json_payload["custom_metadata_has"] = custom_metadata_has
if customer_key is not None:
json_payload["customer_key"] = customer_key
if device_ids is not None:
json_payload["device_ids"] = device_ids
if device_type is not None:
json_payload["device_type"] = device_type
if device_types is not None:
json_payload["device_types"] = device_types
if exclude_if is not None:
json_payload["exclude_if"] = exclude_if
if include_if is not None:
json_payload["include_if"] = include_if
if limit is not None:
json_payload["limit"] = limit
if manufacturer is not None:
json_payload["manufacturer"] = manufacturer
if page_cursor is not None:
json_payload["page_cursor"] = page_cursor
if search is not None:
json_payload["search"] = search
if space_id is not None:
json_payload["space_id"] = space_id
if unstable_location_id is not None:
json_payload["unstable_location_id"] = unstable_location_id
if user_identifier_key is not None:
json_payload["user_identifier_key"] = user_identifier_key
res = self.client.post("/locks/list", json=json_payload)
return [Device.from_dict(item) for item in res["devices"]]
def lock_door(
self,
*,
device_id: str,
sync: Optional[bool] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if sync is not None:
json_payload["sync"] = sync
res = self.client.post("/locks/lock_door", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def unlock_door(
self,
*,
device_id: str,
sync: Optional[bool] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if sync is not None:
json_payload["sync"] = sync
res = self.client.post("/locks/unlock_door", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)