Add color support to matter lights (#87366)

* Added the correct attributes to ColorTemperatureLight and ExtendedColorLight and added CurrentY to codespell ignore word list

* Added enums for matter color modes

* Added support for reading color and color temperature settings from matter api

* Added away of getting the ColorControl featureMap while the get_cluster(ColorControl) function is fixed

* Initial working implementation of color and color temperature

* Full supports for lights with both hs and xy

* Added checks to make sure color features are supported before making matter call

* Changed how color mode is figured out

* Moved the logic that gets the brightness to its own function

* Adds matter light tests for hass triggered events

* Adds full test coverage for matter all types of matter lights

* Adds full test coverage for matter all types of matter lights

* Moved light convertion logic to util.py

* Reorderd codespell ignore list and removed unused code

* Adds brightness state test
This commit is contained in:
Arturo 2023-02-07 13:44:02 -06:00 committed by GitHub
parent 096f6eb554
commit e84a11963e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 2606 additions and 57 deletions

View file

@ -1,6 +1,8 @@
"""Provide integration utilities."""
from __future__ import annotations
XY_COLOR_FACTOR = 65536
def renormalize(
number: float, from_range: tuple[float, float], to_range: tuple[float, float]
@ -9,3 +11,33 @@ def renormalize(
delta1 = from_range[1] - from_range[0]
delta2 = to_range[1] - to_range[0]
return (delta2 * (number - from_range[0]) / delta1) + to_range[0]
def convert_to_matter_hs(hass_hs: tuple[float, float]) -> tuple[float, float]:
"""Convert Home Assistant HS to Matter HS."""
return (
hass_hs[0] / 360 * 254,
renormalize(hass_hs[1], (0, 100), (0, 254)),
)
def convert_to_hass_hs(matter_hs: tuple[float, float]) -> tuple[float, float]:
"""Convert Matter HS to Home Assistant HS."""
return (
matter_hs[0] * 360 / 254,
renormalize(matter_hs[1], (0, 254), (0, 100)),
)
def convert_to_matter_xy(hass_xy: tuple[float, float]) -> tuple[float, float]:
"""Convert Home Assistant XY to Matter XY."""
return (hass_xy[0] * XY_COLOR_FACTOR, hass_xy[1] * XY_COLOR_FACTOR)
def convert_to_hass_xy(matter_xy: tuple[float, float]) -> tuple[float, float]:
"""Convert Matter XY to Home Assistant XY."""
return (matter_xy[0] / XY_COLOR_FACTOR, matter_xy[1] / XY_COLOR_FACTOR)