mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Add precision_hint to feature (#871)
This can be used to hint how the sensor value should be rounded when displaying it to users. The values are adapted from the values used by homeassistant.
This commit is contained in:
@@ -108,3 +108,15 @@ async def test_feature_action(mocker):
|
||||
assert feat.value == "<Action>"
|
||||
await feat.set_value(1234)
|
||||
mock_call_action.assert_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."""
|
||||
dummy_value = 3.141593
|
||||
dummy_feature.type = Feature.Type.Sensor
|
||||
dummy_feature.precision_hint = precision_hint
|
||||
|
||||
dummy_feature.attribute_getter = lambda x: dummy_value
|
||||
assert dummy_feature.value == dummy_value
|
||||
assert f"{round(dummy_value, precision_hint)} dummyunit" in repr(dummy_feature)
|
||||
|
Reference in New Issue
Block a user