Skip to content

Persistently cache brightness, color temp, and RGB - #59

Draft
zacharee wants to merge 1 commit into
HamzaETTH:masterfrom
zacharee:fix-color-brightness
Draft

Persistently cache brightness, color temp, and RGB#59
zacharee wants to merge 1 commit into
HamzaETTH:masterfrom
zacharee:fix-color-brightness

Conversation

@zacharee

Copy link
Copy Markdown
Contributor

This change adds a cache object to persist the RGB, color temperature, and brightness values the integration sends to lights across Home Assistant restarts so it doesn't have to recalculate inaccurate values every startup.

For brightness, I added a sanity check for the cache where if the difference between the cached value and the returned value is greater than 3, the integration will assume the cache is stale. I think 3 is a safe threshold value since the ratio of 100:255 is just about 2.5.

For color temperature, I think we could probably also have a sanity check threshold but I don't understand the logic used to calculate the value from the API, so right now it just always assumes the cached value is correct if it exists.

For RGB, I made use of those functions Gemini made discussed in #54 to both do a sanity check comparison and improve the best-guess reversal calculation if there's no cache or the cached value is determined to be stale. From my testing, the function the AI generated to convert RGB to whatever Sengled's values are occasionally flips the weakest channel's value from 0 to 1 and vice-versa compared to the light's behavior, so the comparison ignores it altogether. For the middle channel, scaling by brightness doesn't always get it back to the right value, so there's some tolerance built in.

I haven't had a chance to test this, so it probably needs some changes before it's merged.

@zacharee
zacharee force-pushed the fix-color-brightness branch from fd8fc2e to d066dfb Compare January 31, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant