Add check to validate gamut (#20518)
* color.util - Add check to validate gamut * fix indents * fix typo * Add check to validate gamut * Add tests for gamut checker * fix test * fix pylint issues * fix hue light gamut tests * add check to validate gamut * move None check * Move None check * Include prompt to update bridge/bulb on error * fix wrong commit * fix error message * Update light.py
This commit is contained in:
1 parent
63fd5f2d31
commit
d7bbdb033d
4 files changed
+58
-4
No files matched your search
@@ -41,6 +41,7 @@ SUPPORT_HUE = {
|
||||
}
|
||||
|
||||
ATTR_IS_HUE_GROUP = 'is_hue_group'
|
||||
GAMUT_TYPE_UNAVAILABLE = 'None'
|
||||
# Minimum Hue Bridge API version to support groups
|
||||
# 1.4.0 introduced extended group info
|
||||
# 1.12 introduced the state object for groups
|
||||
@@ -221,7 +222,7 @@ class HueLight(Light):
|
||||
if is_group:
|
||||
self.is_osram = False
|
||||
self.is_philips = False
|
||||
self.gamut_typ = 'None'
|
||||
self.gamut_typ = GAMUT_TYPE_UNAVAILABLE
|
||||
self.gamut = None
|
||||
else:
|
||||
self.is_osram = light.manufacturername == 'OSRAM'
|
||||
@@ -229,6 +230,15 @@ class HueLight(Light):
|
||||
self.gamut_typ = self.light.colorgamuttype
|
||||
self.gamut = self.light.colorgamut
|
||||
_LOGGER.debug("Color gamut of %s: %s", self.name, str(self.gamut))
|
||||
if self.gamut:
|
||||
if not color.check_valid_gamut(self.gamut):
|
||||
err = "Please check for software updates of the bridge " \
|
||||
"and/or bulb in the Philips Hue App, " \
|
||||
"Color gamut of %s: %s, not valid, " \
|
||||
"setting gamut to None."
|
||||
_LOGGER.warning(err, self.name, str(self.gamut))
|
||||
self.gamut_typ = GAMUT_TYPE_UNAVAILABLE
|
||||
self.gamut = None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
||||
@@ -600,3 +600,21 @@ def check_point_in_lamps_reach(p: Tuple[float, float],
|
||||
t = cross_product(v1, q) / cross_product(v1, v2)
|
||||
|
||||
return (s >= 0.0) and (t >= 0.0) and (s + t <= 1.0)
|
||||
|
||||
|
||||
def check_valid_gamut(Gamut: GamutType) -> bool:
|
||||
"""Check if the supplied gamut is valid."""
|
||||
# Check if the three points of the supplied gamut are not on the same line.
|
||||
v1 = XYPoint(Gamut.green.x - Gamut.red.x, Gamut.green.y - Gamut.red.y)
|
||||
v2 = XYPoint(Gamut.blue.x - Gamut.red.x, Gamut.blue.y - Gamut.red.y)
|
||||
not_on_line = cross_product(v1, v2) > 0.0001
|
||||
|
||||
# Check if all six coordinates of the gamut lie between 0 and 1.
|
||||
red_valid = Gamut.red.x >= 0 and Gamut.red.x <= 1 and \
|
||||
Gamut.red.y >= 0 and Gamut.red.y <= 1
|
||||
green_valid = Gamut.green.x >= 0 and Gamut.green.x <= 1 and \
|
||||
Gamut.green.y >= 0 and Gamut.green.y <= 1
|
||||
blue_valid = Gamut.blue.x >= 0 and Gamut.blue.x <= 1 and \
|
||||
Gamut.blue.y >= 0 and Gamut.blue.y <= 1
|
||||
|
||||
return not_on_line and red_valid and green_valid and blue_valid
|
||||
Reference in new issue
Block a user