mirror of
https://github.com/home-assistant/core.git
synced 2026-05-15 13:01:22 +01:00
Fix ESPHome cold/warm white color temperature read-back (#167972)
This commit is contained in:
@@ -259,15 +259,18 @@ class EsphomeLight(EsphomeEntity[LightInfo, LightState], LightEntity):
|
||||
if (color_temp_k := kwargs.get(ATTR_COLOR_TEMP_KELVIN)) is not None:
|
||||
# Do not use kelvin_to_mired here to prevent precision loss
|
||||
color_temp_mired = 1_000_000.0 / color_temp_k
|
||||
data["color_temperature"] = color_temp_mired
|
||||
if color_temp_modes := _filter_color_modes(
|
||||
color_modes, LightColorCapability.COLOR_TEMPERATURE
|
||||
):
|
||||
data["color_temperature"] = color_temp_mired
|
||||
color_modes = color_temp_modes
|
||||
else:
|
||||
# Convert color temperature to explicit cold/warm white
|
||||
# values to avoid ESPHome applying brightness to both
|
||||
# master brightness and white channels (b² effect).
|
||||
# Also send explicit cold/warm white values to avoid
|
||||
# ESPHome applying brightness to both master brightness
|
||||
# and white channels (b² effect). The firmware skips
|
||||
# deriving cwww from color_temperature when the channels
|
||||
# are already set explicitly, but still stores
|
||||
# color_temperature so HA can read it back.
|
||||
data["cold_white"], data["warm_white"] = self._color_temp_to_cold_warm(
|
||||
color_temp_mired
|
||||
)
|
||||
|
||||
@@ -1913,6 +1913,7 @@ async def test_only_cold_warm_white_support(
|
||||
key=1,
|
||||
state=True,
|
||||
color_mode=color_modes,
|
||||
color_temperature=pytest.approx(400.0),
|
||||
cold_white=pytest.approx(0.0),
|
||||
warm_white=pytest.approx(1.0),
|
||||
device_id=0,
|
||||
@@ -1944,6 +1945,7 @@ async def test_only_cold_warm_white_support(
|
||||
state=True,
|
||||
brightness=pytest.approx(0.4980392156862745),
|
||||
color_mode=color_modes,
|
||||
color_temperature=pytest.approx(277.7777777777778),
|
||||
cold_white=pytest.approx(0.9798, abs=1e-3),
|
||||
warm_white=pytest.approx(1.0),
|
||||
device_id=0,
|
||||
@@ -2008,6 +2010,7 @@ async def test_cold_warm_white_no_mireds_set(
|
||||
key=1,
|
||||
state=True,
|
||||
color_mode=color_modes,
|
||||
color_temperature=pytest.approx(277.7777777777778),
|
||||
cold_white=1.0,
|
||||
warm_white=1.0,
|
||||
device_id=0,
|
||||
|
||||
Reference in New Issue
Block a user