1 """Config flow for Integration - Riemann sum integral integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from typing
import Any, cast
8 import voluptuous
as vol
14 ATTR_UNIT_OF_MEASUREMENT,
22 SchemaCommonFlowHandler,
23 SchemaConfigFlowHandler,
25 SchemaOptionsFlowHandler,
29 CONF_MAX_SUB_INTERVAL,
41 selector.SelectOptionDict(value=
"k", label=
"k (kilo)"),
42 selector.SelectOptionDict(value=
"M", label=
"M (mega)"),
43 selector.SelectOptionDict(value=
"G", label=
"G (giga)"),
44 selector.SelectOptionDict(value=
"T", label=
"T (tera)"),
52 INTEGRATION_METHODS = [
57 ALLOWED_DOMAINS = [COUNTER_DOMAIN, INPUT_NUMBER_DOMAIN, SENSOR_DOMAIN]
62 handler: SchemaOptionsFlowHandler,
63 ) -> selector.EntitySelector:
64 """Return an entity selector which compatible entities."""
65 current = handler.hass.states.get(handler.options[CONF_SOURCE_SENSOR])
66 unit_of_measurement = (
67 current.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
if current
else None
72 for ent
in handler.hass.states.async_all(ALLOWED_DOMAINS)
73 if ent.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == unit_of_measurement
74 and ent.domain
in ALLOWED_DOMAINS
77 return selector.EntitySelector(
78 selector.EntitySelectorConfig(include_entities=entities)
83 if handler
is None or not isinstance(
84 handler.parent_handler, SchemaOptionsFlowHandler
86 entity_selector = selector.EntitySelector(
87 selector.EntitySelectorConfig(domain=ALLOWED_DOMAINS)
93 vol.Required(CONF_SOURCE_SENSOR): entity_selector,
94 vol.Required(CONF_METHOD, default=METHOD_TRAPEZOIDAL): selector.SelectSelector(
95 selector.SelectSelectorConfig(
96 options=INTEGRATION_METHODS, translation_key=CONF_METHOD
99 vol.Optional(CONF_ROUND_DIGITS): selector.NumberSelector(
100 selector.NumberSelectorConfig(
101 min=0, max=6, mode=selector.NumberSelectorMode.BOX
104 vol.Optional(CONF_MAX_SUB_INTERVAL): selector.DurationSelector(
105 selector.DurationSelectorConfig(allow_negative=
False)
118 vol.Required(CONF_NAME): selector.TextSelector(),
119 vol.Optional(CONF_UNIT_PREFIX): selector.SelectSelector(
120 selector.SelectSelectorConfig(
121 options=UNIT_PREFIXES, mode=selector.SelectSelectorMode.DROPDOWN
125 CONF_UNIT_TIME, default=UnitOfTime.HOURS
126 ): selector.SelectSelector(
127 selector.SelectSelectorConfig(
129 mode=selector.SelectSelectorMode.DROPDOWN,
130 translation_key=CONF_UNIT_TIME,
148 """Handle a config or options flow for Integration."""
150 config_flow = CONFIG_FLOW
151 options_flow = OPTIONS_FLOW
154 """Return config entry title."""
155 return cast(str, options[
"name"])
str async_config_entry_title(self, Mapping[str, Any] options)
vol.Schema _get_config_schema(SchemaCommonFlowHandler handler)
dict _get_options_dict(SchemaCommonFlowHandler|None handler)
selector.EntitySelector entity_selector_compatible(SchemaOptionsFlowHandler handler)
vol.Schema _get_options_schema(SchemaCommonFlowHandler handler)