-
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
Conversation
Adding support for a Dooya DT360E-45/20 (Device ID: 4F6E)
Adding support for a Dooya DT360E-45/20 (Device ID: 4F6E)
broadlink/__init__.py
Outdated
@@ -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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful.
@burjakremen Thank you very much for the contribution! |
broadlink/cover.py
Outdated
"""Return the position of the curtain.""" | ||
return self._send(0xca, 0xc0 ,0x06, 0x5d) | ||
|
||
def set_percentage_and_wait(self, new_percentage) -> int: |
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.
def set_percentage(self, new_percentage: int) -> int:
broadlink/cover.py
Outdated
payload = self.decrypt(response[0x38:]) | ||
return payload[17] | ||
|
||
def open(self) -> int: |
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.
What does the integer returned by this function represent?
Fixing errors in code
Fixing code error
broadlink/cover.py
Outdated
"""Return the position of the curtain.""" | ||
return self._send(0xca, 0xc0 ,0x06, 0x00) | ||
|
||
def set_percentage_and_wait(self, new_percentage) -> None: |
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.
I think this method should be renamed to set_percentage
because it is non-blocking.
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.
` return self._send(0xca, 0xc0 ,0x06, 0x00)
def set_percentage(self, new_percentage) -> None:
new_percent_hex = struct.pack('<H', 49357+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.
Does the device wait until the position is reached to send the response?
Rename method "def set_percentage_and_wait" -> "def set_percentage"
broadlink/cover.py
Outdated
device.__init__(self, *args, **kwargs) | ||
self.type = "Dooya DT360E(4F6E)" | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the "magic1" and "magic2" parameters.
Rename "magic3" to "command".
Rename "magic4" to "attribute" and set default to 0.
def _send(self, command: int, attribute: int = 0) -> int:
broadlink/cover.py
Outdated
packet[6] = magic1 | ||
packet[7] = magic2 |
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.
This magic is called checksum. We can use this:
checksum = 0xc0c4 + command + attribute & 0xffff
packet[6] = checksum & 0xff
packet[7] = checksum >> 8
broadlink/cover.py
Outdated
packet[15] = magic3 | ||
packet[16] = magic4 |
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.
Rename "magic3" to "command" and "magic4" to "attribute".
broadlink/cover.py
Outdated
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
self._send(0x01)
broadlink/cover.py
Outdated
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
self._send(0x02)
broadlink/cover.py
Outdated
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
self._send(0x03)
broadlink/cover.py
Outdated
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
self._send(0x06)
broadlink/cover.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
self._send(0x09, new_percentage)
broadlink/cover.py
Outdated
@@ -1,5 +1,6 @@ | |||
"""Support for covers.""" | |||
import time | |||
import struct |
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.
Remove unused import.
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.
Thanks for your constructive comments. All necessary changes have been made.
Add GH Actions
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.
This code looks very good. Latest suggestions (not mandatory)...
broadlink/cover.py
Outdated
@@ -58,3 +58,52 @@ 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 comment
The reason will be displayed to describe this comment to others. Learn more.
class dt36b(device):
broadlink/cover.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
self.type = "DT36B"
broadlink/__init__.py
Outdated
@@ -5,7 +5,7 @@ | |||
|
|||
from .alarm import S1C | |||
from .climate import hysen | |||
from .cover import dooya | |||
from .cover import dooya, dooya_new |
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.
from .cover import dooya, dt36b
broadlink/__init__.py
Outdated
@@ -92,6 +92,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 comment
The reason will be displayed to describe this comment to others. Learn more.
0x4F6E: (dt36b, "DT360E-45/20", "Dooya"),
broadlink/cover.py
Outdated
@@ -58,3 +58,52 @@ def set_percentage_and_wait(self, new_percentage: int) -> None: | |||
time.sleep(0.2) | |||
current = self.get_percentage() | |||
self.stop() | |||
|
|||
class dooya_new(device): | |||
"""Controls a Dooya curtain motor.""" |
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.
"""Controls a Dooya DT360E (type B)."""
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.
All done
This code looks really good. I think it is ready to be merged. My only doubt is about the name of the class. Maybe we should rename dooya to dt1 and this one to dt2? Or use dt360 and dt360b? I don't know. @mjg59 May I have your opinion on this? |
What's status here? I have |
@felipediel Hi, can you merge |
Hi. This code is outdated, I will rebase and give it some treatment when I find the time |
I think it's better to make it work first then improve it later. Adding a hexadecimal code is not that difficult, it doesn't take three years. If this is an active project, valuing code quality is understandable, but since updates are not frequent, why not add it first? |
It's not just a hex code, it needs a PR rebase and Home Assistant integration. It will take some time. |
Hi, why did you close, it's a really good addition to the project, could you please reopen it? |
Reopen here: #770 |
Add support for a new Dooya DT360E-45/20 curtain motor`s (Device ID: 4F6E)