-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat(ed): add new query01 msg for ed device #328
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -8,7 +8,13 @@ | |||||
from midealocal.device import MideaDevice | ||||||
from midealocal.message import ListTypes | ||||||
|
||||||
from .message import MessageEDResponse, MessageNewSet, MessageOldSet, MessageQuery | ||||||
from .message import ( | ||||||
MessageEDResponse, | ||||||
MessageNewSet, | ||||||
MessageOldSet, | ||||||
MessageQuery, | ||||||
MessageQuery01, | ||||||
) | ||||||
|
||||||
_LOGGER = logging.getLogger(__name__) | ||||||
|
||||||
|
@@ -77,9 +83,12 @@ def _use_new_set(self) -> bool: | |||||
# if (self.sub_type > 342 or self.sub_type == 340) else False | ||||||
return True | ||||||
|
||||||
def build_query(self) -> list[MessageQuery]: | ||||||
def build_query(self) -> list[MessageQuery | MessageQuery01]: | ||||||
"""Midea ED device build query.""" | ||||||
return [MessageQuery(self._message_protocol_version, self._device_class)] | ||||||
return [ | ||||||
MessageQuery(self._message_protocol_version), | ||||||
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.
Suggested change
|
||||||
MessageQuery01(self._message_protocol_version), | ||||||
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.
Suggested change
|
||||||
] | ||||||
|
||||||
def process_message(self, msg: bytes) -> dict[str, Any]: | ||||||
"""Midea ED device process message.""" | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,11 @@ def _body(self) -> bytearray: | |
class MessageQuery(MessageEDBase): | ||
"""ED message query.""" | ||
|
||
def __init__(self, protocol_version: int, body_type: ListTypes) -> None: | ||
def __init__( | ||
self, | ||
protocol_version: int, | ||
body_type: ListTypes = ListTypes.X00, | ||
) -> None: | ||
"""Initialize ED message query.""" | ||
super().__init__( | ||
protocol_version=protocol_version, | ||
|
@@ -77,6 +81,26 @@ def _body(self) -> bytearray: | |
return bytearray([0x01]) | ||
|
||
|
||
class MessageQuery01(MessageEDBase): | ||
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 class isn't needed |
||
"""ED message query01.""" | ||
|
||
def __init__( | ||
self, | ||
protocol_version: int, | ||
body_type: ListTypes = ListTypes.X01, | ||
) -> None: | ||
"""Initialize ED message query01.""" | ||
super().__init__( | ||
protocol_version=protocol_version, | ||
message_type=MessageType.query, | ||
body_type=body_type, | ||
) | ||
|
||
@property | ||
def _body(self) -> bytearray: | ||
return bytearray([0x01]) | ||
|
||
|
||
class MessageNewSet(MessageEDBase): | ||
"""ED message new set.""" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
from midealocal.const import ProtocolVersion | ||
from midealocal.devices.ed import DeviceAttributes, MideaEDDevice | ||
from midealocal.devices.ed.message import MessageQuery | ||
from midealocal.devices.ed.message import MessageQuery, MessageQuery01 | ||
|
||
|
||
class TestMideaEDDevice: | ||
|
@@ -89,8 +89,9 @@ def test_process_message(self) -> None: | |
def test_build_query(self) -> None: | ||
"""Test build query.""" | ||
queries = self.device.build_query() | ||
assert len(queries) == 1 | ||
assert len(queries) == 2 | ||
assert isinstance(queries[0], MessageQuery) | ||
assert isinstance(queries[1], MessageQuery01) | ||
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. Check body_type value here. |
||
|
||
def test_set_attribute(self) -> None: | ||
"""Test set attribute.""" | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -14,6 +14,7 @@ | |||
MessageEDResponse, | ||||
MessageNewSet, | ||||
MessageQuery, | ||||
MessageQuery01, | ||||
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.
Suggested change
|
||||
) | ||||
from midealocal.message import ListTypes, MessageType | ||||
|
||||
|
@@ -39,9 +40,20 @@ def test_query_body(self) -> None: | |||
"""Test query body.""" | ||||
query = MessageQuery( | ||||
protocol_version=ProtocolVersion.V1, | ||||
body_type=ListTypes.X02, | ||||
) | ||||
expected_body = bytearray([0x02, 0x01]) | ||||
expected_body = bytearray([0x00, 0x01]) | ||||
assert query.body == expected_body | ||||
|
||||
|
||||
class TestMessageQuery01: | ||||
"""Test Message Query01.""" | ||||
|
||||
def test_query_body(self) -> None: | ||||
"""Test query body.""" | ||||
query = MessageQuery01( | ||||
protocol_version=ProtocolVersion.V1, | ||||
) | ||||
expected_body = bytearray([0x01, 0x01]) | ||||
assert query.body == expected_body | ||||
|
||||
|
||||
|
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.
if device NOT support
MessageQuery
and ONLY supportMessageQuery01
, we only useMessageQuery
with the same name, when device sendMessageQuery
with body 00, it will addMessageQuery
toself._unsupported_protocol
, soMessageQuery
with body 01 will be ignored and can't work anymore.this is the reason why we need to add it with a different class name