Skip to content

Commit

Permalink
fix: fix exception when targets are none
Browse files Browse the repository at this point in the history
  • Loading branch information
muhlba91 committed Dec 14, 2023
1 parent 609f9a0 commit ae8517a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
5 changes: 4 additions & 1 deletion onyx_client/device/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def update_with(self, update: Optional["Light"]):
update: the update patch"""
super().update_with(update)

self.target_brightness.update_with(update.target_brightness)
if self.target_brightness is not None:
self.target_brightness.update_with(update.target_brightness)
else:
self.target_brightness = update.target_brightness
self.actual_brightness.update_with(update.actual_brightness)
self.dim_duration.update_with(update.dim_duration)

Expand Down
10 changes: 8 additions & 2 deletions onyx_client/device/shutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ def update_with(self, update: Optional["Shutter"]):
update: the update patch"""
super().update_with(update)

self.target_position.update_with(update.target_position)
self.target_angle.update_with(update.target_angle)
if self.target_position is not None:
self.target_position.update_with(update.target_position)
else:
self.target_position = update.target_position
if self.target_angle is not None:
self.target_angle.update_with(update.target_angle)
else:
self.target_angle = update.target_angle
self.actual_position.update_with(update.actual_position)
self.actual_angle.update_with(update.actual_angle)

Expand Down
29 changes: 29 additions & 0 deletions tests/device/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,32 @@ def test_update_with_partials(self, device_mode):
assert light.target_brightness == NumericValue(1, 10, 10, False)
assert light.actual_brightness == NumericValue(20, 0, 10, False)
assert light.dim_duration == NumericValue(3, 0, 100, False)

value1 = NumericValue(1, 0, 10, False)
value2 = NumericValue(2, 0, 10, False)
value3 = NumericValue(3, 0, 10, False)
light = Light(
"id",
"name",
DeviceType.BASIC_LIGHT,
device_mode,
list(Action),
None,
value2,
value3,
)
update = Light(
"id",
"name1",
DeviceType.BASIC_LIGHT,
device_mode,
list(Action),
value1,
None,
None,
)
light.update_with(update)
assert light.name == "name1"
assert light.target_brightness == value1
assert light.actual_brightness == value2
assert light.dim_duration == value3
33 changes: 33 additions & 0 deletions tests/device/test_shutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,36 @@ def test_update_with_partials(self, device_mode):
assert shutter.target_angle == NumericValue(2, 10, 10, False)
assert shutter.actual_angle == NumericValue(3, 0, 100, False)
assert shutter.actual_position == NumericValue(4, 0, 10, False)

value1 = NumericValue(1, 0, 10, False)
value2 = NumericValue(2, 0, 10, False)
value3 = NumericValue(3, 0, 10, False)
value4 = NumericValue(4, 0, 10, False)
shutter = Shutter(
"id",
"name",
DeviceType.AWNING,
device_mode,
list(Action),
None,
None,
value3,
value4,
)
update = Shutter(
"id",
"name1",
DeviceType.AWNING,
device_mode,
list(Action),
value1,
value2,
None,
None,
)
shutter.update_with(update)
assert shutter.name == "name1"
assert shutter.target_position == value1
assert shutter.target_angle == value2
assert shutter.actual_angle == value3
assert shutter.actual_position == value4

0 comments on commit ae8517a

Please sign in to comment.