Esempio n. 1
0
    async def async_step_secure_manual(self,
                                       user_input: dict | None = None
                                       ) -> FlowResult:
        """Configure ip secure manually."""
        errors: dict = {}

        if user_input is not None:
            assert self._tunneling_config
            entry_data = self._tunneling_config | KNXConfigEntryData(
                connection_type=CONF_KNX_TUNNELING_TCP_SECURE,
                device_authentication=user_input[
                    CONF_KNX_SECURE_DEVICE_AUTHENTICATION],
                user_id=user_input[CONF_KNX_SECURE_USER_ID],
                user_password=user_input[CONF_KNX_SECURE_USER_PASSWORD],
            )

            return self.async_create_entry(
                title=f"Secure Tunneling @ {self._tunneling_config[CONF_HOST]}",
                data=entry_data,
            )

        fields = {
            vol.Required(CONF_KNX_SECURE_USER_ID, default=2):
            vol.All(
                selector.NumberSelector(
                    selector.NumberSelectorConfig(
                        min=1, max=127,
                        mode=selector.NumberSelectorMode.BOX), ),
                vol.Coerce(int),
            ),
            vol.Required(CONF_KNX_SECURE_USER_PASSWORD):
            selector.TextSelector(
                selector.TextSelectorConfig(
                    type=selector.TextSelectorType.PASSWORD), ),
            vol.Required(CONF_KNX_SECURE_DEVICE_AUTHENTICATION):
            selector.TextSelector(
                selector.TextSelectorConfig(
                    type=selector.TextSelectorType.PASSWORD), ),
        }

        return self.async_show_form(step_id="secure_manual",
                                    data_schema=vol.Schema(fields),
                                    errors=errors)
    selector.SelectOptionDict(value=TIME_SECONDS, label="s (seconds)"),
    selector.SelectOptionDict(value=TIME_MINUTES, label="min (minutes)"),
    selector.SelectOptionDict(value=TIME_HOURS, label="h (hours)"),
    selector.SelectOptionDict(value=TIME_DAYS, label="d (days)"),
]
INTEGRATION_METHODS = [
    selector.SelectOptionDict(value=METHOD_TRAPEZOIDAL, label="Trapezoidal rule"),
    selector.SelectOptionDict(value=METHOD_LEFT, label="Left Riemann sum"),
    selector.SelectOptionDict(value=METHOD_RIGHT, label="Right Riemann sum"),
]

OPTIONS_SCHEMA = vol.Schema(
    {
        vol.Required(CONF_ROUND_DIGITS, default=2): selector.NumberSelector(
            selector.NumberSelectorConfig(
                min=0, max=6, mode=selector.NumberSelectorMode.BOX
            ),
        ),
    }
)

