mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Fix matter light color capabilities bit map (#88693)
* Adds matter light color capabilities bit map * Fixed matter light hue and saturation test
This commit is contained in:
parent
091305fc57
commit
0a3a8c4b3c
@ -1,6 +1,7 @@
|
|||||||
"""Matter light."""
|
"""Matter light."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from enum import IntFlag
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from chip.clusters import Objects as clusters
|
from chip.clusters import Objects as clusters
|
||||||
@ -260,11 +261,15 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
color_temp = kwargs.get(ATTR_COLOR_TEMP)
|
color_temp = kwargs.get(ATTR_COLOR_TEMP)
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
|
|
||||||
if hs_color is not None and self.supports_color:
|
if self.supported_color_modes is not None:
|
||||||
|
if hs_color is not None and ColorMode.HS in self.supported_color_modes:
|
||||||
await self._set_hs_color(hs_color)
|
await self._set_hs_color(hs_color)
|
||||||
elif xy_color is not None:
|
elif xy_color is not None and ColorMode.XY in self.supported_color_modes:
|
||||||
await self._set_xy_color(xy_color)
|
await self._set_xy_color(xy_color)
|
||||||
elif color_temp is not None and self.supports_color_temperature:
|
elif (
|
||||||
|
color_temp is not None
|
||||||
|
and ColorMode.COLOR_TEMP in self.supported_color_modes
|
||||||
|
):
|
||||||
await self._set_color_temp(color_temp)
|
await self._set_color_temp(color_temp)
|
||||||
|
|
||||||
if brightness is not None and self.supports_brightness:
|
if brightness is not None and self.supports_brightness:
|
||||||
@ -284,7 +289,6 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
@callback
|
@callback
|
||||||
def _update_from_device(self) -> None:
|
def _update_from_device(self) -> None:
|
||||||
"""Update from device."""
|
"""Update from device."""
|
||||||
|
|
||||||
if self._attr_supported_color_modes is None:
|
if self._attr_supported_color_modes is None:
|
||||||
# work out what (color)features are supported
|
# work out what (color)features are supported
|
||||||
supported_color_modes: set[ColorMode] = set()
|
supported_color_modes: set[ColorMode] = set()
|
||||||
@ -297,30 +301,19 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
if self._entity_info.endpoint.has_attribute(
|
if self._entity_info.endpoint.has_attribute(
|
||||||
None, clusters.ColorControl.Attributes.ColorMode
|
None, clusters.ColorControl.Attributes.ColorMode
|
||||||
):
|
):
|
||||||
# device has some color support, check which color modes
|
capabilities = self.get_matter_attribute_value(
|
||||||
# are supported with the featuremap on the ColorControl cluster
|
clusters.ColorControl.Attributes.ColorCapabilities
|
||||||
color_feature_map = self.get_matter_attribute_value(
|
|
||||||
clusters.ColorControl.Attributes.FeatureMap,
|
|
||||||
)
|
)
|
||||||
if (
|
|
||||||
color_feature_map
|
assert capabilities is not None
|
||||||
& clusters.ColorControl.Attributes.CurrentHue.attribute_id
|
|
||||||
):
|
if capabilities & ColorCapabilities.kHueSaturationSupported:
|
||||||
supported_color_modes.add(ColorMode.HS)
|
supported_color_modes.add(ColorMode.HS)
|
||||||
if (
|
|
||||||
color_feature_map
|
if capabilities & ColorCapabilities.kXYAttributesSupported:
|
||||||
& clusters.ColorControl.Attributes.CurrentX.attribute_id
|
|
||||||
):
|
|
||||||
supported_color_modes.add(ColorMode.XY)
|
supported_color_modes.add(ColorMode.XY)
|
||||||
|
|
||||||
# color temperature support detection using the featuremap is not reliable
|
if capabilities & ColorCapabilities.kColorTemperatureSupported:
|
||||||
# (temporary?) fallback to checking the value
|
|
||||||
if (
|
|
||||||
self.get_matter_attribute_value(
|
|
||||||
clusters.ColorControl.Attributes.ColorTemperatureMireds
|
|
||||||
)
|
|
||||||
is not None
|
|
||||||
):
|
|
||||||
supported_color_modes.add(ColorMode.COLOR_TEMP)
|
supported_color_modes.add(ColorMode.COLOR_TEMP)
|
||||||
|
|
||||||
self._attr_supported_color_modes = supported_color_modes
|
self._attr_supported_color_modes = supported_color_modes
|
||||||
@ -351,11 +344,23 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
self._attr_brightness = self._get_brightness()
|
self._attr_brightness = self._get_brightness()
|
||||||
|
|
||||||
|
|
||||||
|
# This enum should be removed once the ColorControlCapabilities enum is added to the CHIP (Matter) library
|
||||||
|
# clusters.ColorControl.Bitmap.ColorCapabilities
|
||||||
|
class ColorCapabilities(IntFlag):
|
||||||
|
"""Color control capabilities bitmap."""
|
||||||
|
|
||||||
|
kHueSaturationSupported = 0x1
|
||||||
|
kEnhancedHueSupported = 0x2
|
||||||
|
kColorLoopSupported = 0x4
|
||||||
|
kXYAttributesSupported = 0x8
|
||||||
|
kColorTemperatureSupported = 0x10
|
||||||
|
|
||||||
|
|
||||||
# Discovery schema(s) to map Matter Attributes to HA entities
|
# Discovery schema(s) to map Matter Attributes to HA entities
|
||||||
DISCOVERY_SCHEMAS = [
|
DISCOVERY_SCHEMAS = [
|
||||||
MatterDiscoverySchema(
|
MatterDiscoverySchema(
|
||||||
platform=Platform.LIGHT,
|
platform=Platform.LIGHT,
|
||||||
entity_description=LightEntityDescription(key="ExtendedMatterLight"),
|
entity_description=LightEntityDescription(key="MatterLight"),
|
||||||
entity_class=MatterLight,
|
entity_class=MatterLight,
|
||||||
required_attributes=(clusters.OnOff.Attributes.OnOff,),
|
required_attributes=(clusters.OnOff.Attributes.OnOff,),
|
||||||
optional_attributes=(
|
optional_attributes=(
|
||||||
|
@ -288,7 +288,7 @@ async def test_extended_color_light(
|
|||||||
"turn_on",
|
"turn_on",
|
||||||
{
|
{
|
||||||
"entity_id": entity_id,
|
"entity_id": entity_id,
|
||||||
"hs_color": (0, 0),
|
"hs_color": (236.69291338582678, 100.0),
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
@ -299,9 +299,9 @@ async def test_extended_color_light(
|
|||||||
call(
|
call(
|
||||||
node_id=1,
|
node_id=1,
|
||||||
endpoint_id=1,
|
endpoint_id=1,
|
||||||
command=clusters.ColorControl.Commands.MoveToColor(
|
command=clusters.ColorControl.Commands.MoveToHueAndSaturation(
|
||||||
colorX=21168,
|
hue=167,
|
||||||
colorY=21561,
|
saturation=254,
|
||||||
transitionTime=0,
|
transitionTime=0,
|
||||||
optionsMask=0,
|
optionsMask=0,
|
||||||
optionsOverride=0,
|
optionsOverride=0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user