def basic_group_config_schema(domain: str) -> vol.Schema: """Generate config schema.""" return vol.Schema({ vol.Required("name"): selector.TextSelector(), vol.Required(CONF_ENTITIES): selector.EntitySelector( selector.EntitySelectorConfig(domain=domain, multiple=True), ), vol.Required(CONF_HIDE_MEMBERS, default=False): selector.BooleanSelector(), })
def basic_group_options_schema( domain: str, handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler, options: dict[str, Any], ) -> vol.Schema: """Generate options schema.""" handler = cast(SchemaOptionsFlowHandler, handler) return vol.Schema({ vol.Required(CONF_ENTITIES): entity_selector_without_own_entities( handler, selector.EntitySelectorConfig(domain=domain, multiple=True)), vol.Required(CONF_HIDE_MEMBERS, default=False): selector.BooleanSelector(), })
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( 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), ),
) from .const import CONF_ENTITY_IDS, CONF_ROUND_DIGITS, DOMAIN _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] = {
def detail_config_schema( _, options: Dict[str, Any], ) -> vol.Schema: """Generate options schema.""" options_schema: Dict[vol.Optional | vol.Required, Any] = {} if options[const.CONF_FREQUENCY] in const.ANNUAL_FREQUENCY: # "annual" options_schema[required(const.CONF_DATE, options)] = str elif options[const.CONF_FREQUENCY] in const.GROUP_FREQUENCY: # "group" options_schema[required( CONF_ENTITIES, options)] = selector.EntitySelector( selector.EntitySelectorConfig(domain="sensor", integration=const.DOMAIN, multiple=True), ) elif options[const.CONF_FREQUENCY] not in const.BLANK_FREQUENCY: # everything else except "blank" and every-n-days if options[const.CONF_FREQUENCY] not in const.DAILY_FREQUENCY: weekdays_dict = {weekday: weekday for weekday in WEEKDAYS} options_schema[required(const.CONF_COLLECTION_DAYS, options)] = cv.multi_select(weekdays_dict) # everything else except "blank" options_schema[optional(const.CONF_FIRST_MONTH, options, const.DEFAULT_FIRST_MONTH)] = vol.In( const.MONTH_OPTIONS) options_schema[optional(const.CONF_LAST_MONTH, options, const.DEFAULT_LAST_MONTH)] = vol.In( const.MONTH_OPTIONS) if options[const.CONF_FREQUENCY] in const.MONTHLY_FREQUENCY: # "monthly" options_schema[optional(const.CONF_WEEKDAY_ORDER_NUMBER, options)] = vol.All( cv.multi_select({ "1": "1st", "2": "2nd", "3": "3rd", "4": "4th", "5": "5th" }), ) options_schema[optional(const.CONF_FORCE_WEEK_NUMBERS, options)] = bool if options[const.CONF_FREQUENCY] in const.WEEKLY_DAILY_MONTHLY: # "every-n-weeks", "every-n-days", "monthly" options_schema[required(const.CONF_PERIOD, options)] = vol.All( vol.Coerce(int), vol.Range(min=1, max=1000)) if options[const.CONF_FREQUENCY] in const.WEEKLY_FREQUENCY_X: # every-n-weeks options_schema[required(const.CONF_FIRST_WEEK, options, const.DEFAULT_FIRST_WEEK)] = vol.All( vol.Coerce(int), vol.Range(min=1, max=52)) if options[const.CONF_FREQUENCY] in const.DAILY_FREQUENCY: # every-n-days options_schema[required(const.CONF_FIRST_DATE, options)] = selector.DateSelector() if options.get(const.CONF_VERBOSE_STATE, False): # "verbose_state" options_schema[required(const.CONF_VERBOSE_FORMAT, options, const.DEFAULT_VERBOSE_FORMAT)] = cv.string options_schema[required(const.CONF_DATE_FORMAT, options, const.DEFAULT_DATE_FORMAT)] = cv.string return vol.Schema(options_schema)
TARGET_DOMAIN_OPTIONS = [ selector.SelectOptionDict(value=Platform.COVER, label="Cover"), 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."""