Skip to content

Refine nearby color function#62

Merged
chazzu merged 1 commit intochazzu:masterfrom
Snuffy2:Refine-nearby-color-function
Oct 6, 2025
Merged

Refine nearby color function#62
chazzu merged 1 commit intochazzu:masterfrom
Snuffy2:Refine-nearby-color-function

Conversation

@Snuffy2
Copy link
Contributor

@Snuffy2 Snuffy2 commented Oct 5, 2025

This pull request introduces several improvements and refactors to the animated scenes custom component for Home Assistant, focusing on enhanced color handling and documentation. The most significant updates are the expanded support for "nearby color" perturbations and improved RGB conversion logic for various color types. These changes make the component more robust and user-friendly, especially when working with different light color modes.

Color handling enhancements

  • Expanded the supported color types for "nearby color" perturbations to include RGB, RGBW, RGBWW, color temperature (kelvin), HS, and XY, with robust conversion helpers for each type. Added _convert_to_rgb and _convert_back_to_original_color_type methods to reliably translate between color representations.
  • Refactored the find_nearby_color method to use HLS space perturbation for all supported color types, improving color variation and accuracy. Added clamping and cyclic handling for HLS values, and ensured output matches the original color type.
  • Added a helper function _rgb_to_kelvin to approximate the kelvin value from an RGB triple, enabling round-trip conversion for color temperature types.

Configuration and logging

  • Updated the color configuration schema to restrict nearby_colors to the range 0–10, reflecting the new documented behavior.
  • Added debug logging to show which nearby color was picked for a light during animation runs, aiding troubleshooting and transparency.

Documentation improvements

  • Added multiple shields/badges to the top of the README.MD for downloads, releases, license, activity, and HACS support, and defined badge links at the end of the file for easier maintenance. [1] [2]
  • Clarified the documentation for the nearby_colors configuration option, specifying that the valid range is now 1–10 (instead of 1–100) and removing the RGB-specific caveat.

Constants and limits

  • Defined MIN_KELVIN and MAX_KELVIN constants in const.py and used them throughout the codebase for color temperature bounds, replacing hardcoded values. [1] [2] [3]

These changes collectively improve the flexibility, reliability, and maintainability of the animated scenes integration, especially when dealing with a variety of light color modes and user configurations.

@chazzu chazzu merged commit 74c5c5d into chazzu:master Oct 6, 2025
3 checks passed
@Snuffy2 Snuffy2 deleted the Refine-nearby-color-function branch October 6, 2025 01: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.

2 participants