Add port devices and enable toggles

This commit is contained in:
2026-02-13 21:13:54 +01:00
parent 6824134c91
commit 0af4fc8375
47 changed files with 646 additions and 245 deletions

View File

@@ -23,6 +23,8 @@ from .const import (
CONF_PORT_ID,
CONF_POSITION_ADDRESS,
CONF_POSITION_STATE_ADDRESS,
CONF_ENABLED,
CONF_PORT_ENABLED,
CONF_STATE_ADDRESS,
CONF_STOP_ADDRESS,
DOMAIN,
@@ -170,7 +172,12 @@ class HAKnxBridgeOptionsFlow(config_entries.OptionsFlow):
if user_input is not None:
port_id = user_input[CONF_PORT_ID]
ports = [port for port in ports if port.get("id") != port_id]
return self.async_create_entry(title="", data={CONF_PORTS: ports})
overrides = dict(self._config_entry.options.get(CONF_PORT_ENABLED, {}))
overrides.pop(port_id, None)
return self.async_create_entry(
title="",
data={CONF_PORTS: ports, CONF_PORT_ENABLED: overrides},
)
options = [
{
@@ -250,15 +257,22 @@ class HAKnxBridgeOptionsFlow(config_entries.OptionsFlow):
async def _async_store_port(self, port_type: str, user_input: dict):
ports = list(self._config_entry.options.get(CONF_PORTS, []))
title = _entity_title(self.hass, user_input[CONF_ENTITY_ID])
enabled = bool(user_input.get(CONF_ENABLED, True))
ports.append(
{
"id": uuid.uuid4().hex,
"type": port_type,
"title": title,
"data": user_input,
"enabled": enabled,
}
)
return self.async_create_entry(title="", data={CONF_PORTS: ports})
overrides = dict(self._config_entry.options.get(CONF_PORT_ENABLED, {}))
overrides[ports[-1]["id"]] = enabled
return self.async_create_entry(
title="",
data={CONF_PORTS: ports, CONF_PORT_ENABLED: overrides},
)
async def _async_edit_port(self, port_type: str, user_input, schema_factory):
ports = list(self._config_entry.options.get(CONF_PORTS, []))
@@ -284,9 +298,16 @@ class HAKnxBridgeOptionsFlow(config_entries.OptionsFlow):
errors=errors,
)
enabled = bool(user_input.get(CONF_ENABLED, True))
port["data"] = user_input
port["enabled"] = enabled
port["title"] = _entity_title(self.hass, user_input[CONF_ENTITY_ID])
return self.async_create_entry(title="", data={CONF_PORTS: ports})
overrides = dict(self._config_entry.options.get(CONF_PORT_ENABLED, {}))
overrides[port_id] = enabled
return self.async_create_entry(
title="",
data={CONF_PORTS: ports, CONF_PORT_ENABLED: overrides},
)
class BinarySensorPortSubentryFlow(config_entries.ConfigSubentryFlow):
@@ -390,6 +411,9 @@ def _binary_sensor_schema(defaults: dict | None = None) -> vol.Schema:
): (
selector.BooleanSelector()
),
vol.Optional(CONF_ENABLED, default=bool(defaults.get(CONF_ENABLED, True))): (
selector.BooleanSelector()
),
}
)
@@ -530,6 +554,9 @@ def _cover_schema(defaults: dict | None = None) -> vol.Schema:
): (
selector.BooleanSelector()
),
vol.Optional(CONF_ENABLED, default=bool(defaults.get(CONF_ENABLED, True))): (
selector.BooleanSelector()
),
}
)
@@ -580,6 +607,9 @@ def _switch_schema(defaults: dict | None = None) -> vol.Schema:
): (
selector.BooleanSelector()
),
vol.Optional(CONF_ENABLED, default=bool(defaults.get(CONF_ENABLED, True))): (
selector.BooleanSelector()
),
}
)