Skip to content

Commit

Permalink
fix: fix numeric value initialization defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
muhlba91 committed Dec 15, 2023
1 parent e1b4443 commit 5ac467e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions onyx_client/data/numeric_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
Expand Down
4 changes: 2 additions & 2 deletions tests/data/test_numeric_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -327,6 +328,7 @@ async def test_device_shutter(self, mock_response, client):
},
"actual_angle": {
"maximum": 360,
"minimum": 0,
"type": "numeric",
"value": 0,
"animation": {
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 22 additions & 16 deletions tests/utils/test_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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},
Expand All @@ -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)
Expand Down Expand Up @@ -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),
)
Expand All @@ -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)


Expand Down Expand Up @@ -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),
Expand All @@ -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)

Expand Down

0 comments on commit 5ac467e

Please sign in to comment.