Fix KNX UI Light color temperature DPT (#123778)

This commit is contained in:
Matthias Alphart 2024-08-15 10:52:55 +02:00 committed by GitHub
parent 81c4bb5f72
commit d6d016e029
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 2 deletions

View File

@ -226,7 +226,7 @@ def _create_ui_light(xknx: XKNX, knx_config: ConfigType, name: str) -> XknxLight
group_address_color_temp_state = None group_address_color_temp_state = None
color_temperature_type = ColorTemperatureType.UINT_2_BYTE color_temperature_type = ColorTemperatureType.UINT_2_BYTE
if ga_color_temp := knx_config.get(CONF_GA_COLOR_TEMP): if ga_color_temp := knx_config.get(CONF_GA_COLOR_TEMP):
if ga_color_temp[CONF_DPT] == ColorTempModes.RELATIVE: if ga_color_temp[CONF_DPT] == ColorTempModes.RELATIVE.value:
group_address_tunable_white = ga_color_temp[CONF_GA_WRITE] group_address_tunable_white = ga_color_temp[CONF_GA_WRITE]
group_address_tunable_white_state = [ group_address_tunable_white_state = [
ga_color_temp[CONF_GA_STATE], ga_color_temp[CONF_GA_STATE],
@ -239,7 +239,7 @@ def _create_ui_light(xknx: XKNX, knx_config: ConfigType, name: str) -> XknxLight
ga_color_temp[CONF_GA_STATE], ga_color_temp[CONF_GA_STATE],
*ga_color_temp[CONF_GA_PASSIVE], *ga_color_temp[CONF_GA_PASSIVE],
] ]
if ga_color_temp[CONF_DPT] == ColorTempModes.ABSOLUTE_FLOAT: if ga_color_temp[CONF_DPT] == ColorTempModes.ABSOLUTE_FLOAT.value:
color_temperature_type = ColorTemperatureType.FLOAT_2_BYTE color_temperature_type = ColorTemperatureType.FLOAT_2_BYTE
_color_dpt = get_dpt(CONF_GA_COLOR) _color_dpt = get_dpt(CONF_GA_COLOR)

View File

@ -5,6 +5,7 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest
from xknx.core import XknxConnectionState from xknx.core import XknxConnectionState
from xknx.devices.light import Light as XknxLight from xknx.devices.light import Light as XknxLight
@ -1174,3 +1175,46 @@ async def test_light_ui_create(
await knx.receive_response("2/2/2", True) await knx.receive_response("2/2/2", True)
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state is STATE_ON assert state.state is STATE_ON
@pytest.mark.parametrize(
("color_temp_mode", "raw_ct"),
[
("7.600", (0x10, 0x68)),
("9", (0x46, 0x69)),
("5.001", (0x74,)),
],
)
async def test_light_ui_color_temp(
hass: HomeAssistant,
knx: KNXTestKit,
create_ui_entity: KnxEntityGenerator,
color_temp_mode: str,
raw_ct: tuple[int, ...],
) -> None:
"""Test creating a switch."""
await knx.setup_integration({})
await create_ui_entity(
platform=Platform.LIGHT,
entity_data={"name": "test"},
knx_data={
"ga_switch": {"write": "1/1/1", "state": "2/2/2"},
"ga_color_temp": {
"write": "3/3/3",
"dpt": color_temp_mode,
},
"_light_color_mode_schema": "default",
"sync_state": True,
},
)
await knx.assert_read("2/2/2", True)
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": "light.test", ATTR_COLOR_TEMP_KELVIN: 4200},
blocking=True,
)
await knx.assert_write("3/3/3", raw_ct)
state = hass.states.get("light.test")
assert state.state is STATE_ON
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == pytest.approx(4200, abs=1)