mirror of
https://github.com/bahmcloud/HA-KNX-Bridge.git
synced 2026-04-06 18:01:14 +00:00
Add switch port support
This commit is contained in:
@@ -12,6 +12,7 @@ from homeassistant.helpers import selector
|
||||
from .const import (
|
||||
CONF_ANGLE_ADDRESS,
|
||||
CONF_ANGLE_STATE_ADDRESS,
|
||||
CONF_COMMAND_ADDRESS,
|
||||
CONF_KNX_ENTRY_ID,
|
||||
CONF_MOVE_LONG_ADDRESS,
|
||||
CONF_MOVE_SHORT_ADDRESS,
|
||||
@@ -66,6 +67,9 @@ class HAKnxBridgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"binary_sensor": config_entries.SubentryType(
|
||||
name="Binary Sensor Port", flow_class=BinarySensorPortSubentryFlow
|
||||
),
|
||||
"switch": config_entries.SubentryType(
|
||||
name="Switch Port", flow_class=SwitchPortSubentryFlow
|
||||
),
|
||||
"cover": config_entries.SubentryType(
|
||||
name="Cover Port", flow_class=CoverPortSubentryFlow
|
||||
),
|
||||
@@ -102,6 +106,24 @@ class BinarySensorPortSubentryFlow(config_entries.ConfigSubentryFlow):
|
||||
return self.async_show_form(step_id="user", data_schema=_binary_sensor_schema())
|
||||
|
||||
|
||||
class SwitchPortSubentryFlow(config_entries.ConfigSubentryFlow):
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input: dict | None = None):
|
||||
if user_input is not None:
|
||||
user_input, errors = _validate_knx_addresses(
|
||||
user_input, [CONF_COMMAND_ADDRESS, CONF_STATE_ADDRESS]
|
||||
)
|
||||
if errors:
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=_switch_schema(), errors=errors
|
||||
)
|
||||
title = _entity_title(self.hass, user_input[CONF_ENTITY_ID])
|
||||
return self.async_create_entry(title=title, data=user_input)
|
||||
|
||||
return self.async_show_form(step_id="user", data_schema=_switch_schema())
|
||||
|
||||
|
||||
class CoverPortSubentryFlow(config_entries.ConfigSubentryFlow):
|
||||
VERSION = 1
|
||||
|
||||
@@ -180,6 +202,22 @@ def _cover_schema() -> vol.Schema:
|
||||
)
|
||||
|
||||
|
||||
def _switch_schema() -> vol.Schema:
|
||||
return vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_ENTITY_ID): selector.EntitySelector(
|
||||
selector.EntitySelectorConfig(domain=["switch"])
|
||||
),
|
||||
vol.Optional(CONF_COMMAND_ADDRESS): selector.TextSelector(
|
||||
selector.TextSelectorConfig(type="text")
|
||||
),
|
||||
vol.Optional(CONF_STATE_ADDRESS): selector.TextSelector(
|
||||
selector.TextSelectorConfig(type="text")
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _validate_knx_addresses(
|
||||
user_input: dict, keys: list[str]
|
||||
) -> tuple[dict, dict[str, str]]:
|
||||
|
||||
Reference in New Issue
Block a user