-
Notifications
You must be signed in to change notification settings - Fork 70
feat: Recognize Q10 devices and add a command trait #721
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,38 @@ | ||
| """Thin wrapper around the MQTT channel for Roborock B01 Q10 devices.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP | ||
| from roborock.exceptions import RoborockException | ||
| from roborock.protocols.b01_q10_protocol import ( | ||
| ParamsType, | ||
| encode_mqtt_payload, | ||
| ) | ||
|
|
||
| from .mqtt_channel import MqttChannel | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
| _TIMEOUT = 10.0 | ||
|
|
||
|
|
||
| async def send_command( | ||
| mqtt_channel: MqttChannel, | ||
| command: B01_Q10_DP, | ||
| params: ParamsType, | ||
| ) -> None: | ||
| """Send a command on the MQTT channel, without waiting for a response""" | ||
| _LOGGER.debug("Sending B01 MQTT command: cmd=%s params=%s", command, params) | ||
| roborock_message = encode_mqtt_payload(command, params) | ||
| _LOGGER.debug("Sending MQTT message: %s", roborock_message) | ||
| try: | ||
| await mqtt_channel.publish(roborock_message) | ||
| except RoborockException as ex: | ||
| _LOGGER.debug( | ||
| "Error sending B01 decoded command (method=%s params=%s): %s", | ||
| command, | ||
| params, | ||
| ex, | ||
| ) | ||
| raise | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| """Traits for B01 devices.""" | ||
|
|
||
| from . import q7, q10 | ||
| from .q7 import Q7PropertiesApi | ||
| from .q10 import Q10PropertiesApi | ||
|
|
||
| __all__ = ["Q7PropertiesApi", "q7", "q10"] | ||
| __all__ = [ | ||
| "Q7PropertiesApi", | ||
| "Q10PropertiesApi", | ||
| "q7", | ||
| "q10", | ||
| ] |
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 |
|---|---|---|
| @@ -1 +1,29 @@ | ||
| """Q10""" | ||
| """Traits for Q10 B01 devices.""" | ||
|
|
||
| from typing import Any | ||
|
|
||
| from roborock.devices.b01_q7_channel import send_decoded_command | ||
| from roborock.devices.mqtt_channel import MqttChannel | ||
| from roborock.devices.traits import Trait | ||
|
|
||
| from .command import CommandTrait | ||
|
|
||
| __all__ = [ | ||
| "Q10PropertiesApi", | ||
| ] | ||
|
|
||
|
|
||
| class Q10PropertiesApi(Trait): | ||
| """API for interacting with B01 devices.""" | ||
|
|
||
| command: CommandTrait | ||
| """Trait for sending commands to Q10 devices.""" | ||
|
|
||
| def __init__(self, channel: MqttChannel) -> None: | ||
| """Initialize the B01Props API.""" | ||
| self.command = CommandTrait(channel) | ||
|
|
||
|
|
||
| def create(channel: MqttChannel) -> Q10PropertiesApi: | ||
| """Create traits for B01 devices.""" | ||
| return Q10PropertiesApi(channel) |
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,32 @@ | ||
| from typing import Any | ||
|
|
||
| from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP | ||
| from roborock.devices.b01_q10_channel import send_command | ||
| from roborock.devices.mqtt_channel import MqttChannel | ||
| from roborock.protocols.b01_q10_protocol import ParamsType | ||
|
|
||
|
|
||
| class CommandTrait: | ||
| """Trait for sending commands to Q10 Roborock devices. | ||
|
|
||
| This trait allows sending raw commands directly to the device. It is particularly | ||
| useful for accessing features that do not have their own traits. Generally | ||
| it is preferred to use specific traits for device functionality when | ||
| available. | ||
| """ | ||
|
|
||
| def __init__(self, channel: MqttChannel) -> None: | ||
| """Initialize the CommandTrait.""" | ||
| self._channel = channel | ||
|
|
||
| async def send(self, command: B01_Q10_DP, params: ParamsType = None) -> Any: | ||
| """Send a command to the device. | ||
|
|
||
| Sending a raw command to the device using this method does not update | ||
| the internal state of any other traits. It is the responsibility of the | ||
| caller to ensure that any traits affected by the command are refreshed | ||
| as needed. | ||
| """ | ||
| if not self._channel: | ||
| raise ValueError("Device trait in invalid state") | ||
| return await send_command(self._channel, command, params=params) |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.