Skip to content
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 Dooya DT360E (v2) #785

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion broadlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .const import DEFAULT_BCAST_ADDR, DEFAULT_PORT, DEFAULT_TIMEOUT
from .alarm import S1C
from .climate import hysen
from .cover import dooya
from .cover import dooya, dooya2
from .device import Device, ping, scan
from .hub import s3
from .light import lb1, lb2
Expand Down Expand Up @@ -180,6 +180,9 @@
dooya: {
0x4E4D: ("DT360E-45/20", "Dooya"),
},
dooya2: {
0x4F6E: ("DT360E-45/20", "Dooya"),
},
bg1: {
0x51E3: ("BG800/BG900", "BG Electrical"),
},
Expand Down
62 changes: 55 additions & 7 deletions broadlink/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
class dooya(Device):
"""Controls a Dooya curtain motor."""

TYPE = "Dooya DT360E"
TYPE = "DT360E"

def _send(self, magic1: int, magic2: int) -> int:
def _send(self, command: int, attribute: int = 0) -> int:
"""Send a packet to the device."""
packet = bytearray(16)
packet[0] = 0x09
packet[2] = 0xBB
packet[3] = magic1
packet[4] = magic2
packet[3] = command
packet[4] = attribute
packet[9] = 0xFA
packet[10] = 0x44
response = self.send_packet(0x6A, packet)
Expand All @@ -26,15 +26,15 @@ def _send(self, magic1: int, magic2: int) -> int:

def open(self) -> int:
"""Open the curtain."""
return self._send(0x01, 0x00)
return self._send(0x01)

def close(self) -> int:
"""Close the curtain."""
return self._send(0x02, 0x00)
return self._send(0x02)

def stop(self) -> int:
"""Stop the curtain."""
return self._send(0x03, 0x00)
return self._send(0x03)

def get_percentage(self) -> int:
"""Return the position of the curtain."""
Expand All @@ -55,3 +55,51 @@ def set_percentage_and_wait(self, new_percentage: int) -> None:
time.sleep(0.2)
current = self.get_percentage()
self.stop()


class dooya2(Device):
"""Controls a Dooya curtain motor (version 2)."""

TYPE = "DT360E-2"

def _send(self, command: int, attribute: int = 0) -> int:
"""Send a packet to the device."""
checksum = 0xC0C4 + command + attribute & 0xFFFF
packet = bytearray(32)
packet[0] = 0x16
packet[2] = 0xA5
packet[3] = 0xA5
packet[4] = 0x5A
packet[5] = 0x5A
packet[6] = checksum & 0xFF
packet[7] = checksum >> 8
packet[8] = 0x02
packet[9] = 0x0B
packet[10] = 0x0A
packet[15] = command
packet[16] = attribute

response = self.send_packet(0x6A, packet)
e.check_error(response[0x22:0x24])
payload = self.decrypt(response[0x38:])
return payload[0x11]

def open(self) -> None:
"""Open the curtain."""
self._send(0x01)

def close(self) -> None:
"""Close the curtain."""
self._send(0x02)

def stop(self) -> None:
"""Stop the curtain."""
self._send(0x03)

def get_percentage(self) -> int:
"""Return the position of the curtain."""
return self._send(0x06)

def set_percentage(self, new_percentage: int) -> None:
"""Set the position of the curtain."""
self._send(0x09, new_percentage)
Loading