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(
            selector.NumberSelectorConfig(
                min=0,
                max=6,
                mode=selector.NumberSelectorMode.BOX,
                unit_of_measurement="decimals",
            ),
        ),
        vol.Required(CONF_UNIT_PREFIX, default="none"): selector.SelectSelector(
            selector.SelectSelectorConfig(options=UNIT_PREFIXES),
        ),
        vol.Required(CONF_UNIT_TIME, default=TIME_HOURS): selector.SelectSelector(
            selector.SelectSelectorConfig(
                options=TIME_UNITS, mode=selector.SelectSelectorMode.DROPDOWN
Example #2
0
ERROR_INVALID_ROUTE = "No FerryAnnouncement found"

DATA_SCHEMA = vol.Schema({
    vol.Required(CONF_API_KEY):
    selector.TextSelector(selector.TextSelectorConfig()),
    vol.Required(CONF_FROM):
    selector.TextSelector(selector.TextSelectorConfig()),
    vol.Optional(CONF_TO):
    selector.TextSelector(selector.TextSelectorConfig()),
    vol.Optional(CONF_TIME):
    selector.TimeSelector(selector.TimeSelectorConfig()),
    vol.Required(CONF_WEEKDAY, default=WEEKDAYS):
    selector.SelectSelector(
        selector.SelectSelectorConfig(
            options=WEEKDAYS,
            multiple=True,
            mode=selector.SelectSelectorMode.DROPDOWN,
        )),
})
DATA_SCHEMA_REAUTH = vol.Schema({
    vol.Required(CONF_API_KEY):
    selector.TextSelector(selector.TextSelectorConfig()),
})


class TVFerryConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
    """Handle a config flow for Trafikverket Ferry integration."""

    VERSION = 1

    entry: config_entries.ConfigEntry | None
_STATISTIC_MEASURES = [
    selector.SelectOptionDict(value="min", label="Minimum"),
    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)
}
    selector.SelectOptionDict(value=TIME_DAYS, label="Days"),
]

OPTIONS_SCHEMA = vol.Schema(
    {
        vol.Required(CONF_ROUND_DIGITS, default=2): selector.NumberSelector(
            selector.NumberSelectorConfig(
                min=0,
                max=6,
                mode=selector.NumberSelectorMode.BOX,
                unit_of_measurement="decimals",
            ),
        ),
        vol.Required(CONF_TIME_WINDOW): selector.DurationSelector(),
        vol.Required(CONF_UNIT_PREFIX, default="none"): selector.SelectSelector(
            selector.SelectSelectorConfig(options=UNIT_PREFIXES),
        ),
        vol.Required(CONF_UNIT_TIME, default=TIME_HOURS): selector.SelectSelector(
            selector.SelectSelectorConfig(options=TIME_UNITS),
        ),
    }
)

CONFIG_SCHEMA = vol.Schema(
    {
        vol.Required(CONF_NAME): selector.TextSelector(),
        vol.Required(CONF_SOURCE): selector.EntitySelector(
            selector.EntitySelectorConfig(domain="sensor"),
        ),
    }
).extend(OPTIONS_SCHEMA.schema)
Example #5
0
OPTIONS_SCHEMA = vol.Schema(
    {
        vol.Required(CONF_SOURCE_SENSOR): selector.EntitySelector(
            selector.EntitySelectorConfig(domain="sensor"),
        ),
    }
)

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(),
Example #6
0
    selector.SelectOptionDict(value=Platform.FAN, label="Fan"),
    selector.SelectOptionDict(value=Platform.LIGHT, label="Light"),
    selector.SelectOptionDict(value=Platform.LOCK, label="Lock"),
    selector.SelectOptionDict(value=Platform.SIREN, label="Siren"),
]

CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
    "user":
    SchemaFlowFormStep(
        vol.Schema({
            vol.Required(CONF_ENTITY_ID):
            selector.EntitySelector(
                selector.EntitySelectorConfig(domain=Platform.SWITCH), ),
            vol.Required(CONF_TARGET_DOMAIN):
            selector.SelectSelector(
                selector.SelectSelectorConfig(
                    options=TARGET_DOMAIN_OPTIONS), ),
        }))
}


class SwitchAsXConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
    """Handle a config flow for Switch as X."""

    config_flow = CONFIG_FLOW

    def async_config_entry_title(self, options: Mapping[str, Any]) -> str:
        """Return config entry title and hide the wrapped entity if registered."""
        # Hide the wrapped entry if registered
        registry = er.async_get(self.hass)
        entity_entry = registry.async_get(options[CONF_ENTITY_ID])
        if entity_entry is not None and not entity_entry.hidden: