mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Adjust climate constants in coolmaster config flow (#70764)
This commit is contained in:
parent
403992dfa5
commit
bd87ae79ae
@ -1,31 +1,46 @@
|
|||||||
"""Config flow to configure Coolmaster."""
|
"""Config flow to configure Coolmaster."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from pycoolmasternet_async import CoolMasterNet
|
from pycoolmasternet_async import CoolMasterNet
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries, core
|
from homeassistant.components.climate.const import HVACMode
|
||||||
|
from homeassistant.config_entries import ConfigFlow
|
||||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||||
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import AVAILABLE_MODES, CONF_SUPPORTED_MODES, DEFAULT_PORT, DOMAIN
|
from .const import CONF_SUPPORTED_MODES, DEFAULT_PORT, DOMAIN
|
||||||
|
|
||||||
|
AVAILABLE_MODES = [
|
||||||
|
HVACMode.OFF.value,
|
||||||
|
HVACMode.HEAT.value,
|
||||||
|
HVACMode.COOL.value,
|
||||||
|
HVACMode.DRY.value,
|
||||||
|
HVACMode.HEAT_COOL.value,
|
||||||
|
HVACMode.FAN_ONLY.value,
|
||||||
|
]
|
||||||
|
|
||||||
MODES_SCHEMA = {vol.Required(mode, default=True): bool for mode in AVAILABLE_MODES}
|
MODES_SCHEMA = {vol.Required(mode, default=True): bool for mode in AVAILABLE_MODES}
|
||||||
|
|
||||||
DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str, **MODES_SCHEMA})
|
DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str, **MODES_SCHEMA})
|
||||||
|
|
||||||
|
|
||||||
async def _validate_connection(hass: core.HomeAssistant, host):
|
async def _validate_connection(host: str) -> bool:
|
||||||
cool = CoolMasterNet(host, DEFAULT_PORT)
|
cool = CoolMasterNet(host, DEFAULT_PORT)
|
||||||
units = await cool.status()
|
units = await cool.status()
|
||||||
return bool(units)
|
return bool(units)
|
||||||
|
|
||||||
|
|
||||||
class CoolmasterConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class CoolmasterConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a Coolmaster config flow."""
|
"""Handle a Coolmaster config flow."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
@core.callback
|
@callback
|
||||||
def _async_get_entry(self, data):
|
def _async_get_entry(self, data: dict[str, Any]) -> FlowResult:
|
||||||
supported_modes = [
|
supported_modes = [
|
||||||
key for (key, value) in data.items() if key in AVAILABLE_MODES and value
|
key for (key, value) in data.items() if key in AVAILABLE_MODES and value
|
||||||
]
|
]
|
||||||
@ -38,7 +53,9 @@ class CoolmasterConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA)
|
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA)
|
||||||
@ -48,7 +65,7 @@ class CoolmasterConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
host = user_input[CONF_HOST]
|
host = user_input[CONF_HOST]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = await _validate_connection(self.hass, host)
|
result = await _validate_connection(host)
|
||||||
if not result:
|
if not result:
|
||||||
errors["base"] = "no_units"
|
errors["base"] = "no_units"
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
"""Constants for the Coolmaster integration."""
|
"""Constants for the Coolmaster integration."""
|
||||||
|
|
||||||
from homeassistant.components.climate.const import (
|
|
||||||
HVAC_MODE_COOL,
|
|
||||||
HVAC_MODE_DRY,
|
|
||||||
HVAC_MODE_FAN_ONLY,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_HEAT_COOL,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
)
|
|
||||||
|
|
||||||
DATA_INFO = "info"
|
DATA_INFO = "info"
|
||||||
DATA_COORDINATOR = "coordinator"
|
DATA_COORDINATOR = "coordinator"
|
||||||
|
|
||||||
@ -17,12 +8,3 @@ DOMAIN = "coolmaster"
|
|||||||
DEFAULT_PORT = 10102
|
DEFAULT_PORT = 10102
|
||||||
|
|
||||||
CONF_SUPPORTED_MODES = "supported_modes"
|
CONF_SUPPORTED_MODES = "supported_modes"
|
||||||
|
|
||||||
AVAILABLE_MODES = [
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_COOL,
|
|
||||||
HVAC_MODE_DRY,
|
|
||||||
HVAC_MODE_HEAT_COOL,
|
|
||||||
HVAC_MODE_FAN_ONLY,
|
|
||||||
]
|
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.coolmaster.const import AVAILABLE_MODES, DOMAIN
|
from homeassistant.components.coolmaster.config_flow import AVAILABLE_MODES
|
||||||
|
from homeassistant.components.coolmaster.const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
def _flow_data():
|
def _flow_data():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user