Skip to content
Closed
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, dooya_v2
from .device import Device, ping, scan
from .hub import s3
from .light import lb1, lb2
Expand Down Expand Up @@ -178,6 +178,9 @@
dooya: {
0x4E4D: ("DT360E-45/20", "Dooya"),
},
dooya_v2: {
0x4F6E: ("DT360E-45/20", "Dooya_v2"),
},
bg1: {
0x51E3: ("BG800/BG900", "BG Electrical"),
},
Expand Down
69 changes: 69 additions & 0 deletions broadlink/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,72 @@ def set_percentage_and_wait(self, new_percentage: int) -> None:
time.sleep(0.2)
current = self.get_percentage()
self.stop()



class dooya_v2(Device):
"""Controls a Dooya DT360E (type B)."""

def __init__(self, *args, **kwargs) -> None:
"""Initialize the controller."""
Device.__init__(self, *args, **kwargs)

TYPE = "Dooya DT360E v2"


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[17]

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) -> None: # more accurate
"""Set the position of the curtain."""
self._send(0x09, new_percentage)

def set_percentage_and_wait(self, new_percentage: int) -> None:
"""Set the position of the curtain."""
current = self.get_percentage()
if current > new_percentage:
self.close()
while current is not None and current > new_percentage:
time.sleep(0.2)
current = self.get_percentage()

elif current < new_percentage:
self.open()
while current is not None and current < new_percentage:
time.sleep(0.2)
current = self.get_percentage()
self.stop()