broadlink-async 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,457 @@
1
+ """Support for climate control."""
2
+
3
+ import enum
4
+ import struct
5
+ from collections.abc import Sequence
6
+
7
+ from . import exceptions as e
8
+ from .device import Device
9
+ from .helpers import CRC16
10
+
11
+
12
+ class hysen(Device):
13
+ """Controls a Hysen heating thermostat.
14
+
15
+ This device is manufactured by Hysen and sold under different
16
+ brands, including Floureon, Beca Energy, Beok and Decdeal.
17
+
18
+ Supported models:
19
+ - HY02B05H
20
+ - HY03WE
21
+ """
22
+
23
+ TYPE = "HYS"
24
+
25
+ async def send_request(self, request: Sequence[int]) -> bytes:
26
+ """Send a request to the device."""
27
+ packet = bytearray()
28
+ packet.extend((len(request) + 2).to_bytes(2, "little"))
29
+ packet.extend(request)
30
+ packet.extend(CRC16.calculate(request).to_bytes(2, "little"))
31
+
32
+ response = await self.send_packet(0x6A, packet)
33
+ e.check_error(response[0x22:0x24])
34
+ payload = self.decrypt(response[0x38:])
35
+
36
+ p_len = int.from_bytes(payload[:0x02], "little")
37
+ nom_crc = int.from_bytes(payload[p_len : p_len + 2], "little")
38
+ real_crc = CRC16.calculate(payload[0x02:p_len])
39
+
40
+ if nom_crc != real_crc:
41
+ raise e.DataValidationError(
42
+ -4008,
43
+ "Received data packet check error",
44
+ f"Expected a checksum of {nom_crc} and received {real_crc}",
45
+ )
46
+
47
+ return payload[0x02:p_len]
48
+
49
+ def _decode_temp(self, payload, base_index):
50
+ base_temp = payload[base_index] / 2.0
51
+ add_offset = (payload[4] >> 3) & 1 # should offset be added?
52
+ offset_raw_value = (payload[17] >> 4) & 3 # offset value
53
+ offset = (offset_raw_value + 1) / 10 if add_offset else 0.0
54
+ return base_temp + offset
55
+
56
+ async def get_temp(self) -> float:
57
+ """Return the room temperature in degrees celsius."""
58
+ payload = await self.send_request([0x01, 0x03, 0x00, 0x00, 0x00, 0x08])
59
+ return self._decode_temp(payload, 5)
60
+
61
+ async def get_external_temp(self) -> float:
62
+ """Return the external temperature in degrees celsius."""
63
+ payload = await self.send_request([0x01, 0x03, 0x00, 0x00, 0x00, 0x08])
64
+ return self._decode_temp(payload, 18)
65
+
66
+ async def get_full_status(self) -> dict:
67
+ """Return the state of the device.
68
+
69
+ Timer schedule included.
70
+ """
71
+ payload = await self.send_request([0x01, 0x03, 0x00, 0x00, 0x00, 0x16])
72
+ data = {}
73
+ data["remote_lock"] = payload[3] & 1
74
+ data["power"] = payload[4] & 1
75
+ data["active"] = (payload[4] >> 4) & 1
76
+ data["temp_manual"] = (payload[4] >> 6) & 1
77
+ data["heating_cooling"] = (payload[4] >> 7) & 1
78
+ data["room_temp"] = self._decode_temp(payload, 5)
79
+ data["thermostat_temp"] = payload[6] / 2.0
80
+ data["auto_mode"] = payload[7] & 0x0F
81
+ data["loop_mode"] = payload[7] >> 4
82
+ data["sensor"] = payload[8]
83
+ data["osv"] = payload[9]
84
+ data["dif"] = payload[10]
85
+ data["svh"] = payload[11]
86
+ data["svl"] = payload[12]
87
+ data["room_temp_adj"] = int.from_bytes(payload[13:15], "big", signed=True) / 10.0
88
+ data["fre"] = payload[15]
89
+ data["poweron"] = payload[16]
90
+ data["unknown"] = payload[17]
91
+ data["external_temp"] = self._decode_temp(payload, 18)
92
+ data["hour"] = payload[19]
93
+ data["min"] = payload[20]
94
+ data["sec"] = payload[21]
95
+ data["dayofweek"] = payload[22]
96
+
97
+ weekday = []
98
+ for i in range(0, 6):
99
+ weekday.append(
100
+ {
101
+ "start_hour": payload[2 * i + 23],
102
+ "start_minute": payload[2 * i + 24],
103
+ "temp": payload[i + 39] / 2.0,
104
+ }
105
+ )
106
+
107
+ data["weekday"] = weekday
108
+ weekend = []
109
+ for i in range(6, 8):
110
+ weekend.append(
111
+ {
112
+ "start_hour": payload[2 * i + 23],
113
+ "start_minute": payload[2 * i + 24],
114
+ "temp": payload[i + 39] / 2.0,
115
+ }
116
+ )
117
+
118
+ data["weekend"] = weekend
119
+ return data
120
+
121
+ # Change controller mode
122
+ # auto_mode = 1 for auto (scheduled/timed) mode, 0 for manual mode.
123
+ # Manual mode will activate last used temperature.
124
+ # In typical usage call set_temp to activate manual control and set temp.
125
+ # loop_mode refers to index in [ "12345,67", "123456,7", "1234567" ]
126
+ # E.g. loop_mode = 0 ("12345,67") means Saturday and Sunday (weekend schedule)
127
+ # loop_mode = 2 ("1234567") means every day, including Saturday and Sunday (weekday schedule)
128
+ # The sensor command is currently experimental
129
+ async def set_mode(self, auto_mode: int, loop_mode: int, sensor: int = 0) -> None:
130
+ """Set the mode of the device."""
131
+ mode_byte = ((loop_mode + 1) << 4) + auto_mode
132
+ await self.send_request([0x01, 0x06, 0x00, 0x02, mode_byte, sensor])
133
+
134
+ # Advanced settings
135
+ # Sensor mode (SEN) sensor = 0 for internal sensor, 1 for external sensor,
136
+ # 2 for internal control temperature, external limit temperature. Factory default: 0.
137
+ # Set temperature range for external sensor (OSV) osv = 5..99. Factory default: 42C
138
+ # Deadzone for floor temprature (dIF) dif = 1..9. Factory default: 2C
139
+ # Upper temperature limit for internal sensor (SVH) svh = 5..99. Factory default: 35C
140
+ # Lower temperature limit for internal sensor (SVL) svl = 5..99. Factory default: 5C
141
+ # Actual temperature calibration (AdJ) adj = -0.5. Precision 0.1C
142
+ # Anti-freezing function (FrE) fre = 0 for anti-freezing function shut down,
143
+ # 1 for anti-freezing function open. Factory default: 0
144
+ # Power on memory (POn) poweron = 0 for off, 1 for on. Default: 0
145
+ async def set_advanced(
146
+ self,
147
+ loop_mode: int,
148
+ sensor: int,
149
+ osv: int,
150
+ dif: int,
151
+ svh: int,
152
+ svl: int,
153
+ adj: float,
154
+ fre: int,
155
+ poweron: int,
156
+ ) -> None:
157
+ """Set advanced options."""
158
+ await self.send_request(
159
+ [
160
+ 0x01,
161
+ 0x10,
162
+ 0x00,
163
+ 0x02,
164
+ 0x00,
165
+ 0x05,
166
+ 0x0A,
167
+ loop_mode,
168
+ sensor,
169
+ osv,
170
+ dif,
171
+ svh,
172
+ svl,
173
+ int(adj * 10) >> 8 & 0xFF,
174
+ int(adj * 10) & 0xFF,
175
+ fre,
176
+ poweron,
177
+ ]
178
+ )
179
+
180
+ # For backwards compatibility only. Prefer calling set_mode directly.
181
+ # Note this function invokes loop_mode=0 and sensor=0.
182
+ async def switch_to_auto(self) -> None:
183
+ """Switch mode to auto."""
184
+ await self.set_mode(auto_mode=1, loop_mode=0)
185
+
186
+ async def switch_to_manual(self) -> None:
187
+ """Switch mode to manual."""
188
+ await self.set_mode(auto_mode=0, loop_mode=0)
189
+
190
+ # Set temperature for manual mode (also activates manual mode if currently in automatic)
191
+ async def set_temp(self, temp: float) -> None:
192
+ """Set the target temperature."""
193
+ await self.send_request([0x01, 0x06, 0x00, 0x01, 0x00, int(temp * 2)])
194
+
195
+ # Set device on(1) or off(0), does not deactivate Wifi connectivity.
196
+ # Remote lock disables control by buttons on thermostat.
197
+ # heating_cooling: heating(0) cooling(1)
198
+ async def set_power(
199
+ self, power: int = 1, remote_lock: int = 0, heating_cooling: int = 0
200
+ ) -> None:
201
+ """Set the power state of the device."""
202
+ state = (heating_cooling << 7) + power
203
+ await self.send_request([0x01, 0x06, 0x00, 0x00, remote_lock, state])
204
+
205
+ # set time on device
206
+ # n.b. day=1 is Monday, ..., day=7 is Sunday
207
+ async def set_time(self, hour: int, minute: int, second: int, day: int) -> None:
208
+ """Set the time."""
209
+ await self.send_request(
210
+ [0x01, 0x10, 0x00, 0x08, 0x00, 0x02, 0x04, hour, minute, second, day]
211
+ )
212
+
213
+ # Set timer schedule
214
+ # Format is the same as you get from get_full_status.
215
+ # weekday is a list (ordered) of 6 dicts like:
216
+ # {'start_hour':17, 'start_minute':30, 'temp': 22 }
217
+ # Each one specifies the thermostat temp that will become effective at start_hour:start_minute
218
+ # weekend is similar but only has 2 (e.g. switch on in morning and off in afternoon)
219
+ async def set_schedule(self, weekday: list[dict], weekend: list[dict]) -> None:
220
+ """Set timer schedule."""
221
+ request = [0x01, 0x10, 0x00, 0x0A, 0x00, 0x0C, 0x18]
222
+
223
+ # weekday times
224
+ for i in range(0, 6):
225
+ request.append(weekday[i]["start_hour"])
226
+ request.append(weekday[i]["start_minute"])
227
+
228
+ # weekend times
229
+ for i in range(0, 2):
230
+ request.append(weekend[i]["start_hour"])
231
+ request.append(weekend[i]["start_minute"])
232
+
233
+ # weekday temperatures
234
+ for i in range(0, 6):
235
+ request.append(int(weekday[i]["temp"] * 2))
236
+
237
+ # weekend temperatures
238
+ for i in range(0, 2):
239
+ request.append(int(weekend[i]["temp"] * 2))
240
+
241
+ await self.send_request(request)
242
+
243
+
244
+ class hvac(Device):
245
+ """Controls a HVAC.
246
+
247
+ Supported models:
248
+ - Tornado SMART X SQ series
249
+ - Aux ASW-H12U3/JIR1DI-US
250
+ - Aux ASW-H36U2/LFR1DI-US
251
+ """
252
+
253
+ TYPE = "HVAC"
254
+
255
+ @enum.unique
256
+ class Mode(enum.IntEnum):
257
+ """Enumerates modes."""
258
+
259
+ AUTO = 0
260
+ COOL = 1
261
+ DRY = 2
262
+ HEAT = 3
263
+ FAN = 4
264
+
265
+ @enum.unique
266
+ class Speed(enum.IntEnum):
267
+ """Enumerates fan speed."""
268
+
269
+ HIGH = 1
270
+ MID = 2
271
+ LOW = 3
272
+ AUTO = 5
273
+
274
+ @enum.unique
275
+ class Preset(enum.IntEnum):
276
+ """Enumerates presets."""
277
+
278
+ NORMAL = 0
279
+ TURBO = 1
280
+ MUTE = 2
281
+
282
+ @enum.unique
283
+ class SwHoriz(enum.IntEnum):
284
+ """Enumerates horizontal swing."""
285
+
286
+ ON = 0
287
+ OFF = 7
288
+
289
+ @enum.unique
290
+ class SwVert(enum.IntEnum):
291
+ """Enumerates vertical swing."""
292
+
293
+ ON = 0
294
+ POS1 = 1
295
+ POS2 = 2
296
+ POS3 = 3
297
+ POS4 = 4
298
+ POS5 = 5
299
+ OFF = 7
300
+
301
+ def _encode(self, data: bytes) -> bytes:
302
+ """Encode data for transport."""
303
+ packet = bytearray(10)
304
+ p_len = 10 + len(data)
305
+ struct.pack_into("<HHHHH", packet, 0, p_len, 0x00BB, 0x8006, 0, len(data))
306
+ packet += data
307
+ crc = CRC16.calculate(packet[0x02:], polynomial=0x9BE4)
308
+ packet += crc.to_bytes(2, "little")
309
+ return packet
310
+
311
+ def _decode(self, response: bytes) -> bytes:
312
+ """Decode data from transport."""
313
+ # payload[0x2:0x8] == bytes([0xbb, 0x00, 0x07, 0x00, 0x00, 0x00])
314
+ payload = self.decrypt(response[0x38:])
315
+ p_len = int.from_bytes(payload[:0x02], "little")
316
+ nom_crc = int.from_bytes(payload[p_len : p_len + 2], "little")
317
+ real_crc = CRC16.calculate(payload[0x02:p_len], polynomial=0x9BE4)
318
+
319
+ if nom_crc != real_crc:
320
+ raise e.DataValidationError(
321
+ -4008,
322
+ "Received data packet check error",
323
+ f"Expected a checksum of {nom_crc} and received {real_crc}",
324
+ )
325
+
326
+ d_len = int.from_bytes(payload[0x08:0x0A], "little")
327
+ return payload[0x0A : 0x0A + d_len]
328
+
329
+ async def _send(self, command: int, data: bytes = b"") -> bytes:
330
+ """Send a command to the unit."""
331
+ prefix = bytes([((command << 4) | 1), 1])
332
+ packet = self._encode(prefix + data)
333
+ response = await self.send_packet(0x6A, packet)
334
+ e.check_error(response[0x22:0x24])
335
+ return self._decode(response)[0x02:]
336
+
337
+ def _parse_state(self, data: bytes) -> dict:
338
+ """Parse state."""
339
+ state = {}
340
+ state["power"] = bool(data[0x08] & 1 << 5)
341
+ state["target_temp"] = 8 + (data[0x00] >> 3) + (data[0x04] >> 7) * 0.5
342
+ state["swing_v"] = self.SwVert(data[0x00] & 0b111)
343
+ state["swing_h"] = self.SwHoriz(data[0x01] >> 5)
344
+ state["mode"] = self.Mode(data[0x05] >> 5)
345
+ state["speed"] = self.Speed(data[0x03] >> 5)
346
+ state["preset"] = self.Preset(data[0x04] >> 6)
347
+ state["sleep"] = bool(data[0x05] & 1 << 2)
348
+ state["ifeel"] = bool(data[0x05] & 1 << 3)
349
+ state["health"] = bool(data[0x08] & 1 << 1)
350
+ state["clean"] = bool(data[0x08] & 1 << 2)
351
+ state["display"] = bool(data[0x0A] & 1 << 4)
352
+ state["mildew"] = bool(data[0x0A] & 1 << 3)
353
+ return state
354
+
355
+ async def set_state(
356
+ self,
357
+ power: bool,
358
+ target_temp: float, # 16<=target_temp<=32
359
+ mode: Mode,
360
+ speed: Speed,
361
+ preset: Preset,
362
+ swing_h: SwHoriz,
363
+ swing_v: SwVert,
364
+ sleep: bool,
365
+ ifeel: bool,
366
+ display: bool,
367
+ health: bool,
368
+ clean: bool,
369
+ mildew: bool,
370
+ ) -> dict:
371
+ """Set the state of the device."""
372
+ # TODO: decode unknown bits
373
+ UNK0 = 0b100
374
+ UNK1 = 0b1101
375
+ UNK2 = 0b101
376
+
377
+ target_temp = round(target_temp * 2) / 2
378
+
379
+ if preset == self.Preset.MUTE:
380
+ if mode != self.Mode.FAN:
381
+ raise ValueError("mute is only available in fan mode")
382
+ speed = self.Speed.LOW
383
+
384
+ elif preset == self.Preset.TURBO:
385
+ if mode not in {self.Mode.COOL, self.Mode.HEAT}:
386
+ raise ValueError("turbo is only available in cooling/heating")
387
+ speed = self.Speed.HIGH
388
+
389
+ data = bytearray(0x0D)
390
+ data[0x00] = (int(target_temp) - 8 << 3) | swing_v
391
+ data[0x01] = (swing_h << 5) | UNK0
392
+ data[0x02] = ((target_temp % 1 == 0.5) << 7) | UNK1
393
+ data[0x03] = speed << 5
394
+ data[0x04] = preset << 6
395
+ data[0x05] = mode << 5 | sleep << 2 | ifeel << 3
396
+ data[0x08] = power << 5 | clean << 2 | (health and 0b11)
397
+ data[0x0A] = display << 4 | mildew << 3
398
+ data[0x0C] = UNK2
399
+
400
+ resp = await self._send(0, data)
401
+ return self._parse_state(resp)
402
+
403
+ async def get_state(self) -> dict:
404
+ """Returns a dictionary with the unit's parameters.
405
+
406
+ Returns:
407
+ dict:
408
+ power (bool):
409
+ target_temp (float): temperature set point 16<n<32
410
+ mode (hvac.Mode):
411
+ speed (hvac.Speed):
412
+ preset (hvac.Preset):
413
+ swing_h (hvac.SwHoriz):
414
+ swing_v (hvac.SwVert):
415
+ sleep (bool):
416
+ ifeel (bool):
417
+ display (bool):
418
+ health (bool):
419
+ clean (bool):
420
+ mildew (bool):
421
+ """
422
+ resp = await self._send(1)
423
+
424
+ if len(resp) < 13:
425
+ raise e.DataValidationError(
426
+ -4007,
427
+ "Received data packet length error",
428
+ f"Expected at least 15 bytes and received {len(resp) + 2}",
429
+ )
430
+
431
+ return self._parse_state(resp)
432
+
433
+ async def get_ac_info(self) -> dict:
434
+ """Returns dictionary with AC info.
435
+
436
+ Returns:
437
+ dict:
438
+ power (bool): power
439
+ ambient_temp (float): ambient temperature
440
+ """
441
+ resp = await self._send(2)
442
+
443
+ if len(resp) < 22:
444
+ raise e.DataValidationError(
445
+ -4007,
446
+ "Received data packet length error",
447
+ f"Expected at least 24 bytes and received {len(resp) + 2}",
448
+ )
449
+
450
+ ac_info = {}
451
+ ac_info["power"] = resp[0x1] & 1
452
+
453
+ ambient_temp = resp[0x05] & 0b11111, resp[0x15] & 0b11111
454
+ if any(ambient_temp):
455
+ ac_info["ambient_temp"] = ambient_temp[0] + ambient_temp[1] / 10.0
456
+
457
+ return ac_info
@@ -0,0 +1,6 @@
1
+ """Constants."""
2
+
3
+ DEFAULT_BCAST_ADDR = "255.255.255.255"
4
+ DEFAULT_PORT = 80
5
+ DEFAULT_RETRY_INTVL = 1
6
+ DEFAULT_TIMEOUT = 10
@@ -0,0 +1,183 @@
1
+ """Support for covers."""
2
+
3
+ import asyncio
4
+ from collections.abc import Sequence
5
+
6
+ from . import exceptions as e
7
+ from .device import Device
8
+
9
+
10
+ class dooya(Device):
11
+ """Controls a Dooya curtain motor."""
12
+
13
+ TYPE = "DT360E"
14
+
15
+ async def _send(self, command: int, attribute: int = 0) -> int:
16
+ """Send a packet to the device."""
17
+ packet = bytearray(16)
18
+ packet[0x00] = 0x09
19
+ packet[0x02] = 0xBB
20
+ packet[0x03] = command
21
+ packet[0x04] = attribute
22
+ packet[0x09] = 0xFA
23
+ packet[0x0A] = 0x44
24
+
25
+ resp = await self.send_packet(0x6A, packet)
26
+ e.check_error(resp[0x22:0x24])
27
+ payload = self.decrypt(resp[0x38:])
28
+ return payload[4]
29
+
30
+ async def open(self) -> int:
31
+ """Open the curtain."""
32
+ return await self._send(0x01)
33
+
34
+ async def close(self) -> int:
35
+ """Close the curtain."""
36
+ return await self._send(0x02)
37
+
38
+ async def stop(self) -> int:
39
+ """Stop the curtain."""
40
+ return await self._send(0x03)
41
+
42
+ async def get_percentage(self) -> int:
43
+ """Return the position of the curtain."""
44
+ return await self._send(0x06, 0x5D)
45
+
46
+ async def set_percentage_and_wait(self, new_percentage: int) -> None:
47
+ """Set the position of the curtain."""
48
+ current = await self.get_percentage()
49
+ if current > new_percentage:
50
+ await self.close()
51
+ while current is not None and current > new_percentage:
52
+ await asyncio.sleep(0.2)
53
+ current = await self.get_percentage()
54
+
55
+ elif current < new_percentage:
56
+ await self.open()
57
+ while current is not None and current < new_percentage:
58
+ await asyncio.sleep(0.2)
59
+ current = await self.get_percentage()
60
+ await self.stop()
61
+
62
+
63
+ class dooya2(Device):
64
+ """Controls a Dooya curtain motor (version 2)."""
65
+
66
+ TYPE = "DT360E-2"
67
+
68
+ async def _send(self, operation: int, data: Sequence = b""):
69
+ """Send a command to the device."""
70
+ packet = bytearray(12)
71
+ packet[0x02] = 0xA5
72
+ packet[0x03] = 0xA5
73
+ packet[0x04] = 0x5A
74
+ packet[0x05] = 0x5A
75
+ packet[0x08] = operation
76
+ packet[0x09] = 0x0B
77
+
78
+ if data:
79
+ data_len = len(data)
80
+ packet[0x0A] = data_len & 0xFF
81
+ packet[0x0B] = data_len >> 8
82
+ packet += bytes(2)
83
+ packet.extend(data)
84
+
85
+ checksum = sum(packet, 0xBEAF) & 0xFFFF
86
+ packet[0x06] = checksum & 0xFF
87
+ packet[0x07] = checksum >> 8
88
+
89
+ packet_len = len(packet) - 2
90
+ packet[0x00] = packet_len & 0xFF
91
+ packet[0x01] = packet_len >> 8
92
+
93
+ resp = await self.send_packet(0x6A, packet)
94
+ e.check_error(resp[0x22:0x24])
95
+ payload = self.decrypt(resp[0x38:])
96
+ return payload
97
+
98
+ async def open(self) -> None:
99
+ """Open the curtain."""
100
+ await self._send(2, [0x00, 0x01, 0x00])
101
+
102
+ async def close(self) -> None:
103
+ """Close the curtain."""
104
+ await self._send(2, [0x00, 0x02, 0x00])
105
+
106
+ async def stop(self) -> None:
107
+ """Stop the curtain."""
108
+ await self._send(2, [0x00, 0x03, 0x00])
109
+
110
+ async def get_percentage(self) -> int:
111
+ """Return the position of the curtain."""
112
+ resp = await self._send(1, [0x00, 0x06, 0x00])
113
+ return resp[0x11]
114
+
115
+ async def set_percentage(self, new_percentage: int) -> None:
116
+ """Set the position of the curtain."""
117
+ await self._send(2, [0x00, 0x09, new_percentage])
118
+
119
+
120
+ class wser(Device):
121
+ """Controls a Wistar curtain motor"""
122
+
123
+ TYPE = "WSER"
124
+
125
+ async def _send(self, operation: int, data: Sequence = b""):
126
+ """Send a command to the device."""
127
+ packet = bytearray(12)
128
+ packet[0x02] = 0xA5
129
+ packet[0x03] = 0xA5
130
+ packet[0x04] = 0x5A
131
+ packet[0x05] = 0x5A
132
+ packet[0x08] = operation
133
+ packet[0x09] = 0x0B
134
+
135
+ if data:
136
+ data_len = len(data)
137
+ packet[0x0A] = data_len & 0xFF
138
+ packet[0x0B] = data_len >> 8
139
+ packet += bytes(2)
140
+ packet.extend(data)
141
+
142
+ checksum = sum(packet, 0xBEAF) & 0xFFFF
143
+ packet[0x06] = checksum & 0xFF
144
+ packet[0x07] = checksum >> 8
145
+
146
+ packet_len = len(packet) - 2
147
+ packet[0x00] = packet_len & 0xFF
148
+ packet[0x01] = packet_len >> 8
149
+
150
+ resp = await self.send_packet(0x6A, packet)
151
+ e.check_error(resp[0x22:0x24])
152
+ payload = self.decrypt(resp[0x38:])
153
+ return payload
154
+
155
+ async def get_position(self) -> int:
156
+ """Return the position of the curtain."""
157
+ resp = await self._send(1, [])
158
+ position = resp[0x0E]
159
+ return position
160
+
161
+ async def open(self) -> int:
162
+ """Open the curtain."""
163
+ resp = await self._send(2, [0x4A, 0x31, 0xA0])
164
+ position = resp[0x0E]
165
+ return position
166
+
167
+ async def close(self) -> int:
168
+ """Close the curtain."""
169
+ resp = await self._send(2, [0x61, 0x32, 0xA0])
170
+ position = resp[0x0E]
171
+ return position
172
+
173
+ async def stop(self) -> int:
174
+ """Stop the curtain."""
175
+ resp = await self._send(2, [0x4C, 0x73, 0xA0])
176
+ position = resp[0x0E]
177
+ return position
178
+
179
+ async def set_position(self, position: int) -> int:
180
+ """Set the position of the curtain."""
181
+ resp = await self._send(2, [position, 0x70, 0xA0])
182
+ position = resp[0x0E]
183
+ return position