mirror of
https://github.com/bahmcloud/HA-KNX-Bridge.git
synced 2026-04-06 16:51:14 +00:00
Add light relative dimming
This commit is contained in:
@@ -43,6 +43,7 @@ from .const import (
|
||||
CONF_LIGHT_COLOR_TEMPERATURE_ADDRESS,
|
||||
CONF_LIGHT_COLOR_TEMPERATURE_STATE_ADDRESS,
|
||||
CONF_LIGHT_COLOR_TEMPERATURE_MODE,
|
||||
CONF_LIGHT_RELATIVE_DIMMING_ADDRESS,
|
||||
CONF_LIGHT_MIN_KELVIN,
|
||||
CONF_LIGHT_MAX_KELVIN,
|
||||
CONF_LIGHT_RED_ADDRESS,
|
||||
@@ -143,6 +144,7 @@ class LightPort:
|
||||
color_temperature_mode: str
|
||||
min_kelvin: int | None
|
||||
max_kelvin: int | None
|
||||
relative_dimming_address: str | None
|
||||
red_address: str | None
|
||||
red_state_address: str | None
|
||||
red_state_invert_outgoing: bool
|
||||
@@ -336,6 +338,9 @@ class BridgeManager:
|
||||
color_temperature_mode=color_temp_mode,
|
||||
min_kelvin=_clean_int(data.get(CONF_LIGHT_MIN_KELVIN)),
|
||||
max_kelvin=_clean_int(data.get(CONF_LIGHT_MAX_KELVIN)),
|
||||
relative_dimming_address=_clean_address(
|
||||
data.get(CONF_LIGHT_RELATIVE_DIMMING_ADDRESS)
|
||||
),
|
||||
red_address=_clean_address(data.get(CONF_LIGHT_RED_ADDRESS)),
|
||||
red_state_address=_clean_address(
|
||||
data.get(CONF_LIGHT_RED_STATE_ADDRESS)
|
||||
@@ -656,6 +661,12 @@ class BridgeManager:
|
||||
port,
|
||||
"color_temperature",
|
||||
)
|
||||
self._register_knx_light_command(
|
||||
port.relative_dimming_address,
|
||||
None,
|
||||
port,
|
||||
"relative_dimming",
|
||||
)
|
||||
self._register_knx_light_command(
|
||||
port.red_address,
|
||||
_get_event_type(CONF_LIGHT_RED_ADDRESS),
|
||||
@@ -1139,6 +1150,27 @@ class BridgeManager:
|
||||
)
|
||||
return
|
||||
|
||||
if action == "relative_dimming":
|
||||
value = _extract_event_value(event)
|
||||
if value is None:
|
||||
return
|
||||
if value in (0, 8):
|
||||
return
|
||||
step = _relative_dimming_step(value)
|
||||
if step is None:
|
||||
return
|
||||
direction, percent = step
|
||||
if percent <= 0:
|
||||
return
|
||||
if direction == "down":
|
||||
percent = -percent
|
||||
await self._call_light_service(
|
||||
port.entity_id,
|
||||
"turn_on",
|
||||
{"brightness_step_pct": percent},
|
||||
)
|
||||
return
|
||||
|
||||
if action.startswith("red_"):
|
||||
await self._handle_light_component_action(port, "red", action, event)
|
||||
elif action.startswith("green_"):
|
||||
@@ -1635,6 +1667,32 @@ def _light_uses_white_channel(port: LightPort) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def _relative_dimming_step(value: int) -> tuple[str, int] | None:
|
||||
if value < 0 or value > 15:
|
||||
return None
|
||||
if value == 0 or value == 8:
|
||||
return None
|
||||
if value <= 7:
|
||||
direction = "down"
|
||||
step = value
|
||||
else:
|
||||
direction = "up"
|
||||
step = value - 8
|
||||
percent_map = {
|
||||
1: 100,
|
||||
2: 50,
|
||||
3: 25,
|
||||
4: 13,
|
||||
5: 6,
|
||||
6: 3,
|
||||
7: 2,
|
||||
}
|
||||
percent = percent_map.get(step)
|
||||
if percent is None:
|
||||
return None
|
||||
return direction, percent
|
||||
|
||||
|
||||
def _map_scalar_value(value: Any) -> int | None:
|
||||
if isinstance(value, bool):
|
||||
return 1 if value else 0
|
||||
|
||||
Reference in New Issue
Block a user