Implement choice feature type (#880)

Implement the choice feature type allowing to provide a list of choices that can be set.

Co-authored-by: sdb9696
This commit is contained in:
Teemu R
2024-04-30 08:56:09 +02:00
committed by GitHub
parent d3544b4989
commit 300d823895
7 changed files with 98 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
import pytest
from pytest_mock import MockFixture
from kasa import Feature
@@ -110,6 +111,23 @@ async def test_feature_action(mocker):
mock_call_action.assert_called()
async def test_feature_choice_list(dummy_feature, caplog, mocker: MockFixture):
"""Test the choice feature type."""
dummy_feature.type = Feature.Type.Choice
dummy_feature.choices = ["first", "second"]
mock_setter = mocker.patch.object(dummy_feature.device, "dummysetter", create=True)
await dummy_feature.set_value("first")
mock_setter.assert_called_with("first")
mock_setter.reset_mock()
with pytest.raises(ValueError):
await dummy_feature.set_value("invalid")
assert "Unexpected value" in caplog.text
mock_setter.assert_not_called()
@pytest.mark.parametrize("precision_hint", [1, 2, 3])
async def test_precision_hint(dummy_feature, precision_hint):
"""Test that precision hint works as expected."""