Skip to content

Commit

Permalink
fix: ignore invalid brightness value for dim duration
Browse files Browse the repository at this point in the history
  • Loading branch information
muhlba91 committed Dec 12, 2023
1 parent 4c72d54 commit 839c57b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/hella_onyx/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"documentation": "https://github.com/muhlba91/onyx-homeassistant-integration",
"issue_tracker": "https://github.com/muhlba91/onyx-homeassistant-integration/issues",
"requirements": [
"onyx-client==8.1.2"
"onyx-client==8.1.3"
],
"ssdp": [],
"zeroconf": [],
Expand Down
7 changes: 7 additions & 0 deletions custom_components/hella_onyx/sensors/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def turn_off(self, **kwargs: Any) -> None:
def _get_dim_duration(self, target) -> int:
"""Get the dim duration."""
brightness = self._device.actual_brightness
if brightness is None or brightness.value is None or brightness.maximum is None:
_LOGGER.warning(
"received light %s without a valid brightness value: %s",
self._uuid,
brightness,
)
return MIN_USED_DIM_DURATION
return abs(
int(
(target - brightness.value)
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.11"
onyx-client = "^8.1.2"
onyx-client = "^8.1.3"

[tool.poetry.dev-dependencies]
pytest = "^7.3.1"
Expand Down
22 changes: 22 additions & 0 deletions tests/sensors/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,25 @@ def test__get_dim_duration_same(self, api, entity, device):
api.device.return_value = device
assert entity._get_dim_duration(100) == 500
assert api.device.called

def test__get_dim_duration_invalid_value(self, api, entity, device):
device.actual_brightness = NumericValue(
value=None, maximum=100, minimum=0, read_only=False
)
api.device.return_value = device
assert entity._get_dim_duration(90) == 500
assert api.device.called

def test__get_dim_duration_invalid_maximum(self, api, entity, device):
device.actual_brightness = NumericValue(
value=10, maximum=None, minimum=0, read_only=False
)
api.device.return_value = device
assert entity._get_dim_duration(90) == 500
assert api.device.called

def test__get_dim_duration_invalid_brightness(self, api, entity, device):
device.actual_brightness = None
api.device.return_value = device
assert entity._get_dim_duration(90) == 500
assert api.device.called

0 comments on commit 839c57b

Please sign in to comment.