Add options flow fallback for ports

This commit is contained in:
2026-02-13 19:33:55 +01:00
parent 8b20cf4744
commit 502a33dbac
7 changed files with 202 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ from .const import (
CONF_INVERT_OUTGOING,
CONF_MOVE_LONG_ADDRESS,
CONF_MOVE_SHORT_ADDRESS,
CONF_PORTS,
CONF_POSITION_ADDRESS,
CONF_POSITION_STATE_ADDRESS,
CONF_STATE_ADDRESS,
@@ -117,10 +118,8 @@ class BridgeManager:
switch_ports: list[SwitchPort] = []
cover_ports: list[CoverPort] = []
subentries = getattr(self.entry, "subentries", [])
for subentry in subentries:
data = subentry.data
if subentry.type == "binary_sensor":
for port_type, data in _iter_port_configs(self.entry):
if port_type == "binary_sensor":
binary_ports.append(
BinarySensorPort(
entity_id=data["entity_id"],
@@ -133,7 +132,7 @@ class BridgeManager:
),
)
)
elif subentry.type == "switch":
elif port_type == "switch":
switch_ports.append(
SwitchPort(
entity_id=data["entity_id"],
@@ -155,7 +154,7 @@ class BridgeManager:
),
)
)
elif subentry.type == "cover":
elif port_type == "cover":
cover_ports.append(
CoverPort(
entity_id=data["entity_id"],
@@ -632,3 +631,17 @@ def _invert_out_key(address_key: str) -> str:
def _get_value_type(address_key: str) -> str | None:
return ADDRESS_VALUE_TYPE.get(address_key)
def _iter_port_configs(entry: ConfigEntry) -> list[tuple[str, dict[str, Any]]]:
ports: list[tuple[str, dict[str, Any]]] = []
subentries = getattr(entry, "subentries", [])
for subentry in subentries:
ports.append((subentry.type, subentry.data))
option_ports = entry.options.get(CONF_PORTS, [])
for port in option_ports:
port_type = port.get("type")
data = port.get("data", {})
if port_type and isinstance(data, dict):
ports.append((port_type, data))
return ports