|
8 | 8 |
|
9 | 9 | # Curtain keys |
10 | 10 | CURTAIN_COMMAND = "4501" |
| 11 | + |
| 12 | +# For second element of open and close arrs we should add two bytes i.e. ff00 |
| 13 | +# First byte [ff] stands for speed (00 or ff - normal, 01 - slow) * |
| 14 | +# * Only for curtains 3. For other models use ff |
| 15 | +# Second byte [00] is a command (00 - open, 64 - close) |
11 | 16 | OPEN_KEYS = [ |
12 | 17 | f"{REQ_HEADER}{CURTAIN_COMMAND}010100", |
13 | | - f"{REQ_HEADER}{CURTAIN_COMMAND}05ff00", |
| 18 | + f"{REQ_HEADER}{CURTAIN_COMMAND}05", # +speed + "00" |
14 | 19 | ] |
15 | 20 | CLOSE_KEYS = [ |
16 | 21 | f"{REQ_HEADER}{CURTAIN_COMMAND}010164", |
17 | | - f"{REQ_HEADER}{CURTAIN_COMMAND}05ff64", |
| 22 | + f"{REQ_HEADER}{CURTAIN_COMMAND}05", # +speed + "64" |
18 | 23 | ] |
19 | 24 | POSITION_KEYS = [ |
20 | 25 | f"{REQ_HEADER}{CURTAIN_COMMAND}0101", |
21 | | - f"{REQ_HEADER}{CURTAIN_COMMAND}05ff", |
| 26 | + f"{REQ_HEADER}{CURTAIN_COMMAND}05", # +speed |
22 | 27 | ] # +actual_position |
23 | 28 | STOP_KEYS = [f"{REQ_HEADER}{CURTAIN_COMMAND}0001", f"{REQ_HEADER}{CURTAIN_COMMAND}00ff"] |
24 | 29 |
|
@@ -63,27 +68,33 @@ async def _send_multiple_commands(self, keys: list[str]) -> bool: |
63 | 68 | return final_result |
64 | 69 |
|
65 | 70 | @update_after_operation |
66 | | - async def open(self) -> bool: |
67 | | - """Send open command.""" |
68 | | - return await self._send_multiple_commands(OPEN_KEYS) |
| 71 | + async def open(self, speed: int = 255) -> bool: |
| 72 | + """Send open command. Speed 255 - normal, 1 - slow""" |
| 73 | + return await self._send_multiple_commands( |
| 74 | + [OPEN_KEYS[0], f"{OPEN_KEYS[1]}{speed:02X}00"] |
| 75 | + ) |
69 | 76 |
|
70 | 77 | @update_after_operation |
71 | | - async def close(self) -> bool: |
72 | | - """Send close command.""" |
73 | | - return await self._send_multiple_commands(CLOSE_KEYS) |
| 78 | + async def close(self, speed: int = 255) -> bool: |
| 79 | + """Send close command. Speed 255 - normal, 1 - slow""" |
| 80 | + return await self._send_multiple_commands( |
| 81 | + [CLOSE_KEYS[0], f"{CLOSE_KEYS[1]}{speed:02X}64"] |
| 82 | + ) |
74 | 83 |
|
75 | 84 | @update_after_operation |
76 | 85 | async def stop(self) -> bool: |
77 | 86 | """Send stop command to device.""" |
78 | 87 | return await self._send_multiple_commands(STOP_KEYS) |
79 | 88 |
|
80 | 89 | @update_after_operation |
81 | | - async def set_position(self, position: int) -> bool: |
82 | | - """Send position command (0-100) to device.""" |
| 90 | + async def set_position(self, position: int, speed: int = 255) -> bool: |
| 91 | + """Send position command (0-100) to device. Speed 255 - normal, 1 - slow""" |
83 | 92 | position = (100 - position) if self._reverse else position |
84 | | - hex_position = "%0.2X" % position |
85 | 93 | return await self._send_multiple_commands( |
86 | | - [key + hex_position for key in POSITION_KEYS] |
| 94 | + [ |
| 95 | + f"{POSITION_KEYS[0]}{position:02X}", |
| 96 | + f"{POSITION_KEYS[1]}{speed:02X}{position:02X}", |
| 97 | + ] |
87 | 98 | ) |
88 | 99 |
|
89 | 100 | def get_position(self) -> Any: |
|
0 commit comments