Skip to content

Commit 839c57b

Browse files
committed
fix: ignore invalid brightness value for dim duration
1 parent 4c72d54 commit 839c57b

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

custom_components/hella_onyx/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"documentation": "https://github.com/muhlba91/onyx-homeassistant-integration",
66
"issue_tracker": "https://github.com/muhlba91/onyx-homeassistant-integration/issues",
77
"requirements": [
8-
"onyx-client==8.1.2"
8+
"onyx-client==8.1.3"
99
],
1010
"ssdp": [],
1111
"zeroconf": [],

custom_components/hella_onyx/sensors/light.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ def turn_off(self, **kwargs: Any) -> None:
130130
def _get_dim_duration(self, target) -> int:
131131
"""Get the dim duration."""
132132
brightness = self._device.actual_brightness
133+
if brightness is None or brightness.value is None or brightness.maximum is None:
134+
_LOGGER.warning(
135+
"received light %s without a valid brightness value: %s",
136+
self._uuid,
137+
brightness,
138+
)
139+
return MIN_USED_DIM_DURATION
133140
return abs(
134141
int(
135142
(target - brightness.value)

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ classifiers = [
2727

2828
[tool.poetry.dependencies]
2929
python = "^3.11"
30-
onyx-client = "^8.1.2"
30+
onyx-client = "^8.1.3"
3131

3232
[tool.poetry.dev-dependencies]
3333
pytest = "^7.3.1"

tests/sensors/test_light.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,25 @@ def test__get_dim_duration_same(self, api, entity, device):
150150
api.device.return_value = device
151151
assert entity._get_dim_duration(100) == 500
152152
assert api.device.called
153+
154+
def test__get_dim_duration_invalid_value(self, api, entity, device):
155+
device.actual_brightness = NumericValue(
156+
value=None, maximum=100, minimum=0, read_only=False
157+
)
158+
api.device.return_value = device
159+
assert entity._get_dim_duration(90) == 500
160+
assert api.device.called
161+
162+
def test__get_dim_duration_invalid_maximum(self, api, entity, device):
163+
device.actual_brightness = NumericValue(
164+
value=10, maximum=None, minimum=0, read_only=False
165+
)
166+
api.device.return_value = device
167+
assert entity._get_dim_duration(90) == 500
168+
assert api.device.called
169+
170+
def test__get_dim_duration_invalid_brightness(self, api, entity, device):
171+
device.actual_brightness = None
172+
api.device.return_value = device
173+
assert entity._get_dim_duration(90) == 500
174+
assert api.device.called

0 commit comments

Comments
 (0)