Fix HA 2026.03 light color temp compatibility and bump 0.0.34

This commit is contained in:
2026-03-09 08:20:49 +01:00
parent 69267f7c0f
commit 221454d5e8
5 changed files with 50 additions and 49 deletions

View File

@@ -8,7 +8,6 @@ from typing import Any
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_MODE,
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
ATTR_RGB_COLOR,
ATTR_RGBW_COLOR,
@@ -79,6 +78,11 @@ _LOGGER = logging.getLogger(__name__)
KNX_DOMAIN = "knx"
try:
from homeassistant.components.light import ATTR_COLOR_TEMP
except ImportError: # pragma: no cover - fallback for newer HA
ATTR_COLOR_TEMP = "color_temp"
try:
from homeassistant.components.light import ATTR_COLOR_TEMP_KELVIN
except ImportError: # pragma: no cover - fallback for older HA
@@ -678,13 +682,13 @@ class BridgeManager:
)
self._register_knx_light_command(
port.relative_color_temperature_address,
None,
"control_dimming",
port,
"relative_color_temperature",
)
self._register_knx_light_command(
port.relative_dimming_address,
None,
"control_dimming",
port,
"relative_dimming",
)
@@ -1167,7 +1171,7 @@ class BridgeManager:
await self._call_light_service(
port.entity_id,
"turn_on",
{"color_temp": _kelvin_to_mireds(kelvin)},
{ATTR_COLOR_TEMP_KELVIN: int(round(kelvin))},
)
return
@@ -1176,13 +1180,7 @@ class BridgeManager:
if dim_info is not None:
control, step_code = dim_info
if step_code == 0:
direction = "up" if control else "down"
if port.entity_id in self._light_dimming_tasks:
self._stop_light_dimming(port.entity_id)
return
self._start_light_dimming(
port.entity_id, direction, 1
)
self._stop_light_dimming(port.entity_id)
return
value = _extract_dimming_value(event)
if value is None:
@@ -1204,13 +1202,7 @@ class BridgeManager:
if dim_info is not None:
control, step_code = dim_info
if step_code == 0:
direction = "up" if control else "down"
if port.entity_id in self._light_ct_tasks:
self._stop_light_ct_adjust(port.entity_id)
return
self._start_light_ct_adjust(
port, direction, 1
)
self._stop_light_ct_adjust(port.entity_id)
return
value = _extract_dimming_value(event)
if value is None:
@@ -1516,7 +1508,7 @@ class BridgeManager:
await self._call_light_service(
port.entity_id,
"turn_on",
{"color_temp": _kelvin_to_mireds(next_kelvin)},
{ATTR_COLOR_TEMP_KELVIN: int(round(next_kelvin))},
)
await asyncio.sleep(0.3)
@@ -1549,7 +1541,7 @@ class BridgeManager:
await self._call_light_service(
port.entity_id,
"turn_on",
{"color_temp": _kelvin_to_mireds(next_kelvin)},
{ATTR_COLOR_TEMP_KELVIN: int(round(next_kelvin))},
)
self.hass.async_create_task(_runner())
@@ -1595,8 +1587,11 @@ def _extract_dimming_info(event: Event) -> tuple[bool, int] | None:
control = value.get("control")
step = value.get("stepcode", value.get("step_code"))
if control is not None and step is not None:
control_bit = _parse_control_value(control)
if control_bit is None:
return None
try:
return bool(int(control)), int(step) & 0x07
return control_bit, int(step) & 0x07
except (TypeError, ValueError):
return None
if isinstance(value, (int, float)):
@@ -1616,6 +1611,20 @@ def _extract_dimming_info(event: Event) -> tuple[bool, int] | None:
return None
def _parse_control_value(value: Any) -> bool | None:
if isinstance(value, bool):
return value
if isinstance(value, (int, float)):
return bool(int(value))
if isinstance(value, str):
text = value.strip().lower()
if text in ("increase", "up", "raise", "1", "true", "on"):
return True
if text in ("decrease", "down", "lower", "0", "false", "off"):
return False
return None
def _clean_address(address: Any) -> str | None:
if not address:
return None
@@ -1692,12 +1701,6 @@ def _percent_to_brightness(percent: int) -> int:
return int(round(percent / 100 * 255))
def _kelvin_to_mireds(kelvin: float) -> int:
if kelvin <= 0:
return 0
return int(round(1000000 / kelvin))
def _mireds_to_kelvin(mireds: float) -> float:
if mireds <= 0:
return 0
@@ -1889,21 +1892,11 @@ def _relative_dimming_step(value: int) -> tuple[str, int] | None:
return None
if value <= 7:
direction = "down"
step = value
percent = value
else:
direction = "up"
step = value - 8
percent_map = {
1: 10,
2: 8,
3: 6,
4: 4,
5: 3,
6: 2,
7: 1,
}
percent = percent_map.get(step)
if percent is None:
percent = value
if percent <= 0:
return None
return direction, percent