| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Implementation of vacuum mop.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from enum import IntEnum | ||
| from typing import Annotated | ||
|
|
||
| from ...feature import Feature | ||
| from ...module import FeatureAttribute | ||
| from ..smartmodule import SmartModule | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Waterlevel(IntEnum): | ||
| """Water level for mopping.""" | ||
|
|
||
| Disable = 0 | ||
| Low = 1 | ||
| Medium = 2 | ||
| High = 3 | ||
|
|
||
|
|
||
| class Mop(SmartModule): | ||
| """Implementation of vacuum mop.""" | ||
|
|
||
| REQUIRED_COMPONENT = "mop" | ||
|
|
||
| def _initialize_features(self) -> None: | ||
| """Initialize features.""" | ||
| self._add_feature( | ||
| Feature( | ||
| self._device, | ||
| id="mop_attached", | ||
| name="Mop attached", | ||
| container=self, | ||
| icon="mdi:square-rounded", | ||
| attribute_getter="mop_attached", | ||
| category=Feature.Category.Info, | ||
| type=Feature.BinarySensor, | ||
| ) | ||
| ) | ||
|
|
||
| self._add_feature( | ||
| Feature( | ||
| self._device, | ||
| id="mop_waterlevel", | ||
| name="Mop water level", | ||
| container=self, | ||
| attribute_getter="waterlevel", | ||
| attribute_setter="set_waterlevel", | ||
| icon="mdi:water", | ||
| choices_getter=lambda: list(Waterlevel.__members__), | ||
| category=Feature.Category.Config, | ||
| type=Feature.Type.Choice, | ||
| ) | ||
| ) | ||
|
|
||
| def query(self) -> dict: | ||
| """Query to execute during the update cycle.""" | ||
| return { | ||
| "getMopState": {}, | ||
| "getCleanAttr": {"type": "global"}, | ||
| } | ||
|
|
||
| @property | ||
| def mop_attached(self) -> bool: | ||
| """Return True if mop is attached.""" | ||
| return self.data["getMopState"]["mop_state"] | ||
|
|
||
| @property | ||
| def _settings(self) -> dict: | ||
| """Return settings settings.""" | ||
| return self.data["getCleanAttr"] | ||
|
|
||
| @property | ||
| def waterlevel(self) -> Annotated[str, FeatureAttribute()]: | ||
| """Return water level.""" | ||
| return Waterlevel(int(self._settings["cistern"])).name | ||
|
|
||
| async def set_waterlevel(self, mode: str) -> Annotated[dict, FeatureAttribute()]: | ||
| """Set waterlevel mode.""" | ||
| name_to_value = {x.name: x.value for x in Waterlevel} | ||
| if mode not in name_to_value: | ||
| raise ValueError("Invalid waterlevel %s, available %s", mode, name_to_value) | ||
|
|
||
| settings = self._settings.copy() | ||
| settings["cistern"] = name_to_value[mode] | ||
| return await self.call("setCleanAttr", settings) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| from pytest_mock import MockerFixture | ||
|
|
||
| from kasa import Module | ||
| from kasa.smart import SmartDevice | ||
| from kasa.smart.modules.mop import Waterlevel | ||
|
|
||
| from ...device_fixtures import get_parent_and_child_modules, parametrize | ||
|
|
||
| mop = parametrize("has mop", component_filter="mop", protocol_filter={"SMART"}) | ||
|
|
||
|
|
||
| @mop | ||
| @pytest.mark.parametrize( | ||
| ("feature", "prop_name", "type"), | ||
| [ | ||
| ("mop_attached", "mop_attached", bool), | ||
| ("mop_waterlevel", "waterlevel", str), | ||
| ], | ||
| ) | ||
| async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type): | ||
| """Test that features are registered and work as expected.""" | ||
| mod = next(get_parent_and_child_modules(dev, Module.Mop)) | ||
| assert mod is not None | ||
|
|
||
| prop = getattr(mod, prop_name) | ||
| assert isinstance(prop, type) | ||
|
|
||
| feat = mod._device.features[feature] | ||
| assert feat.value == prop | ||
| assert isinstance(feat.value, type) | ||
|
|
||
|
|
||
| @mop | ||
| async def test_mop_waterlevel(dev: SmartDevice, mocker: MockerFixture): | ||
| """Test dust mode.""" | ||
| mop_module = next(get_parent_and_child_modules(dev, Module.Mop)) | ||
| call = mocker.spy(mop_module, "call") | ||
|
|
||
| waterlevel = mop_module._device.features["mop_waterlevel"] | ||
| assert mop_module.waterlevel == waterlevel.value | ||
|
|
||
| new_level = Waterlevel.High | ||
| await mop_module.set_waterlevel(new_level.name) | ||
|
|
||
| params = mop_module._settings.copy() | ||
| params["cistern"] = new_level.value | ||
|
|
||
| call.assert_called_with("setCleanAttr", params) | ||
|
|
||
| await dev.update() | ||
|
|
||
| assert mop_module.waterlevel == new_level.name | ||
|
|
||
| with pytest.raises(ValueError, match="Invalid waterlevel"): | ||
| await mop_module.set_waterlevel("invalid") |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis is the same query as used by clean module, but it probably shouldn't matter. If we ever add support for spot cleaning, we may need to consider how to handle that (as its query only differs by type).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWill there always be a vaccum module? Could this data come from that module to avoid querying it twice?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityOh, good point. I think there is no mop-only devices, but if there is, this will still keep working.
And as we construct the query using update(), there are no duplicates here for the time being, so this is fine.
We will become problems if we want to add zone/spot cleaning though, as they will use type: pose for their settings.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThat would indeed be a challenge as we'd overwrite the other module query as things currently stand.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes, we can tackle that whenever it comes an issue. But it is not necessary for this PR, so I think we can merge it as it is? Assuming the selected categories, identifier names and user visible strings are fine, that is.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.