From 5ac467ebf58ebdcb5e47cc8402f14c0639375d9d Mon Sep 17 00:00:00 2001 From: Daniel Muehlbachler-Pietrzykowski Date: Fri, 15 Dec 2023 13:47:48 +0100 Subject: [PATCH] fix: fix numeric value initialization defaults --- onyx_client/data/numeric_value.py | 4 ++-- tests/data/test_numeric_value.py | 4 ++-- tests/test_client.py | 6 +++-- tests/utils/test_mapper.py | 38 ++++++++++++++++++------------- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/onyx_client/data/numeric_value.py b/onyx_client/data/numeric_value.py index f0073e0..b0a3326 100644 --- a/onyx_client/data/numeric_value.py +++ b/onyx_client/data/numeric_value.py @@ -41,8 +41,8 @@ def create(properties: dict): return NumericValue( properties.get("value", None), - properties.get("minimum", 0), - properties.get("maximum", 100), + properties.get("minimum", None), + properties.get("maximum", None), properties.get("read_only", False), AnimationValue.create(properties.get("animation", None)), ) diff --git a/tests/data/test_numeric_value.py b/tests/data/test_numeric_value.py index 85f1022..0d0e44d 100644 --- a/tests/data/test_numeric_value.py +++ b/tests/data/test_numeric_value.py @@ -38,7 +38,7 @@ def test_create(self): ) def test_create_value_only(self): - expected = NumericValue(10, 0, 100, False) + expected = NumericValue(10, None, None, False) assert ( NumericValue.create( { @@ -49,7 +49,7 @@ def test_create_value_only(self): ) def test_create_no_value(self): - expected = NumericValue(None, 0, 100, False) + expected = NumericValue(None, None, None, False) assert NumericValue.create({}) == expected def test_create_none(self): diff --git a/tests/test_client.py b/tests/test_client.py index ac716f3..445141e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -310,6 +310,7 @@ async def test_device_shutter(self, mock_response, client): "target_angle": {"maximum": 360, "type": "numeric", "value": 0}, "actual_position": { "maximum": 100, + "minimum": 0, "value": 100, "type": "numeric", "animation": { @@ -327,6 +328,7 @@ async def test_device_shutter(self, mock_response, client): }, "actual_angle": { "maximum": 360, + "minimum": 0, "type": "numeric", "value": 0, "animation": { @@ -355,8 +357,8 @@ async def test_device_shutter(self, mock_response, client): DeviceType.ROLLERSHUTTER, ] assert device.actions == [Action.STOP] - assert device.target_position == NumericValue(100, 0, 100, False) - assert device.target_angle == NumericValue(0, 0, 360, False) + assert device.target_position == NumericValue(100, None, 100, False) + assert device.target_angle == NumericValue(0, None, 360, False) assert device.actual_position == NumericValue( 100, 0, diff --git a/tests/utils/test_mapper.py b/tests/utils/test_mapper.py index 4cec9e9..0f64db4 100644 --- a/tests/utils/test_mapper.py +++ b/tests/utils/test_mapper.py @@ -15,10 +15,16 @@ def test_numeric_value(): assert numeric_value("key", {"key": {"value": 1}}) == NumericValue( - value=1, minimum=0, maximum=100, read_only=False + value=1, minimum=None, maximum=None, read_only=False ) +def test_numeric_value_full(): + assert numeric_value( + "key", {"key": {"value": 1, "minimum": 0, "maximum": 10}} + ) == NumericValue(value=1, minimum=0, maximum=10, read_only=False) + + def test_numeric_value_empty_properties(): assert numeric_value("key", {}) is None @@ -106,8 +112,8 @@ def test_init_device_weather_full(): "values": ["weather"], }, "wind_peak": {"value": 1, "minimum": 10}, - "sun_brightness_peak": {"value": 2, "minimum": 1, "maximum": 10}, - "sun_brightness_sink": {"value": 3, "minimum": 1, "maximum": 10}, + "sun_brightness_peak": {"value": 2, "minimum": 1}, + "sun_brightness_sink": {"minimum": 1, "maximum": 10}, "air_pressure": {"value": 4, "minimum": 1, "maximum": 10}, "humidity": {"value": 5, "minimum": 1, "maximum": 10}, "temperature": {"value": 6, "minimum": 1, "maximum": 10}, @@ -119,9 +125,9 @@ def test_init_device_weather_full(): assert device.name == "name" assert device.device_mode.mode == DeviceType.WEATHER assert len(device.device_mode.values) == 1 - assert device.wind_peak == NumericValue(1, 10, 100, False) - assert device.sun_brightness_peak == NumericValue(2, 1, 10, False) - assert device.sun_brightness_sink == NumericValue(3, 1, 10, False) + assert device.wind_peak == NumericValue(1, 10, None, False) + assert device.sun_brightness_peak == NumericValue(2, 1, None, False) + assert device.sun_brightness_sink == NumericValue(None, 1, 10, False) assert device.air_pressure == NumericValue(4, 1, 10, False) assert device.humidity == NumericValue(5, 1, 10, False) assert device.temperature == NumericValue(6, 1, 10, False) @@ -174,8 +180,8 @@ def test_init_device_light_full(): "values": ["basic_light"], }, "target_brightness": {"value": 1, "minimum": 10}, - "actual_brightness": {"value": 2, "minimum": 1, "maximum": 10}, - "dim_duration": {"value": 3, "minimum": 1, "maximum": 10}, + "actual_brightness": {"value": 2, "maximum": 10}, + "dim_duration": {"minimum": 1, "maximum": 10}, }, list(Action), ) @@ -184,9 +190,9 @@ def test_init_device_light_full(): assert device.name == "name" assert device.device_mode.mode == DeviceType.BASIC_LIGHT assert len(device.device_mode.values) == 1 - assert device.target_brightness == NumericValue(1, 10, 100, False) - assert device.actual_brightness == NumericValue(2, 1, 10, False) - assert device.dim_duration == NumericValue(3, 1, 10, False) + assert device.target_brightness == NumericValue(1, 10, None, False) + assert device.actual_brightness == NumericValue(2, None, 10, False) + assert device.dim_duration == NumericValue(None, 1, 10, False) assert device.actions == list(Action) @@ -219,8 +225,8 @@ def test_init_device_shutter_full(): "values": ["awning", "rollershutter"], }, "target_position": {"value": 10, "minimum": 10}, - "target_angle": {"value": 1, "minimum": 1, "maximum": 10}, - "actual_position": {"value": 10, "maximum": 10}, + "target_angle": {"value": 1, "maximum": 10}, + "actual_position": {"minimum": 0, "maximum": 10}, "actual_angle": {"value": 1, "minimum": 1, "maximum": 10}, }, list(Action), @@ -230,9 +236,9 @@ def test_init_device_shutter_full(): assert device.name == "name" assert device.device_mode.mode == DeviceType.ROLLERSHUTTER assert len(device.device_mode.values) == 2 - assert device.target_position == NumericValue(10, 10, 100, False) - assert device.target_angle == NumericValue(1, 1, 10, False) - assert device.actual_position == NumericValue(10, 0, 10, False) + assert device.target_position == NumericValue(10, 10, None, False) + assert device.target_angle == NumericValue(1, None, 10, False) + assert device.actual_position == NumericValue(None, 0, 10, False) assert device.actual_angle == NumericValue(1, 1, 10, False) assert device.actions == list(Action)