1
0
Fork 0

Add support for Dooya DT360E (v2) (#785)

This commit is contained in:
Felipe Martins Diel 2024-04-09 20:32:41 -03:00 committed by GitHub
parent 821820c61e
commit 4766d68289
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 8 deletions

View File

@ -7,7 +7,7 @@ from . import exceptions as e
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
@ -180,6 +180,9 @@ SUPPORTED_TYPES = {
dooya: {
0x4E4D: ("DT360E-45/20", "Dooya"),
},
dooya2: {
0x4F6E: ("DT360E-45/20", "Dooya"),
},
bg1: {
0x51E3: ("BG800/BG900", "BG Electrical"),
},

View File

@ -8,15 +8,15 @@ from .device import Device
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)
@ -26,15 +26,15 @@ class dooya(Device):
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."""
@ -55,3 +55,51 @@ class dooya(Device):
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)