fix(light): fix color-temp out-of-range errors and migrate to ATTR_COLOR_TEMP_KELVIN#587
Open
ZakiZtraki wants to merge 1 commit into
Open
Conversation
…KELVIN Meross API rejects temperature payloads outside 1-100 (error code 5000 'Out of range'). The previous mired-based conversion produced negative values when the input fell outside the assumed min/max range. Changes: - Replace deprecated ATTR_COLOR_TEMP (mired) with ATTR_COLOR_TEMP_KELVIN across both LightEntityWrapper and DiffuserLightEntityWrapper, silencing the HA 2026.1 deprecation warning. - Convert Kelvin directly to the Meross 1-100 scale using the device's known range (2700-6500 K), removing the intermediate mired inversion. - Clamp the result with max(1, min(100, value)) as a safety net for edge-case inputs or floating-point drift. - Add _attr_min_color_temp_kelvin / _attr_max_color_temp_kelvin (2700-6500 K) to both entity classes so the HA UI slider stays within the supported range. - Replace color_temp property (mired) with color_temp_kelvin (Kelvin) on LightEntityWrapper to match the new API. Tested on: MSL120D hw2.0.0 / fw2.1.5 (white + colour-temperature modes now work; RGB mode unaffected). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Meross bulbs that support white/colour-temperature mode (e.g. MSL120D) return error code 5000 when Home Assistant sends a
temperaturepayload outside the accepted range of 1–100:The root causes were:
100 - norm_value * 100) produced negative values or values > 100 when the input fell outside the assumed min/max mired range.ATTR_COLOR_TEMP(mired-based), which HA has deprecated and will remove in HA Core 2026.1, producing warnings in the log._attr_min_color_temp_kelvin/_attr_max_color_temp_kelvin, so the HA UI slider used HA's broad defaults instead of the Meross-supported range.Changes
ATTR_COLOR_TEMP_KELVINin bothLightEntityWrapperandDiffuserLightEntityWrapper, eliminating the HA 2026.1 deprecation warning.max(1, min(100, value))as a safety net for edge-case inputs or floating-point drift._attr_min_color_temp_kelvin = 2700,_attr_max_color_temp_kelvin = 6500) on both entity classes so the HA slider stays within supported bounds.color_tempwithcolor_temp_kelvinonLightEntityWrapperto match the new API.Compatibility
No existing configuration is broken:
Tested devices