Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions custom_components/xiaomi_miot/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ def on_init(self):
self._attr_max_color_temp_kelvin = prop.range_max()
self._attr_names[ATTR_COLOR_TEMP_KELVIN] = attr
else:
self._attr_min_mireds = prop.range_min()
self._attr_max_mireds = prop.range_max()
# Convert mireds range to kelvin (mireds min -> kelvin max)
mireds_min = prop.range_min()
mireds_max = prop.range_max()
self._attr_min_color_temp_kelvin = int(1000000 / mireds_max) if mireds_max else 2000
self._attr_max_color_temp_kelvin = int(1000000 / mireds_min) if mireds_min else 6500

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability of large numbers, you can use underscores as a visual separator. This would make the conversion factor 1000000 easier to read.

Suggested change
self._attr_min_color_temp_kelvin = int(1000000 / mireds_max) if mireds_max else 2000
self._attr_max_color_temp_kelvin = int(1000000 / mireds_min) if mireds_min else 6500
self._attr_min_color_temp_kelvin = int(1_000_000 / mireds_max) if mireds_max else 2000
self._attr_max_color_temp_kelvin = int(1_000_000 / mireds_min) if mireds_min else 6500

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! Applied 1_000_000 across all three occurrences in 53ee93d.

self._attr_names[ATTR_COLOR_TEMP] = attr
elif prop.in_list(['color', color_property]) or isinstance(conv, MiotRgbColorConv):
self._attr_names[ATTR_RGB_COLOR] = attr
Expand All @@ -120,7 +123,7 @@ def get_state(self) -> dict:
return {
self.attr: self._attr_is_on,
ATTR_BRIGHTNESS: self._attr_brightness,
ATTR_COLOR_TEMP: self._attr_color_temp,
ATTR_COLOR_TEMP_KELVIN: self._attr_color_temp_kelvin,
}

def set_state(self, data: dict):
Expand All @@ -137,8 +140,9 @@ def set_state(self, data: dict):
self._attr_color_temp_kelvin = val
self._attr_color_mode = ColorMode.COLOR_TEMP
elif (val := data.get(self._attr_names.get(ATTR_COLOR_TEMP))) is not None:
if val != self._attr_color_temp:
self._attr_color_temp = val
kelvin = int(1000000 / val) if val else None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability of large numbers, you can use underscores as a visual separator. This would make the conversion factor 1000000 easier to read.

            kelvin = int(1_000_000 / val) if val else None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the same commit — now uses 1_000_000 here as well.

if kelvin and kelvin != self._attr_color_temp_kelvin:
self._attr_color_temp_kelvin = kelvin
self._attr_color_mode = ColorMode.COLOR_TEMP
if (val := data.get(self._attr_names.get(ATTR_RGB_COLOR))) is not None:
if val != self._attr_rgb_color:
Expand Down