mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
![Raman Gupta](/assets/img/avatar_default.png)
* rebase off current * rearrange * Overload selector function * Update/fix all selector references * better typing? * remove extra option * move things around * Switch to Sequence type to avoid ignoring mypy error * Get rid of ...'s * Improve typing to reduce number of ignores * Remove all typing ignores * Make config optional for selectors that don't need a config * add missing unit prefixes * Rename TypedDicts * Update homeassistant/helpers/selector.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * review feedback * remove peta from integration integration * Fix min_max * Revert change to selector function * Fix logic * Add typing for selector classes * Update selector.py * Fix indent Co-authored-by: Erik Montnemery <erik@montnemery.com>
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
"""Config flow for Min/Max integration."""
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any, cast
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.const import CONF_TYPE
|
|
from homeassistant.helpers import selector
|
|
from homeassistant.helpers.schema_config_entry_flow import (
|
|
SchemaConfigFlowHandler,
|
|
SchemaFlowFormStep,
|
|
SchemaFlowMenuStep,
|
|
)
|
|
|
|
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] = {
|
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
|
}
|
|
|
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
|
}
|
|
|
|
|
|
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
|
"""Handle a config or options flow for Min/Max."""
|
|
|
|
config_flow = CONFIG_FLOW
|
|
options_flow = OPTIONS_FLOW
|
|
|
|
def async_config_entry_title(self, options: Mapping[str, Any]) -> str:
|
|
"""Return config entry title."""
|
|
return cast(str, options["name"]) if "name" in options else ""
|