Files
core/homeassistant/components/generic_hygrostat/config_flow.py
T

94 lines
2.5 KiB
Python

"""Config flow for Generic hygrostat."""
from collections.abc import Mapping
from typing import Any, cast, override
import voluptuous as vol
from homeassistant.components import fan, switch
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME, PERCENTAGE, Platform
from homeassistant.helpers import selector
from homeassistant.helpers.schema_config_entry_flow import (
SchemaConfigFlowHandler,
SchemaFlowFormStep,
)
from . import (
CONF_DRY_TOLERANCE,
CONF_HUMIDIFIER,
CONF_MIN_DUR,
CONF_SENSOR,
CONF_WET_TOLERANCE,
DEFAULT_TOLERANCE,
DOMAIN,
)
OPTIONS_SCHEMA = {
vol.Required(CONF_DEVICE_CLASS): selector.DeviceClassSelector(
selector.DeviceClassSelectorConfig(domain=Platform.HUMIDIFIER)
),
vol.Required(CONF_SENSOR): selector.EntitySelector(
selector.EntitySelectorConfig(
domain=SENSOR_DOMAIN, device_class=SensorDeviceClass.HUMIDITY
)
),
vol.Required(CONF_HUMIDIFIER): selector.EntitySelector(
selector.EntitySelectorConfig(domain=[switch.DOMAIN, fan.DOMAIN])
),
vol.Required(
CONF_DRY_TOLERANCE, default=DEFAULT_TOLERANCE
): selector.NumberSelector(
selector.NumberSelectorConfig(
min=0,
max=100,
step=0.5,
unit_of_measurement=PERCENTAGE,
mode=selector.NumberSelectorMode.BOX,
)
),
vol.Required(
CONF_WET_TOLERANCE, default=DEFAULT_TOLERANCE
): selector.NumberSelector(
selector.NumberSelectorConfig(
min=0,
max=100,
step=0.5,
unit_of_measurement=PERCENTAGE,
mode=selector.NumberSelectorMode.BOX,
)
),
vol.Optional(CONF_MIN_DUR): selector.DurationSelector(
selector.DurationSelectorConfig(allow_negative=False)
),
}
CONFIG_SCHEMA = {
vol.Required(CONF_NAME): selector.TextSelector(),
**OPTIONS_SCHEMA,
}
CONFIG_FLOW = {
"user": SchemaFlowFormStep(vol.Schema(CONFIG_SCHEMA)),
}
OPTIONS_FLOW = {
"init": SchemaFlowFormStep(vol.Schema(OPTIONS_SCHEMA)),
}
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
"""Handle a config or options flow."""
MINOR_VERSION = 2
config_flow = CONFIG_FLOW
options_flow = OPTIONS_FLOW
options_flow_reloads = True
@override
def async_config_entry_title(self, options: Mapping[str, Any]) -> str:
"""Return config entry title."""
return cast(str, options["name"])