mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-07 00:28:22 +00:00
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:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user