forked from fstercq/freepybox
-
Notifications
You must be signed in to change notification settings - Fork 17
/
home.py
302 lines (252 loc) · 8.63 KB
/
home.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
"""
Home API.
No public documentation available yet.
"""
from typing import Dict
from freebox_api.access import Access
# Home structure : adapter > node > endpoint
class Home:
"""
Home
"""
def __init__(self, access: Access):
self._access = access
home_endpoint_value_schema = {"value": None}
create_home_node_rule_payload_schema = {
"iconUrl": "",
"id": 0,
"label": "",
"name": "",
"role": 0,
"roleLabel": "",
"type": "",
}
node_rule_role_schema = {"node": [0], "role": 0}
node_rule_configuration_data_schema = {"roles": [node_rule_role_schema]}
sms_number_data_schema = {
"description": "Mon numero",
"phoneNumber": "",
"smsEnabled": True,
"voicemailEnabled": True,
}
sms_validation_data_schema = {"applicationHash": ""}
sms_number_validation_data_schema = {"validationCode": ""}
next_pairing_step_payload_schema = {"session": 0, "pageid": 0, "fields": [None]}
start_pairing_step_payload_schema = {"nfc": True, "qrcode": False, "type": ""}
stop_pairing_step_payload_schema = {"session": 0}
async def del_home_adapter(self, home_adapter_id):
"""
Delete home adapter
"""
return await self._access.delete(f"home/adapters/{home_adapter_id}")
async def get_home_adapter(self, home_adapter_id):
"""
Retrieve a registered home adapter
"""
return await self._access.get(f"home/adapters/{home_adapter_id}")
async def get_home_adapters(self):
"""
Retrieve the list of registered home adapters
"""
return await self._access.get("home/adapters")
async def get_camera(self):
"""
Get camera info
"""
return await self._access.get("camera")
async def get_camera_snapshot(self, camera_index=0, size=4, quality=5):
"""
Get camera snapshot
`camera_index`: ``int``
`size`: 2 = 320x240, 3 = 640x480, 4 = 1280x720
`quality`: quality index, default is 5
"""
fbx_cameras = await self.get_camera()
return await self._access.get(
fbx_cameras[camera_index]["stream_url"].replace(
"stream.m3u8", f"snapshot.cgi?size={size}&quality={quality}"
)[1:]
)
async def get_camera_stream_m3u8(self, camera_index=0, channel=2):
"""
Get camera stream
`camera_index`: ``int``
`channel`: 1 is SD, 2 is HD
"""
fbx_cameras = await self.get_camera()
return await self._access.get(
fbx_cameras[camera_index]["stream_url"].replace(
"stream.m3u8", f"stream.m3u8?channel={channel}"
)[1:]
)
async def get_camera_ts(self, ts_name, camera_index=0):
"""
Get camera stream
"""
fbx_cameras = await self.get_camera()
return await self._access.get(
fbx_cameras[camera_index]["stream_url"].replace(
"stream.m3u8", f"{ts_name}"
)[1:]
)
async def get_home_endpoint_value(self, node_id, endpoint_id):
"""
Get home endpoint value
"""
return await self._access.get(f"home/endpoints/{node_id}/{endpoint_id}")
async def get_home_endpoint_values(self, endpoint_list):
"""
Get home endpoint values
"""
return await self._access.post("home/endpoints/get", endpoint_list)
async def set_home_endpoint_value(self, node_id, endpoint_id, home_endpoint_value):
"""
Set home endpoint value
"""
return await self._access.put(
f"home/endpoints/{node_id}/{endpoint_id}", home_endpoint_value
)
async def del_home_link(self, link_id):
"""
Delete home link
"""
return await self._access.delete(f"home/links/{link_id}")
async def get_home_link(self, link_id):
"""
Get home link
"""
return await self._access.get(f"home/links/{link_id}")
async def get_home_links(self):
"""
Get home links
"""
return await self._access.get("home/links")
async def del_home_node(self, node_id: int) -> Dict[str, bool]:
"""
Delete home node id
"""
return await self._access.delete(f"home/nodes/{node_id}") # type: ignore
async def get_home_node(self, node_id):
"""
Get home node id
"""
return await self._access.get(f"home/nodes/{node_id}")
async def edit_home_node(self, node_id, node_data):
"""
Edit home node data
"""
return await self._access.put(f"home/nodes/{node_id}", node_data)
async def get_home_nodes(self):
"""
Get home nodes
"""
return await self._access.get("home/nodes")
async def create_home_node_rule(self, template_name, create_home_node_rule_payload):
"""
Create home node rule
"""
return await self._access.post(
f"home/rules/{template_name}", create_home_node_rule_payload
)
async def get_home_node_existing_rule_config(self, node_id, rule_node_id, role_id):
"""
Get home node existing rule configuration data
"""
return await self._access.get(
f"home/nodes/{node_id}/rules/node/{rule_node_id}/{role_id}"
)
async def get_home_node_template_rule_config(self, node_id, template_name, role_id):
"""
Get node rule template configuration data
"""
return await self._access.get(
f"home/nodes/{node_id}/rules/template/{template_name}/{role_id}"
)
async def set_home_node_rule_config(
self, rule_node_id, node_rule_configuration_data
):
"""
Set node rule configuration data
"""
return await self._access.put(
f"home/rules/{rule_node_id}", node_rule_configuration_data
)
async def get_home_node_new_rules(self, node_id):
"""
Get node new rules
"""
return await self._access.get(f"home/nodes/{node_id}/rules")
async def get_secmod(self):
"""
Get security module
"""
return await self._access.get("home/secmod")
async def create_sms_number(self, sms_number_data):
"""
Create sms number
"""
return await self._access.post("home/sms/numbers", sms_number_data)
async def edit_sms_number(self, sms_number_id, sms_number_data):
"""
Edit sms number
"""
return await self._access.put(
f"home/sms/numbers/{sms_number_id}", sms_number_data
)
async def get_sms_numbers(self):
"""
Get sms numbers
"""
return await self._access.get("home/sms/numbers")
async def send_sms_number_validation(self, sms_number_id, sms_validation_data):
"""
Send sms number validation
"""
return await self._access.post(
f"home/sms/numbers/{sms_number_id}/send_validation_sms", sms_validation_data
)
async def validate_sms_number(self, sms_number_id, sms_number_validation_data):
"""
Validate sms number
"""
return await self._access.post(
f"home/sms/numbers/{sms_number_id}/validate", sms_number_validation_data
)
async def get_home_tile(self, tile_id):
"""
Get the home tile with provided id
"""
return await self._access.get(f"home/tileset/{tile_id}")
async def get_home_tilesets(self):
"""
Get the list of home tileset
"""
return await self._access.get("home/tileset/all")
async def get_home_pairing_state(self, home_adapter_id):
"""
Get the current home pairing state
"""
return await self._access.get(f"home/pairing/{home_adapter_id}")
async def next_home_pairing_step(self, home_adapter_id, next_pairing_step_payload):
"""
Next home pairing step
"""
return await self._access.post(
f"home/pairing/{home_adapter_id}", next_pairing_step_payload
)
async def start_home_pairing_step(
self, home_adapter_id, start_pairing_step_payload
):
"""
Start home pairing step
"""
return await self._access.post(
f"home/pairing/{home_adapter_id}", start_pairing_step_payload
)
async def stop_home_pairing_step(self, home_adapter_id, stop_pairing_step_payload):
"""
Stop home pairing
"""
return await self._access.post(
f"home/pairing/{home_adapter_id}", stop_pairing_step_payload
)