Skip to content

Commit 22096b4

Browse files
Fix medium code quality issues: RGB validation, type annotations (#557)
- Add RGB tuple length validation in _clamp_rgb_tuple (ValueError if not exactly 3 elements) - Fix name_from_value return type: str -> str | None - Fix device_ranges type annotation: dict[range] -> dict[str, tuple] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b897965 commit 22096b4

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

custom_components/dreo/pydreo/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def api_timestamp() -> str:
177177
return str(int(time.time() * 1000))
178178

179179
@staticmethod
180-
def name_from_value(name_value_list : list[tuple], value) -> str:
180+
def name_from_value(name_value_list : list[tuple], value) -> str | None:
181181
"""Return name from list of tuples."""
182182
if not name_value_list:
183183
_LOGGER.error("Helpers::name_from_value - name_value_list is None")

custom_components/dreo/pydreo/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class DreoDeviceDetails:
5454
preset_modes: list[str]
5555
"""List of possible preset mode names"""
5656

57-
device_ranges: dict[range]
57+
device_ranges: dict[str, tuple]
5858
"""Dictionary of different ranges"""
5959

6060
mode_names: list[str] | dict

custom_components/dreo/pydreo/pydreoceilingfan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class PyDreoCeilingFan(PyDreoFanBase):
3232
@staticmethod
3333
def _clamp_rgb_tuple(rgb: tuple) -> tuple[int, int, int]:
3434
"""Clamp RGB tuple values to 0-255 integers."""
35+
if len(rgb) != 3:
36+
raise ValueError(f"RGB tuple must have exactly 3 elements, got {len(rgb)}")
3537
return tuple(max(0, min(255, int(round(c)))) for c in rgb)
3638

3739
@staticmethod

0 commit comments

Comments
 (0)