mirror of
https://github.com/bahmcloud/HA-KNX-Bridge.git
synced 2026-04-06 16:51:14 +00:00
Normalize event destination and clamp percent
This commit is contained in:
@@ -482,11 +482,7 @@ class BridgeManager:
|
||||
if direction is not None and not str(direction).lower().startswith("incoming"):
|
||||
return
|
||||
|
||||
destination = (
|
||||
event.data.get("destination")
|
||||
or event.data.get("destination_address")
|
||||
or event.data.get("address")
|
||||
)
|
||||
destination = _event_destination(event)
|
||||
if not destination:
|
||||
return
|
||||
|
||||
@@ -502,9 +498,8 @@ class BridgeManager:
|
||||
value = _extract_event_value(event)
|
||||
if value is None:
|
||||
return
|
||||
value = _invert_value(
|
||||
value, event.data.get("destination"), self._address_options, "incoming"
|
||||
)
|
||||
destination = _event_destination(event)
|
||||
value = _invert_value(value, destination, self._address_options, "incoming")
|
||||
|
||||
if action == "move_long":
|
||||
if value == 0:
|
||||
@@ -530,9 +525,8 @@ class BridgeManager:
|
||||
value = _extract_event_value(event)
|
||||
if value is None:
|
||||
return
|
||||
value = _invert_value(
|
||||
value, event.data.get("destination"), self._address_options, "incoming"
|
||||
)
|
||||
destination = _event_destination(event)
|
||||
value = _invert_value(value, destination, self._address_options, "incoming")
|
||||
if value == 0:
|
||||
await self._call_switch_service(port.entity_id, "turn_off")
|
||||
elif value == 1:
|
||||
@@ -624,6 +618,8 @@ def _invert_value(
|
||||
options = address_options.get(address)
|
||||
if options is None:
|
||||
return value
|
||||
if options.value_type == "percent":
|
||||
value = _clamp_percent(value)
|
||||
if direction == "incoming":
|
||||
if not options.invert_incoming:
|
||||
return value
|
||||
@@ -631,7 +627,6 @@ def _invert_value(
|
||||
if not options.invert_outgoing:
|
||||
return value
|
||||
if options.value_type == "percent":
|
||||
value = _clamp_percent(value)
|
||||
return 100 - value
|
||||
if value not in (0, 1):
|
||||
return value
|
||||
@@ -680,6 +675,14 @@ def _map_scalar_value(value: Any) -> int | None:
|
||||
return None
|
||||
|
||||
|
||||
def _event_destination(event: Event) -> str | None:
|
||||
return (
|
||||
event.data.get("destination")
|
||||
or event.data.get("destination_address")
|
||||
or event.data.get("address")
|
||||
)
|
||||
|
||||
|
||||
def _iter_port_configs(entry: ConfigEntry) -> list[tuple[str, dict[str, Any]]]:
|
||||
ports: list[tuple[str, dict[str, Any]]] = []
|
||||
subentries = getattr(entry, "subentries", [])
|
||||
|
||||
Reference in New Issue
Block a user