1 """Config flow for Utility Meter integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from typing
import Any, cast
8 import voluptuous
as vol
14 SchemaCommonFlowHandler,
15 SchemaConfigFlowHandler,
22 CONF_METER_DELTA_VALUES,
23 CONF_METER_NET_CONSUMPTION,
25 CONF_METER_PERIODICALLY_RESETTING,
27 CONF_SENSOR_ALWAYS_AVAILABLE,
54 handler: SchemaCommonFlowHandler, user_input: dict[str, Any]
56 """Validate config."""
58 vol.Unique()(user_input[CONF_TARIFFS])
59 except vol.Invalid
as exc:
65 OPTIONS_SCHEMA = vol.Schema(
67 vol.Required(CONF_SOURCE_SENSOR): selector.EntitySelector(
68 selector.EntitySelectorConfig(domain=SENSOR_DOMAIN),
71 CONF_METER_PERIODICALLY_RESETTING,
72 ): selector.BooleanSelector(),
74 CONF_SENSOR_ALWAYS_AVAILABLE,
76 ): selector.BooleanSelector(),
80 CONFIG_SCHEMA = vol.Schema(
82 vol.Required(CONF_NAME): selector.TextSelector(),
83 vol.Required(CONF_SOURCE_SENSOR): selector.EntitySelector(
84 selector.EntitySelectorConfig(domain=SENSOR_DOMAIN),
86 vol.Required(CONF_METER_TYPE): selector.SelectSelector(
87 selector.SelectSelectorConfig(
88 options=METER_TYPES, translation_key=CONF_METER_TYPE
91 vol.Required(CONF_METER_OFFSET, default=0): selector.NumberSelector(
92 selector.NumberSelectorConfig(
95 mode=selector.NumberSelectorMode.BOX,
96 unit_of_measurement=
"days",
99 vol.Required(CONF_TARIFFS, default=[]): selector.SelectSelector(
100 selector.SelectSelectorConfig(options=[], custom_value=
True, multiple=
True),
103 CONF_METER_NET_CONSUMPTION, default=
False
104 ): selector.BooleanSelector(),
106 CONF_METER_DELTA_VALUES, default=
False
107 ): selector.BooleanSelector(),
109 CONF_METER_PERIODICALLY_RESETTING,
111 ): selector.BooleanSelector(),
113 CONF_SENSOR_ALWAYS_AVAILABLE,
115 ): selector.BooleanSelector(),
129 """Handle a config or options flow for Utility Meter."""
133 config_flow = CONFIG_FLOW
134 options_flow = OPTIONS_FLOW
137 """Return config entry title."""
139 return cast(str, options[CONF_NAME])
str async_config_entry_title(self, Mapping[str, Any] options)
dict[str, Any] _validate_config(SchemaCommonFlowHandler handler, dict[str, Any] user_input)