-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for New Dooya motor`s (0x4f6E) #431
Changes from 5 commits
a2eec32
0de42b1
af4163a
43c3745
119fb0c
2031674
4fd2b16
ebaac1f
97077d3
25856e3
d09f501
9482804
153b96f
922eb45
75e483c
1799a8c
29345a1
5c37f85
aa516d8
3cd4dcd
c08c274
4dbabc9
3cca9b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
from .alarm import S1C | ||
from .climate import hysen | ||
from .cover import dooya | ||
from .cover import dooya, dooya_new | ||
from .device import device, scan | ||
from .exceptions import exception | ||
from .light import lb1 | ||
|
@@ -86,6 +86,7 @@ | |
0x2722: (S1C, "S2KIT", "Broadlink"), | ||
0x4ead: (hysen, "HY02B05H", "Hysen"), | ||
0x4e4d: (dooya, "DT360E-45/20", "Dooya"), | ||
0x4f6e: (dooya_new, "DT360E-45/20", "Dooya"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did you get the model name from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beautiful. |
||
0x51e3: (bg1, "BG800/BG900", "BG Electrical"), | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Support for covers.""" | ||
import time | ||
import struct | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your constructive comments. All necessary changes have been made. |
||
|
||
from .device import device | ||
from .exceptions import check_error | ||
|
@@ -58,3 +59,55 @@ def set_percentage_and_wait(self, new_percentage: int) -> None: | |
time.sleep(0.2) | ||
current = self.get_percentage() | ||
self.stop() | ||
|
||
class dooya_new(device): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. class dt36b(device): |
||
"""Controls a Dooya curtain motor.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. """Controls a Dooya DT360E (type B).""" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All done |
||
|
||
def __init__(self, *args, **kwargs) -> None: | ||
"""Initialize the controller.""" | ||
device.__init__(self, *args, **kwargs) | ||
self.type = "Dooya DT360E(4F6E)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self.type = "DT36B" |
||
|
||
def _send(self, magic1: int, magic2: int, magic3:int, magic4:int) -> int: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the "magic1" and "magic2" parameters. def _send(self, command: int, attribute: int = 0) -> int: |
||
"""Send a packet to the device.""" | ||
packet = bytearray(32) | ||
packet[0] = 0x16 | ||
packet[2] = 0xa5 | ||
packet[3] = 0xa5 | ||
packet[4] = 0x5a | ||
packet[5] = 0x5a | ||
packet[6] = magic1 | ||
packet[7] = magic2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This magic is called checksum. We can use this: checksum = 0xc0c4 + command + attribute & 0xffff
packet[6] = checksum & 0xff
packet[7] = checksum >> 8 |
||
packet[8] = 0x02 | ||
packet[9] = 0x0b | ||
packet[10] = 0x0a | ||
packet[15] = magic3 | ||
packet[16] = magic4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename "magic3" to "command" and "magic4" to "attribute". |
||
response = self.send_packet(0x6a, packet) | ||
check_error(response[0x22:0x24]) | ||
payload = self.decrypt(response[0x38:]) | ||
return payload[17] | ||
|
||
def open(self) -> None: | ||
"""Open the curtain.""" | ||
self._send(0xc5, 0xc0, 0x01, 0x00) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self._send(0x01) |
||
|
||
def close(self) -> None: | ||
"""Close the curtain.""" | ||
self._send(0xc6, 0xc0, 0x02, 0x00) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self._send(0x02) |
||
|
||
def stop(self) -> None: | ||
"""Stop the curtain.""" | ||
self._send(0xc7, 0xc0, 0x03, 0x00) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self._send(0x03) |
||
|
||
def get_percentage(self) -> int: | ||
"""Return the position of the curtain.""" | ||
return self._send(0xca, 0xc0 ,0x06, 0x00) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self._send(0x06) |
||
|
||
def set_percentage_and_wait(self, new_percentage) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this method should be renamed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ` return self._send(0xca, 0xc0 ,0x06, 0x00)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the device wait until the position is reached to send the response? |
||
new_percent_hex = struct.pack('<H', 49357+new_percentage) | ||
magic1 = new_percent_hex[0] | ||
magic2 = new_percent_hex[1] | ||
magic3 = 0x09 | ||
magic4 = new_percentage | ||
self._send(magic1, magic2, magic3, magic4) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self._send(0x09, new_percentage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.