CONFIG_SCHEMA = vol.Schema(
    {
        vol.Required(CONF_NAME): selector.TextSelector(),
        vol.Required(CONF_SOURCE_SENSOR): selector.EntitySelector(
            selector.EntitySelectorConfig(domain="sensor")
        ),
        vol.Required(CONF_METHOD, default=METHOD_TRAPEZOIDAL): selector.SelectSelector(
            selector.SelectSelectorConfig(options=INTEGRATION_METHODS),
        ),
        vol.Required(CONF_ROUND_DIGITS, default=2): selector.NumberSelector(
Esempio n. 3
0
    CONF_TCP_PORT,
    CONF_TOPIC_IN_PREFIX,
    CONF_TOPIC_OUT_PREFIX,
    CONF_VERSION,
    DOMAIN,
    ConfGatewayType,
)
from .gateway import MQTT_COMPONENT, is_serial_port, is_socket_address, try_connect

DEFAULT_BAUD_RATE = 115200
DEFAULT_TCP_PORT = 5003
DEFAULT_VERSION = "1.4"

_PORT_SELECTOR = vol.All(
    selector.NumberSelector(
        selector.NumberSelectorConfig(min=1,
                                      max=65535,
                                      mode=selector.NumberSelectorMode.BOX), ),
    vol.Coerce(int),
)


def is_persistence_file(value: str) -> str:
    """Validate that persistence file path ends in either .pickle or .json."""
    if value.endswith((".json", ".pickle")):
        return value
    raise vol.Invalid(f"{value} does not end in either `.json` or `.pickle`")


def _get_schema_common(user_input: dict[str, str]) -> dict:
    """Create a schema with options common to all gateway types."""
    schema = {
    selector.SelectOptionDict(value="max", label="Maximum"),
    selector.SelectOptionDict(value="mean", label="Arithmetic mean"),
    selector.SelectOptionDict(value="median", label="Median"),
    selector.SelectOptionDict(value="last", label="Most recently updated"),
]

OPTIONS_SCHEMA = vol.Schema({
    vol.Required(CONF_ENTITY_IDS):
    selector.EntitySelector(
        selector.EntitySelectorConfig(domain="sensor", multiple=True), ),
    vol.Required(CONF_TYPE):
    selector.SelectSelector(
        selector.SelectSelectorConfig(options=_STATISTIC_MEASURES), ),
    vol.Required(CONF_ROUND_DIGITS, default=2):
    selector.NumberSelector(
        selector.NumberSelectorConfig(min=0,
                                      max=6,
                                      mode=selector.NumberSelectorMode.BOX), ),
})

CONFIG_SCHEMA = vol.Schema({
    vol.Required("name"): selector.TextSelector(),
}).extend(OPTIONS_SCHEMA.schema)

CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
    "user": SchemaFlowFormStep(CONFIG_SCHEMA)
}

OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
    "init": SchemaFlowFormStep(OPTIONS_SCHEMA)
}
Esempio n. 5
0
    async def async_step_init(self,
                              user_input: dict[str, Any] | None = None
                              ) -> FlowResult:
        """Manage KNX options."""
        if user_input is not None:
            self.general_settings = user_input
            return await self.async_step_tunnel()

        supported_connection_types = [
            CONF_KNX_AUTOMATIC,
            CONF_KNX_TUNNELING,
            CONF_KNX_ROUTING,
        ]
        self.current_config = self.config_entry.data  # type: ignore[assignment]

        data_schema = {
            vol.Required(
                CONF_KNX_CONNECTION_TYPE,
                default=(CONF_KNX_TUNNELING if self.current_config.get(CONF_KNX_CONNECTION_TYPE) == CONF_KNX_TUNNELING_TCP else self.current_config.get(CONF_KNX_CONNECTION_TYPE)),
            ):
            vol.In(supported_connection_types),
            vol.Required(
                CONF_KNX_INDIVIDUAL_ADDRESS,
                default=self.current_config[CONF_KNX_INDIVIDUAL_ADDRESS],
            ):
            selector.TextSelector(),
            vol.Required(
                CONF_KNX_MCAST_GRP,
                default=self.current_config.get(CONF_KNX_MCAST_GRP, DEFAULT_MCAST_GRP),
            ):
            _IP_SELECTOR,
            vol.Required(
                CONF_KNX_MCAST_PORT,
                default=self.current_config.get(CONF_KNX_MCAST_PORT, DEFAULT_MCAST_PORT),
            ):
            _PORT_SELECTOR,
        }

        if self.show_advanced_options:
            local_ip = (self.current_config.get(CONF_KNX_LOCAL_IP)
                        if self.current_config.get(CONF_KNX_LOCAL_IP)
                        is not None else CONF_DEFAULT_LOCAL_IP)
            data_schema[vol.Required(
                CONF_KNX_LOCAL_IP,
                default=local_ip,
            )] = _IP_SELECTOR
            data_schema[vol.Required(
                CONF_KNX_STATE_UPDATER,
                default=self.current_config.get(
                    CONF_KNX_STATE_UPDATER,
                    CONF_KNX_DEFAULT_STATE_UPDATER,
                ),
            )] = selector.BooleanSelector()
            data_schema[vol.Required(
                CONF_KNX_RATE_LIMIT,
                default=self.current_config.get(
                    CONF_KNX_RATE_LIMIT,
                    CONF_KNX_DEFAULT_RATE_LIMIT,
                ),
            )] = vol.All(
                selector.NumberSelector(
                    selector.NumberSelectorConfig(
                        min=0,
                        max=CONF_MAX_RATE_LIMIT,
                        mode=selector.NumberSelectorMode.BOX,
                    ), ),
                vol.Coerce(int),
            )

        return self.async_show_form(
            step_id="init",
            data_schema=vol.Schema(data_schema),
            last_step=self.current_config.get(CONF_KNX_CONNECTION_TYPE) !=
            CONF_KNX_TUNNELING,
        )
Esempio n. 6
0
    }
)

CONFIG_SCHEMA = vol.Schema(
    {
        vol.Required(CONF_NAME): selector.TextSelector(),
        vol.Required(CONF_SOURCE_SENSOR): selector.EntitySelector(
            selector.EntitySelectorConfig(domain="sensor"),
        ),
        vol.Required(CONF_METER_TYPE): selector.SelectSelector(
            selector.SelectSelectorConfig(options=METER_TYPES),
        ),
        vol.Required(CONF_METER_OFFSET, default=0): selector.NumberSelector(
            selector.NumberSelectorConfig(
                min=0,
                max=28,
                mode=selector.NumberSelectorMode.BOX,
                unit_of_measurement="days",
            ),
        ),
        vol.Required(CONF_TARIFFS, default=[]): selector.SelectSelector(
            selector.SelectSelectorConfig(options=[], custom_value=True, multiple=True),
        ),
        vol.Required(
            CONF_METER_NET_CONSUMPTION, default=False
        ): selector.BooleanSelector(),
        vol.Required(
            CONF_METER_DELTA_VALUES, default=False
        ): selector.BooleanSelector(),
    }
)
Esempio n. 7
0
    SchemaFlowMenuStep,
)

from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN


def _validate_mode(data: Any) -> Any:
    """Validate the threshold mode, and set limits to None if not set."""
    if CONF_LOWER not in data and CONF_UPPER not in data:
        raise SchemaFlowError("need_lower_upper")
    return {CONF_LOWER: None, CONF_UPPER: None, **data}


OPTIONS_SCHEMA = vol.Schema({
    vol.Required(CONF_HYSTERESIS, default=DEFAULT_HYSTERESIS):
    selector.NumberSelector(
        selector.NumberSelectorConfig(mode=selector.NumberSelectorMode.BOX), ),
    vol.Optional(CONF_LOWER):
    selector.NumberSelector(
        selector.NumberSelectorConfig(mode=selector.NumberSelectorMode.BOX), ),
    vol.Optional(CONF_UPPER):
    selector.NumberSelector(
        selector.NumberSelectorConfig(mode=selector.NumberSelectorMode.BOX), ),
})

CONFIG_SCHEMA = vol.Schema({
    vol.Required(CONF_NAME):
    selector.TextSelector(),
    vol.Required(CONF_ENTITY_ID):
    selector.EntitySelector(selector.EntitySelectorConfig(domain="sensor")),
}).extend(OPTIONS_SCHEMA.schema)