-
Notifications
You must be signed in to change notification settings - Fork 48
feat: Support both a01 and v1 device types with traits #425
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f541de5
feat: Support both a01 and v1 device types with traits
allenporter 4370d30
fix: add safety check for trait creation
allenporter 1a0d3df
feat: Update cli with v1 status trait
allenporter c589925
chore: address code review feedback
allenporter 9165448
chore: Update roborock/devices/v1_channel.py
allenporter 440b0e2
chore: Revert encode_mqtt_payload typing change
allenporter ba06e49
fix: update mqtt payload encoding signature
allenporter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Thin wrapper around the MQTT channel for Roborock A01 devices.""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Any, overload | ||
|
||
from roborock.protocols.a01_protocol import ( | ||
decode_rpc_response, | ||
encode_mqtt_payload, | ||
) | ||
from roborock.roborock_message import RoborockDyadDataProtocol, RoborockZeoProtocol | ||
|
||
from .mqtt_channel import MqttChannel | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@overload | ||
async def send_decoded_command( | ||
mqtt_channel: MqttChannel, | ||
params: dict[RoborockDyadDataProtocol, Any], | ||
) -> dict[RoborockDyadDataProtocol, Any]: | ||
... | ||
|
||
|
||
@overload | ||
async def send_decoded_command( | ||
mqtt_channel: MqttChannel, | ||
params: dict[RoborockZeoProtocol, Any], | ||
) -> dict[RoborockZeoProtocol, Any]: | ||
... | ||
|
||
|
||
async def send_decoded_command( | ||
mqtt_channel: MqttChannel, | ||
params: dict[RoborockDyadDataProtocol, Any] | dict[RoborockZeoProtocol, Any], | ||
) -> dict[RoborockDyadDataProtocol, Any] | dict[RoborockZeoProtocol, Any]: | ||
"""Send a command on the MQTT channel and get a decoded response.""" | ||
_LOGGER.debug("Sending MQTT command: %s", params) | ||
roborock_message = encode_mqtt_payload(params) | ||
response = await mqtt_channel.send_message(roborock_message) | ||
return decode_rpc_response(response) # type: ignore[return-value] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Low-level interface for connections to Roborock devices.""" | ||
|
||
import logging | ||
from collections.abc import Callable | ||
from typing import Protocol | ||
|
||
from roborock.roborock_message import RoborockMessage | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class Channel(Protocol): | ||
"""A generic channel for establishing a connection with a Roborock device. | ||
|
||
Individual channel implementations have their own methods for speaking to | ||
the device that hide some of the protocol specific complexity, but they | ||
are still specialized for the device type and protocol. | ||
""" | ||
|
||
@property | ||
def is_connected(self) -> bool: | ||
"""Return true if the channel is connected.""" | ||
... | ||
|
||
async def subscribe(self, callback: Callable[[RoborockMessage], None]) -> Callable[[], None]: | ||
"""Subscribe to messages from the device.""" | ||
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why can't this just stay as a dict as is? I don't really know what MappingProxyType is
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.
When this returns a
dict
its actually mutable so a caller could theoretically change it. It may be overkill here...