Add vacuum speaker controls (#1332)
Some checks are pending
CI / Perform linting checks (3.13) (push) Waiting to run
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.11) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.12) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.13) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.11) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.12) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.13) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.11) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.12) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.13) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.11) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.12) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.13) (push) Blocked by required conditions
CodeQL checks / Analyze (python) (push) Waiting to run

Implements `speaker` and adds the following features:
* `volume`  to control the speaker volume
* `locate` to play "I'm here sound"
This commit is contained in:
Teemu R.
2025-01-14 17:48:34 +01:00
committed by GitHub
parent 3c98efb015
commit 2542516009
7 changed files with 148 additions and 0 deletions

View File

@@ -637,6 +637,9 @@ class FakeSmartTransport(BaseTransport):
return self._set_on_off_gradually_info(info, params)
elif method == "set_child_protection":
return self._update_sysinfo_key(info, "child_protection", params["enable"])
# Vacuum special actions
elif method in ["playSelectAudio"]:
return {"error_code": 0}
elif method[:3] == "set":
target_method = f"get{method[3:]}"
# Some vacuum commands do not have a getter

View File

@@ -187,6 +187,9 @@
"name": "2",
"version": 1
},
"getVolume": {
"volume": 84
},
"getDoNotDisturb": {
"do_not_disturb": true,
"e_min": 480,

View File

@@ -0,0 +1,71 @@
from __future__ import annotations
import pytest
from pytest_mock import MockerFixture
from kasa import Module
from kasa.smart import SmartDevice
from ...device_fixtures import get_parent_and_child_modules, parametrize
speaker = parametrize(
"has speaker", component_filter="speaker", protocol_filter={"SMART"}
)
@speaker
@pytest.mark.parametrize(
("feature", "prop_name", "type"),
[
("volume", "volume", int),
],
)
async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type):
"""Test that features are registered and work as expected."""
speaker = next(get_parent_and_child_modules(dev, Module.Speaker))
assert speaker is not None
prop = getattr(speaker, prop_name)
assert isinstance(prop, type)
feat = speaker._device.features[feature]
assert feat.value == prop
assert isinstance(feat.value, type)
@speaker
async def test_set_volume(dev: SmartDevice, mocker: MockerFixture):
"""Test speaker settings."""
speaker = next(get_parent_and_child_modules(dev, Module.Speaker))
assert speaker is not None
call = mocker.spy(speaker, "call")
volume = speaker._device.features["volume"]
assert speaker.volume == volume.value
new_volume = 15
await speaker.set_volume(new_volume)
call.assert_called_with("setVolume", {"volume": new_volume})
await dev.update()
assert speaker.volume == new_volume
with pytest.raises(ValueError, match="Volume must be between 0 and 100"):
await speaker.set_volume(-10)
with pytest.raises(ValueError, match="Volume must be between 0 and 100"):
await speaker.set_volume(110)
@speaker
async def test_locate(dev: SmartDevice, mocker: MockerFixture):
"""Test the locate method."""
speaker = next(get_parent_and_child_modules(dev, Module.Speaker))
call = mocker.spy(speaker, "call")
await speaker.locate()
call.assert_called_with("playSelectAudio", {"audio_type": "seek_me"})