1 """Config flow to configure Coolmaster."""
3 from __future__
import annotations
7 from pycoolmasternet_async
import CoolMasterNet
8 import voluptuous
as vol
15 from .const
import CONF_SUPPORTED_MODES, CONF_SWING_SUPPORT, DEFAULT_PORT, DOMAIN
22 HVACMode.HEAT_COOL.value,
23 HVACMode.FAN_ONLY.value,
26 MODES_SCHEMA = {vol.Required(mode, default=
True): bool
for mode
in AVAILABLE_MODES}
28 DATA_SCHEMA = vol.Schema(
30 vol.Required(CONF_HOST): str,
32 vol.Required(CONF_SWING_SUPPORT, default=
False): bool,
38 cool = CoolMasterNet(host, DEFAULT_PORT)
39 units = await cool.status()
44 """Handle a Coolmaster config flow."""
51 key
for (key, value)
in data.items()
if key
in AVAILABLE_MODES
and value
54 title=data[CONF_HOST],
56 CONF_HOST: data[CONF_HOST],
57 CONF_PORT: DEFAULT_PORT,
58 CONF_SUPPORTED_MODES: supported_modes,
59 CONF_SWING_SUPPORT: data[CONF_SWING_SUPPORT],
64 self, user_input: dict[str, Any] |
None =
None
65 ) -> ConfigFlowResult:
66 """Handle a flow initialized by the user."""
67 if user_input
is None:
72 host = user_input[CONF_HOST]
77 errors[
"base"] =
"no_units"
79 errors[
"base"] =
"cannot_connect"
83 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult _async_get_entry(self, dict[str, Any] data)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
bool _validate_connection(str host)