Update new effect before calculating color on Philips TV (#52072)

This commit is contained in:
Joakim Plate 2021-06-28 14:01:29 +02:00 committed by GitHub
parent 8133793f23
commit 24ba81c3a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -237,29 +237,34 @@ class PhilipsTVLightEntity(CoordinatorEntity, LightEntity):
def _update_from_coordinator(self):
current = self._tv.ambilight_current_configuration
color = None
if current and current["isExpert"]:
if settings := _get_settings(current):
color = settings["color"]
if color:
self._attr_hs_color = (
color["hue"] * 360.0 / 255.0,
color["saturation"] * 100.0 / 255.0,
)
self._attr_brightness = color["brightness"]
elif data := self._tv.ambilight_cached:
hsv_h, hsv_s, hsv_v = color_RGB_to_hsv(*_average_pixels(data))
self._attr_hs_color = hsv_h, hsv_s
self._attr_brightness = hsv_v * 255.0 / 100.0
else:
self._attr_hs_color = None
self._attr_brightness = None
if (cache_keys := _get_cache_keys(self._tv)) != self._cache_keys:
self._cache_keys = cache_keys
self._attr_effect_list = self._calculate_effect_list()
self._attr_effect = self._calculate_effect()
if current and current["isExpert"]:
if settings := _get_settings(current):
color = settings["color"]
mode, _, _ = _parse_effect(self._attr_effect)
if mode == EFFECT_EXPERT and color:
self._attr_hs_color = (
color["hue"] * 360.0 / 255.0,
color["saturation"] * 100.0 / 255.0,
)
self._attr_brightness = color["brightness"]
elif mode == EFFECT_MODE and self._tv.ambilight_cached:
hsv_h, hsv_s, hsv_v = color_RGB_to_hsv(
*_average_pixels(self._tv.ambilight_cached)
)
self._attr_hs_color = hsv_h, hsv_s
self._attr_brightness = hsv_v * 255.0 / 100.0
else:
self._attr_hs_color = None
self._attr_brightness = None
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""