Add SelectorType enum and TypedDicts for each selector's data (#68399)
* 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>
This commit is contained in:
parent
e996142592
commit
b325c112b4
16 changed files with 525 additions and 239 deletions
|
@ -9,7 +9,6 @@ import voluptuous as vol
|
|||
from homeassistant.const import (
|
||||
CONF_NAME,
|
||||
CONF_SOURCE,
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
TIME_DAYS,
|
||||
TIME_HOURS,
|
||||
TIME_MINUTES,
|
||||
|
@ -31,50 +30,48 @@ from .const import (
|
|||
)
|
||||
|
||||
UNIT_PREFIXES = [
|
||||
{"value": "none", "label": "none"},
|
||||
{"value": "n", "label": "n (nano)"},
|
||||
{"value": "µ", "label": "µ (micro)"},
|
||||
{"value": "m", "label": "m (milli)"},
|
||||
{"value": "k", "label": "k (kilo)"},
|
||||
{"value": "M", "label": "M (mega)"},
|
||||
{"value": "G", "label": "G (giga)"},
|
||||
{"value": "T", "label": "T (tera)"},
|
||||
{"value": "P", "label": "P (peta)"},
|
||||
selector.SelectOptionDict(value="none", label="none"),
|
||||
selector.SelectOptionDict(value="n", label="n (nano)"),
|
||||
selector.SelectOptionDict(value="µ", label="µ (micro)"),
|
||||
selector.SelectOptionDict(value="m", label="m (milli)"),
|
||||
selector.SelectOptionDict(value="k", label="k (kilo)"),
|
||||
selector.SelectOptionDict(value="M", label="M (mega)"),
|
||||
selector.SelectOptionDict(value="G", label="G (giga)"),
|
||||
selector.SelectOptionDict(value="T", label="T (tera)"),
|
||||
selector.SelectOptionDict(value="P", label="P (peta)"),
|
||||
]
|
||||
TIME_UNITS = [
|
||||
{"value": TIME_SECONDS, "label": "Seconds"},
|
||||
{"value": TIME_MINUTES, "label": "Minutes"},
|
||||
{"value": TIME_HOURS, "label": "Hours"},
|
||||
{"value": TIME_DAYS, "label": "Days"},
|
||||
selector.SelectOptionDict(value=TIME_SECONDS, label="Seconds"),
|
||||
selector.SelectOptionDict(value=TIME_MINUTES, label="Minutes"),
|
||||
selector.SelectOptionDict(value=TIME_HOURS, label="Hours"),
|
||||
selector.SelectOptionDict(value=TIME_DAYS, label="Days"),
|
||||
]
|
||||
|
||||
OPTIONS_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_ROUND_DIGITS, default=2): selector.selector(
|
||||
{
|
||||
"number": {
|
||||
"min": 0,
|
||||
"max": 6,
|
||||
"mode": "box",
|
||||
CONF_UNIT_OF_MEASUREMENT: "decimals",
|
||||
}
|
||||
}
|
||||
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.selector({"duration": {}}),
|
||||
vol.Required(CONF_UNIT_PREFIX, default="none"): selector.selector(
|
||||
{"select": {"options": UNIT_PREFIXES}}
|
||||
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.selector(
|
||||
{"select": {"options": TIME_UNITS}}
|
||||
vol.Required(CONF_UNIT_TIME, default=TIME_HOURS): selector.SelectSelector(
|
||||
selector.SelectSelectorConfig(options=TIME_UNITS),
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_NAME): selector.selector({"text": {}}),
|
||||
vol.Required(CONF_SOURCE): selector.selector(
|
||||
{"entity": {"domain": "sensor"}},
|
||||
vol.Required(CONF_NAME): selector.TextSelector(),
|
||||
vol.Required(CONF_SOURCE): selector.EntitySelector(
|
||||
selector.EntitySelectorConfig(domain="sensor"),
|
||||
),
|
||||
}
|
||||
).extend(OPTIONS_SCHEMA.schema)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue