Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid min and max color temp in bad ZHA light devices #81604

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions homeassistant/components/zha/core/channels/lighting.py
Expand Up @@ -98,12 +98,26 @@ def current_saturation(self) -> int | None:
@property
def min_mireds(self) -> int:
"""Return the coldest color_temp that this channel supports."""
return self.cluster.get("color_temp_physical_min", self.MIN_MIREDS)
min_mireds = self.cluster.get("color_temp_physical_min", self.MIN_MIREDS)
if min_mireds == 0:
self.warning(
"[Min mireds is 0, setting to %s] Please open an issue on the quirks repo to have this device corrected",
self.MIN_MIREDS,
)
min_mireds = self.MIN_MIREDS
return min_mireds

@property
def max_mireds(self) -> int:
"""Return the warmest color_temp that this channel supports."""
return self.cluster.get("color_temp_physical_max", self.MAX_MIREDS)
max_mireds = self.cluster.get("color_temp_physical_max", self.MAX_MIREDS)
if max_mireds == 0:
self.warning(
"[Max mireds is 0, setting to %s] Please open an issue on the quirks repo to have this device corrected",
self.MAX_MIREDS,
)
max_mireds = self.MAX_MIREDS
return max_mireds

@property
def hs_supported(self) -> bool:
Expand Down
6 changes: 5 additions & 1 deletion tests/components/zha/test_light.py
Expand Up @@ -242,7 +242,9 @@ async def eWeLink_light(hass, zigpy_device_mock, zha_device_joined):
color_cluster = zigpy_device.endpoints[1].light_color
color_cluster.PLUGGED_ATTR_READS = {
"color_capabilities": lighting.Color.ColorCapabilities.Color_temperature
| lighting.Color.ColorCapabilities.XY_attributes
| lighting.Color.ColorCapabilities.XY_attributes,
"color_temp_physical_min": 0,
"color_temp_physical_max": 0,
}
zha_device = await zha_device_joined(zigpy_device)
zha_device.available = True
Expand Down Expand Up @@ -1192,6 +1194,8 @@ async def test_transitions(
assert eWeLink_state.state == STATE_ON
assert eWeLink_state.attributes["color_temp"] == 235
assert eWeLink_state.attributes["color_mode"] == ColorMode.COLOR_TEMP
assert eWeLink_state.attributes["min_mireds"] == 153
assert eWeLink_state.attributes["max_mireds"] == 500


async def async_test_on_off_from_light(hass, cluster, entity_id):
Expand Down