-
Notifications
You must be signed in to change notification settings - Fork 50
chore: Overhaul new device trait interfaces #489
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 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ca12a41
chore: Overhaul new device trait interfaces
allenporter b2118dd
chore: Only allow a single trait
allenporter 1f0d366
feat: update CLI with new properties
allenporter 137f17b
chore: remove unnecessarily local variables
allenporter f6a944a
chore: add comment about rpc channel hacks and separate property files
allenporter dc93a62
chore: Rename b01 properties to match v1
allenporter 48310da
chore: fix return types in CleanSummaryTrait
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
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,15 @@ | ||
"""Module for device traits.""" | ||
|
||
from abc import ABC | ||
|
||
__all__ = [ | ||
"Trait", | ||
"traits_mixin", | ||
"v1", | ||
"a01", | ||
"b01", | ||
] | ||
|
||
|
||
class Trait(ABC): | ||
"""Base class for all traits.""" |
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,61 @@ | ||
from typing import Any | ||
|
||
from roborock.containers import HomeDataProduct, RoborockCategory | ||
from roborock.devices.a01_channel import send_decoded_command | ||
from roborock.devices.mqtt_channel import MqttChannel | ||
from roborock.devices.traits import Trait | ||
from roborock.roborock_message import RoborockDyadDataProtocol, RoborockZeoProtocol | ||
|
||
__init__ = [ | ||
"DyadApi", | ||
"ZeoApi", | ||
] | ||
|
||
|
||
class DyadApi(Trait): | ||
"""API for interacting with Dyad devices.""" | ||
|
||
def __init__(self, channel: MqttChannel) -> None: | ||
"""Initialize the Dyad API.""" | ||
self._channel = channel | ||
|
||
async def query_values(self, protocols: list[RoborockDyadDataProtocol]) -> dict[RoborockDyadDataProtocol, Any]: | ||
"""Query the device for the values of the given Dyad protocols.""" | ||
params = {RoborockDyadDataProtocol.ID_QUERY: [int(p) for p in protocols]} | ||
return await send_decoded_command(self._channel, params) | ||
|
||
async def set_value(self, protocol: RoborockDyadDataProtocol, value: Any) -> dict[RoborockDyadDataProtocol, Any]: | ||
"""Set a value for a specific protocol on the device.""" | ||
params = {protocol: value} | ||
return await send_decoded_command(self._channel, params) | ||
|
||
|
||
class ZeoApi(Trait): | ||
"""API for interacting with Zeo devices.""" | ||
|
||
name = "zeo" | ||
|
||
def __init__(self, channel: MqttChannel) -> None: | ||
"""Initialize the Zeo API.""" | ||
self._channel = channel | ||
|
||
async def query_values(self, protocols: list[RoborockZeoProtocol]) -> dict[RoborockZeoProtocol, Any]: | ||
"""Query the device for the values of the given protocols.""" | ||
params = {RoborockZeoProtocol.ID_QUERY: [int(p) for p in protocols]} | ||
return await send_decoded_command(self._channel, params) | ||
|
||
async def set_value(self, protocol: RoborockZeoProtocol, value: Any) -> dict[RoborockZeoProtocol, Any]: | ||
"""Set a value for a specific protocol on the device.""" | ||
params = {protocol: value} | ||
return await send_decoded_command(self._channel, params) | ||
|
||
|
||
def create_a01_traits(product: HomeDataProduct, mqtt_channel: MqttChannel) -> list[Trait]: | ||
"""Create traits for A01 devices.""" | ||
match product.category: | ||
case RoborockCategory.WET_DRY_VAC: | ||
return [DyadApi(mqtt_channel)] | ||
case RoborockCategory.WASHING_MACHINE: | ||
return [ZeoApi(mqtt_channel)] | ||
case _: | ||
raise NotImplementedError(f"Unsupported category {product.category}") |
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,17 @@ | ||
"""Traits for B01 devices.""" | ||
|
||
from roborock.devices.b01_channel import send_decoded_command | ||
from roborock.devices.mqtt_channel import MqttChannel | ||
from roborock.devices.traits import Trait | ||
|
||
from .props import B01PropsApi | ||
|
||
__init__ = [ | ||
"create_b01_traits", | ||
"B01PropsApi", | ||
] | ||
|
||
|
||
def create_b01_traits(channel: MqttChannel) -> list[Trait]: | ||
"""Create traits for B01 devices.""" | ||
return [B01PropsApi(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
This file was deleted.
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.