diff --git a/homeassistant/components/generic_thermostat/__init__.py b/homeassistant/components/generic_thermostat/__init__.py index fcec36b8d35..dc43049a262 100644 --- a/homeassistant/components/generic_thermostat/__init__.py +++ b/homeassistant/components/generic_thermostat/__init__.py @@ -1,15 +1,12 @@ """The generic_thermostat component.""" from homeassistant.config_entries import ConfigEntry -from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers.device import ( async_remove_stale_devices_links_keep_entity_device, ) -CONF_HEATER = "heater" -DOMAIN = "generic_thermostat" -PLATFORMS = [Platform.CLIMATE] +from .const import CONF_HEATER, PLATFORMS async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/generic_thermostat/climate.py b/homeassistant/components/generic_thermostat/climate.py index 1b19def9cf4..22001b2acc4 100644 --- a/homeassistant/components/generic_thermostat/climate.py +++ b/homeassistant/components/generic_thermostat/climate.py @@ -14,13 +14,7 @@ import voluptuous as vol from homeassistant.components.climate import ( ATTR_PRESET_MODE, PLATFORM_SCHEMA as CLIMATE_PLATFORM_SCHEMA, - PRESET_ACTIVITY, - PRESET_AWAY, - PRESET_COMFORT, - PRESET_ECO, - PRESET_HOME, PRESET_NONE, - PRESET_SLEEP, ClimateEntity, ClimateEntityFeature, HVACAction, @@ -64,36 +58,31 @@ from homeassistant.helpers.reload import async_setup_reload_service from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, VolDictType -from . import CONF_HEATER, DOMAIN, PLATFORMS +from .const import ( + CONF_AC_MODE, + CONF_COLD_TOLERANCE, + CONF_HEATER, + CONF_HOT_TOLERANCE, + CONF_MIN_DUR, + CONF_PRESETS, + CONF_SENSOR, + DEFAULT_TOLERANCE, + DOMAIN, + PLATFORMS, +) _LOGGER = logging.getLogger(__name__) -DEFAULT_TOLERANCE = 0.3 DEFAULT_NAME = "Generic Thermostat" -CONF_SENSOR = "target_sensor" + +CONF_INITIAL_HVAC_MODE = "initial_hvac_mode" +CONF_KEEP_ALIVE = "keep_alive" CONF_MIN_TEMP = "min_temp" CONF_MAX_TEMP = "max_temp" -CONF_TARGET_TEMP = "target_temp" -CONF_AC_MODE = "ac_mode" -CONF_MIN_DUR = "min_cycle_duration" -CONF_COLD_TOLERANCE = "cold_tolerance" -CONF_HOT_TOLERANCE = "hot_tolerance" -CONF_KEEP_ALIVE = "keep_alive" -CONF_INITIAL_HVAC_MODE = "initial_hvac_mode" CONF_PRECISION = "precision" +CONF_TARGET_TEMP = "target_temp" CONF_TEMP_STEP = "target_temp_step" -CONF_PRESETS = { - p: f"{p}_temp" - for p in ( - PRESET_AWAY, - PRESET_COMFORT, - PRESET_ECO, - PRESET_HOME, - PRESET_SLEEP, - PRESET_ACTIVITY, - ) -} PRESETS_SCHEMA: VolDictType = { vol.Optional(v): vol.Coerce(float) for v in CONF_PRESETS.values() diff --git a/homeassistant/components/generic_thermostat/config_flow.py b/homeassistant/components/generic_thermostat/config_flow.py index 29e3d69c2da..e9079a9f41a 100644 --- a/homeassistant/components/generic_thermostat/config_flow.py +++ b/homeassistant/components/generic_thermostat/config_flow.py @@ -16,7 +16,7 @@ from homeassistant.helpers.schema_config_entry_flow import ( SchemaFlowFormStep, ) -from .climate import ( +from .const import ( CONF_AC_MODE, CONF_COLD_TOLERANCE, CONF_HEATER, diff --git a/homeassistant/components/generic_thermostat/const.py b/homeassistant/components/generic_thermostat/const.py new file mode 100644 index 00000000000..51927297b63 --- /dev/null +++ b/homeassistant/components/generic_thermostat/const.py @@ -0,0 +1,34 @@ +"""Constants for the Generic Thermostat helper.""" + +from homeassistant.components.climate import ( + PRESET_ACTIVITY, + PRESET_AWAY, + PRESET_COMFORT, + PRESET_ECO, + PRESET_HOME, + PRESET_SLEEP, +) +from homeassistant.const import Platform + +DOMAIN = "generic_thermostat" + +PLATFORMS = [Platform.CLIMATE] + +CONF_AC_MODE = "ac_mode" +CONF_COLD_TOLERANCE = "cold_tolerance" +CONF_HEATER = "heater" +CONF_HOT_TOLERANCE = "hot_tolerance" +CONF_MIN_DUR = "min_cycle_duration" +CONF_PRESETS = { + p: f"{p}_temp" + for p in ( + PRESET_AWAY, + PRESET_COMFORT, + PRESET_ECO, + PRESET_HOME, + PRESET_SLEEP, + PRESET_ACTIVITY, + ) +} +CONF_SENSOR = "target_sensor" +DEFAULT_TOLERANCE = 0.3 diff --git a/tests/components/generic_thermostat/test_climate.py b/tests/components/generic_thermostat/test_climate.py index 3ea38a22c3c..dcf1cd695e2 100644 --- a/tests/components/generic_thermostat/test_climate.py +++ b/tests/components/generic_thermostat/test_climate.py @@ -21,7 +21,7 @@ from homeassistant.components.climate import ( PRESET_SLEEP, HVACMode, ) -from homeassistant.components.generic_thermostat import ( +from homeassistant.components.generic_thermostat.const import ( DOMAIN as GENERIC_THERMOSTAT_DOMAIN, ) from homeassistant.const import ( diff --git a/tests/components/generic_thermostat/test_config_flow.py b/tests/components/generic_thermostat/test_config_flow.py index 81e06146a14..7a7fdabc6e6 100644 --- a/tests/components/generic_thermostat/test_config_flow.py +++ b/tests/components/generic_thermostat/test_config_flow.py @@ -6,12 +6,11 @@ from syrupy.assertion import SnapshotAssertion from syrupy.filters import props from homeassistant.components.climate import PRESET_AWAY -from homeassistant.components.generic_thermostat.climate import ( +from homeassistant.components.generic_thermostat.const import ( CONF_AC_MODE, CONF_COLD_TOLERANCE, CONF_HEATER, CONF_HOT_TOLERANCE, - CONF_NAME, CONF_PRESETS, CONF_SENSOR, DOMAIN, @@ -21,6 +20,7 @@ from homeassistant.config_entries import SOURCE_USER from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_UNIT_OF_MEASUREMENT, + CONF_NAME, STATE_OFF, UnitOfTemperature, ) diff --git a/tests/components/generic_thermostat/test_init.py b/tests/components/generic_thermostat/test_init.py index 0d6e106237c..addae2f684e 100644 --- a/tests/components/generic_thermostat/test_init.py +++ b/tests/components/generic_thermostat/test_init.py @@ -2,7 +2,7 @@ from __future__ import annotations -from homeassistant.components.generic_thermostat import DOMAIN +from homeassistant.components.generic_thermostat.const import DOMAIN from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er