Skip to content

Commit

Permalink
ZHA light entity cleanup (#75573)
Browse files Browse the repository at this point in the history
* use base class attributes

* initial hue and saturation support

* spec is 65536 not 65535

* fixes

* enhanced current hue

* fix comparison

* clean up

* fix channel test

* oops

* report enhanced current hue
  • Loading branch information
dmulcahey committed Jul 21, 2022
1 parent 6cb1794 commit 04c6b9c
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 164 deletions.
71 changes: 71 additions & 0 deletions homeassistant/components/zha/core/channels/lighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class ColorChannel(ZigbeeChannel):
REPORT_CONFIG = (
AttrReportConfig(attr="current_x", config=REPORT_CONFIG_DEFAULT),
AttrReportConfig(attr="current_y", config=REPORT_CONFIG_DEFAULT),
AttrReportConfig(attr="current_hue", config=REPORT_CONFIG_DEFAULT),
AttrReportConfig(attr="enhanced_current_hue", config=REPORT_CONFIG_DEFAULT),
AttrReportConfig(attr="current_saturation", config=REPORT_CONFIG_DEFAULT),
AttrReportConfig(attr="color_temperature", config=REPORT_CONFIG_DEFAULT),
)
MAX_MIREDS: int = 500
Expand All @@ -52,6 +55,14 @@ def color_capabilities(self) -> int:
return self.CAPABILITIES_COLOR_XY | self.CAPABILITIES_COLOR_TEMP
return self.CAPABILITIES_COLOR_XY

@property
def zcl_color_capabilities(self) -> lighting.Color.ColorCapabilities:
"""Return ZCL color capabilities of the light."""
color_capabilities = self.cluster.get("color_capabilities")
if color_capabilities is None:
return lighting.Color.ColorCapabilities(self.CAPABILITIES_COLOR_XY)
return lighting.Color.ColorCapabilities(color_capabilities)

@property
def color_mode(self) -> int | None:
"""Return cached value of the color_mode attribute."""
Expand All @@ -77,6 +88,21 @@ def current_y(self) -> int | None:
"""Return cached value of the current_y attribute."""
return self.cluster.get("current_y")

@property
def current_hue(self) -> int | None:
"""Return cached value of the current_hue attribute."""
return self.cluster.get("current_hue")

@property
def enhanced_current_hue(self) -> int | None:
"""Return cached value of the enhanced_current_hue attribute."""
return self.cluster.get("enhanced_current_hue")

@property
def current_saturation(self) -> int | None:
"""Return cached value of the current_saturation attribute."""
return self.cluster.get("current_saturation")

@property
def min_mireds(self) -> int:
"""Return the coldest color_temp that this channel supports."""
Expand All @@ -86,3 +112,48 @@ def min_mireds(self) -> int:
def max_mireds(self) -> int:
"""Return the warmest color_temp that this channel supports."""
return self.cluster.get("color_temp_physical_max", self.MAX_MIREDS)

@property
def hs_supported(self) -> bool:
"""Return True if the channel supports hue and saturation."""
return (
self.zcl_color_capabilities is not None
and lighting.Color.ColorCapabilities.Hue_and_saturation
in self.zcl_color_capabilities
)

@property
def enhanced_hue_supported(self) -> bool:
"""Return True if the channel supports enhanced hue and saturation."""
return (
self.zcl_color_capabilities is not None
and lighting.Color.ColorCapabilities.Enhanced_hue
in self.zcl_color_capabilities
)

@property
def xy_supported(self) -> bool:
"""Return True if the channel supports xy."""
return (
self.zcl_color_capabilities is not None
and lighting.Color.ColorCapabilities.XY_attributes
in self.zcl_color_capabilities
)

@property
def color_temp_supported(self) -> bool:
"""Return True if the channel supports color temperature."""
return (
self.zcl_color_capabilities is not None
and lighting.Color.ColorCapabilities.Color_temperature
in self.zcl_color_capabilities
)

@property
def color_loop_supported(self) -> bool:
"""Return True if the channel supports color loop."""
return (
self.zcl_color_capabilities is not None
and lighting.Color.ColorCapabilities.Color_loop
in self.zcl_color_capabilities
)

0 comments on commit 04c6b9c

Please sign in to comment.