Remove incoming inversion toggles

This commit is contained in:
2026-02-15 16:47:44 +01:00
parent b59455909c
commit c5ab9e854c
47 changed files with 73 additions and 1015 deletions

View File

@@ -15,7 +15,6 @@ from .const import (
ADDRESS_EVENT_TYPE,
ADDRESS_VALUE_TYPE,
CONF_COMMAND_ADDRESS,
CONF_INVERT_INCOMING,
CONF_INVERT_OUTGOING,
CONF_MOVE_LONG_ADDRESS,
CONF_MOVE_SHORT_ADDRESS,
@@ -36,7 +35,6 @@ KNX_DOMAIN = "knx"
class BinarySensorPort:
entity_id: str
state_address: str | None
state_invert_incoming: bool
state_invert_outgoing: bool
@@ -44,25 +42,13 @@ class BinarySensorPort:
class CoverPort:
entity_id: str
move_long_address: str | None
move_long_invert_incoming: bool
move_long_invert_outgoing: bool
move_short_address: str | None
move_short_invert_incoming: bool
move_short_invert_outgoing: bool
stop_address: str | None
stop_invert_incoming: bool
stop_invert_outgoing: bool
position_address: str | None
position_invert_incoming: bool
position_invert_outgoing: bool
position_state_address: str | None
position_state_invert_incoming: bool
position_state_invert_outgoing: bool
angle_address: str | None
angle_invert_incoming: bool
angle_invert_outgoing: bool
angle_state_address: str | None
angle_state_invert_incoming: bool
angle_state_invert_outgoing: bool
@@ -71,16 +57,12 @@ class SwitchPort:
entity_id: str
command_address: str | None
state_address: str | None
command_invert_incoming: bool
command_invert_outgoing: bool
state_invert_incoming: bool
state_invert_outgoing: bool
@dataclass(frozen=True)
class AddressOptions:
value_type: str | None
invert_incoming: bool
invert_outgoing: bool
@@ -131,9 +113,6 @@ class BridgeManager:
BinarySensorPort(
entity_id=data["entity_id"],
state_address=_clean_address(data.get(CONF_STATE_ADDRESS)),
state_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_STATE_ADDRESS))
),
state_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_STATE_ADDRESS))
),
@@ -147,15 +126,6 @@ class BridgeManager:
data.get(CONF_COMMAND_ADDRESS)
),
state_address=_clean_address(data.get(CONF_STATE_ADDRESS)),
command_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_COMMAND_ADDRESS))
),
command_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_COMMAND_ADDRESS))
),
state_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_STATE_ADDRESS))
),
state_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_STATE_ADDRESS))
),
@@ -166,55 +136,19 @@ class BridgeManager:
CoverPort(
entity_id=data["entity_id"],
move_long_address=_clean_address(data.get(CONF_MOVE_LONG_ADDRESS)),
move_long_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_MOVE_LONG_ADDRESS))
),
move_long_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_MOVE_LONG_ADDRESS))
),
move_short_address=_clean_address(data.get(CONF_MOVE_SHORT_ADDRESS)),
move_short_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_MOVE_SHORT_ADDRESS))
),
move_short_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_MOVE_SHORT_ADDRESS))
),
stop_address=_clean_address(data.get(CONF_STOP_ADDRESS)),
stop_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_STOP_ADDRESS))
),
stop_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_STOP_ADDRESS))
),
position_address=_clean_address(data.get(CONF_POSITION_ADDRESS)),
position_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_POSITION_ADDRESS))
),
position_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_POSITION_ADDRESS))
),
position_state_address=_clean_address(
data.get(CONF_POSITION_STATE_ADDRESS)
),
position_state_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_POSITION_STATE_ADDRESS))
),
position_state_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_POSITION_STATE_ADDRESS))
),
angle_address=_clean_address(data.get(CONF_ANGLE_ADDRESS)),
angle_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_ANGLE_ADDRESS))
),
angle_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_ANGLE_ADDRESS))
),
angle_state_address=_clean_address(
data.get(CONF_ANGLE_STATE_ADDRESS)
),
angle_state_invert_incoming=_clean_bool(
data.get(_invert_in_key(CONF_ANGLE_STATE_ADDRESS))
),
angle_state_invert_outgoing=_clean_bool(
data.get(_invert_out_key(CONF_ANGLE_STATE_ADDRESS))
),
@@ -235,7 +169,6 @@ class BridgeManager:
self._remember_address_options(
port.state_address,
_get_value_type(CONF_STATE_ADDRESS),
port.state_invert_incoming,
port.state_invert_outgoing,
)
self._unsub_listeners.append(
@@ -250,7 +183,6 @@ class BridgeManager:
self._remember_address_options(
port.state_address,
_get_value_type(CONF_STATE_ADDRESS),
port.state_invert_incoming,
port.state_invert_outgoing,
)
self._unsub_listeners.append(
@@ -266,14 +198,12 @@ class BridgeManager:
self._remember_address_options(
port.position_state_address,
_get_value_type(CONF_POSITION_STATE_ADDRESS),
port.position_state_invert_incoming,
port.position_state_invert_outgoing,
)
if port.angle_state_address:
self._remember_address_options(
port.angle_state_address,
_get_value_type(CONF_ANGLE_STATE_ADDRESS),
port.angle_state_invert_incoming,
port.angle_state_invert_outgoing,
)
self._unsub_listeners.append(
@@ -288,8 +218,6 @@ class BridgeManager:
for port in switch_ports:
self._register_knx_switch_address(
port.command_address,
port.command_invert_incoming,
port.command_invert_outgoing,
port,
)
@@ -297,40 +225,30 @@ class BridgeManager:
self._register_knx_address(
port.move_long_address,
CONF_MOVE_LONG_ADDRESS,
port.move_long_invert_incoming,
port.move_long_invert_outgoing,
port,
"move_long",
)
self._register_knx_address(
port.move_short_address,
CONF_MOVE_SHORT_ADDRESS,
port.move_short_invert_incoming,
port.move_short_invert_outgoing,
port,
"move_short",
)
self._register_knx_address(
port.stop_address,
CONF_STOP_ADDRESS,
port.stop_invert_incoming,
port.stop_invert_outgoing,
port,
"stop",
)
self._register_knx_address(
port.position_address,
CONF_POSITION_ADDRESS,
port.position_invert_incoming,
port.position_invert_outgoing,
port,
"position",
)
self._register_knx_address(
port.angle_address,
CONF_ANGLE_ADDRESS,
port.angle_invert_incoming,
port.angle_invert_outgoing,
port,
"angle",
)
@@ -351,8 +269,6 @@ class BridgeManager:
self,
address: str | None,
address_key: str,
invert_incoming: bool,
invert_outgoing: bool,
port: CoverPort,
action: str,
) -> None:
@@ -365,15 +281,13 @@ class BridgeManager:
value_type = _get_value_type(address_key)
event_type = _get_event_type(address_key)
self._remember_address_options(
address, value_type, invert_incoming, invert_outgoing
address, value_type, False
)
self._registered_addresses.append((address, event_type))
def _register_knx_switch_address(
self,
address: str | None,
invert_incoming: bool,
invert_outgoing: bool,
port: SwitchPort,
) -> None:
if not address:
@@ -384,8 +298,7 @@ class BridgeManager:
self._remember_address_options(
address,
_get_value_type(CONF_COMMAND_ADDRESS),
invert_incoming,
invert_outgoing,
False,
)
self._registered_addresses.append((address, _get_event_type(CONF_COMMAND_ADDRESS)))
@@ -393,12 +306,10 @@ class BridgeManager:
self,
address: str,
value_type: str | None,
invert_incoming: bool,
invert_outgoing: bool,
) -> None:
self._address_options[address] = AddressOptions(
value_type=value_type,
invert_incoming=invert_incoming,
invert_outgoing=invert_outgoing,
)
@@ -430,7 +341,7 @@ class BridgeManager:
return
payload = 1 if new_state.state == "on" else 0
payload = _invert_value(
payload, port.state_address, self._address_options, "outgoing"
payload, port.state_address, self._address_options
)
await self._knx_send_raw(port.state_address, payload)
@@ -445,7 +356,7 @@ class BridgeManager:
return
payload = 1 if new_state.state == "on" else 0
payload = _invert_value(
payload, port.state_address, self._address_options, "outgoing"
payload, port.state_address, self._address_options
)
await self._knx_send_raw(port.state_address, payload)
@@ -464,7 +375,6 @@ class BridgeManager:
position,
port.position_state_address,
self._address_options,
"outgoing",
)
await self._knx_send_percent(
port.position_state_address, position
@@ -477,7 +387,6 @@ class BridgeManager:
angle,
port.angle_state_address,
self._address_options,
"outgoing",
)
await self._knx_send_percent(port.angle_state_address, angle)
@@ -505,7 +414,7 @@ class BridgeManager:
if value is None:
return
destination = _event_destination(event)
value = _invert_value(value, destination, self._address_options, "incoming")
value = _invert_value(value, destination, self._address_options)
if action == "move_long":
if value == 0:
@@ -532,7 +441,7 @@ class BridgeManager:
if value is None:
return
destination = _event_destination(event)
value = _invert_value(value, destination, self._address_options, "incoming")
value = _invert_value(value, destination, self._address_options)
if value == 0:
await self._call_switch_service(port.entity_id, "turn_off")
elif value == 1:
@@ -617,7 +526,6 @@ def _invert_value(
value: int,
address: str | None,
address_options: dict[str, AddressOptions],
direction: str,
) -> int:
if address is None:
return value
@@ -626,12 +534,8 @@ def _invert_value(
return value
if options.value_type == "percent":
value = _clamp_percent(value)
if direction == "incoming":
if not options.invert_incoming:
return value
else:
if not options.invert_outgoing:
return value
if not options.invert_outgoing:
return value
if options.value_type == "percent":
return 100 - value
if value not in (0, 1):
@@ -639,10 +543,6 @@ def _invert_value(
return 0 if value == 1 else 1
def _invert_in_key(address_key: str) -> str:
return f"{address_key}_{CONF_INVERT_INCOMING}"
def _invert_out_key(address_key: str) -> str:
return f"{address_key}_{CONF_INVERT_OUTGOING}"