Use climate enums in homematicip_cloud (#70668)
parent
eeecdf213d
commit
4827fe5280
|
@ -9,18 +9,15 @@ from homematicip.base.enums import AbsenceType
|
|||
from homematicip.device import Switch
|
||||
from homematicip.functionalHomes import IndoorClimateHome
|
||||
|
||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
PRESET_AWAY,
|
||||
PRESET_BOOST,
|
||||
PRESET_ECO,
|
||||
PRESET_NONE,
|
||||
ClimateEntityFeature,
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
|
@ -112,31 +109,29 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
|
|||
return self._device.humidity
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> str:
|
||||
def hvac_mode(self) -> HVACMode:
|
||||
"""Return hvac operation ie."""
|
||||
if self._disabled_by_cooling_mode and not self._has_switch:
|
||||
return HVAC_MODE_OFF
|
||||
return HVACMode.OFF
|
||||
if self._device.boostMode:
|
||||
return HVAC_MODE_HEAT
|
||||
return HVACMode.HEAT
|
||||
if self._device.controlMode == HMIP_MANUAL_CM:
|
||||
return HVAC_MODE_HEAT if self._heat_mode_enabled else HVAC_MODE_COOL
|
||||
return HVACMode.HEAT if self._heat_mode_enabled else HVACMode.COOL
|
||||
|
||||
return HVAC_MODE_AUTO
|
||||
return HVACMode.AUTO
|
||||
|
||||
@property
|
||||
def hvac_modes(self) -> list[str]:
|
||||
def hvac_modes(self) -> list[HVACMode]:
|
||||
"""Return the list of available hvac operation modes."""
|
||||
if self._disabled_by_cooling_mode and not self._has_switch:
|
||||
return [HVAC_MODE_OFF]
|
||||
return [HVACMode.OFF]
|
||||
|
||||
return (
|
||||
[HVAC_MODE_AUTO, HVAC_MODE_HEAT]
|
||||
if self._heat_mode_enabled
|
||||
else [HVAC_MODE_AUTO, HVAC_MODE_COOL]
|
||||
)
|
||||
if self._heat_mode_enabled:
|
||||
return [HVACMode.AUTO, HVACMode.HEAT]
|
||||
return [HVACMode.AUTO, HVACMode.COOL]
|
||||
|
||||
@property
|
||||
def hvac_action(self) -> str | None:
|
||||
def hvac_action(self) -> HVACAction | None:
|
||||
"""
|
||||
Return the current hvac_action.
|
||||
|
||||
|
@ -147,9 +142,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
|
|||
and self._has_radiator_thermostat
|
||||
and self._heat_mode_enabled
|
||||
):
|
||||
return (
|
||||
CURRENT_HVAC_HEAT if self._device.valvePosition else CURRENT_HVAC_IDLE
|
||||
)
|
||||
return HVACAction.HEATING if self._device.valvePosition else HVACAction.IDLE
|
||||
|
||||
return None
|
||||
|
||||
|
@ -158,7 +151,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
|
|||
"""Return the current preset mode."""
|
||||
if self._device.boostMode:
|
||||
return PRESET_BOOST
|
||||
if self.hvac_mode in (HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF):
|
||||
if self.hvac_mode in (HVACMode.COOL, HVACMode.HEAT, HVACMode.OFF):
|
||||
return PRESET_NONE
|
||||
if self._device.controlMode == HMIP_ECO_CM:
|
||||
if self._indoor_climate.absenceType == AbsenceType.VACATION:
|
||||
|
@ -213,12 +206,12 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
|
|||
if self.min_temp <= temperature <= self.max_temp:
|
||||
await self._device.set_point_temperature(temperature)
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set new target hvac mode."""
|
||||
if hvac_mode not in self.hvac_modes:
|
||||
return
|
||||
|
||||
if hvac_mode == HVAC_MODE_AUTO:
|
||||
if hvac_mode == HVACMode.AUTO:
|
||||
await self._device.set_control_mode(HMIP_AUTOMATIC_CM)
|
||||
else:
|
||||
await self._device.set_control_mode(HMIP_MANUAL_CM)
|
||||
|
@ -235,7 +228,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
|
|||
if preset_mode in self._device_profile_names:
|
||||
profile_idx = self._get_profile_idx_by_name(preset_mode)
|
||||
if self._device.controlMode != HMIP_AUTOMATIC_CM:
|
||||
await self.async_set_hvac_mode(HVAC_MODE_AUTO)
|
||||
await self.async_set_hvac_mode(HVACMode.AUTO)
|
||||
await self._device.set_active_profile(profile_idx)
|
||||
|
||||
@property
|
||||
|
|
|
@ -10,16 +10,12 @@ from homeassistant.components.climate.const import (
|
|||
ATTR_HVAC_ACTION,
|
||||
ATTR_PRESET_MODE,
|
||||
ATTR_PRESET_MODES,
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
PRESET_AWAY,
|
||||
PRESET_BOOST,
|
||||
PRESET_ECO,
|
||||
PRESET_NONE,
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
|
||||
from homeassistant.components.homematicip_cloud.climate import (
|
||||
|
@ -53,7 +49,7 @@ async def test_hmip_heating_group_heat(hass, default_mock_hap_factory):
|
|||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
assert ha_state.attributes["current_temperature"] == 23.8
|
||||
assert ha_state.attributes["min_temp"] == 5.0
|
||||
assert ha_state.attributes["max_temp"] == 30.0
|
||||
|
@ -80,7 +76,7 @@ async def test_hmip_heating_group_heat(hass, default_mock_hap_factory):
|
|||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
{"entity_id": entity_id, "hvac_mode": HVAC_MODE_HEAT},
|
||||
{"entity_id": entity_id, "hvac_mode": HVACMode.HEAT},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 3
|
||||
|
@ -88,12 +84,12 @@ async def test_hmip_heating_group_heat(hass, default_mock_hap_factory):
|
|||
assert hmip_device.mock_calls[-1][1] == ("MANUAL",)
|
||||
await async_manipulate_test_data(hass, hmip_device, "controlMode", "MANUAL")
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == HVAC_MODE_HEAT
|
||||
assert ha_state.state == HVACMode.HEAT
|
||||
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
{"entity_id": entity_id, "hvac_mode": HVAC_MODE_AUTO},
|
||||
{"entity_id": entity_id, "hvac_mode": HVACMode.AUTO},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 5
|
||||
|
@ -101,7 +97,7 @@ async def test_hmip_heating_group_heat(hass, default_mock_hap_factory):
|
|||
assert hmip_device.mock_calls[-1][1] == ("AUTOMATIC",)
|
||||
await async_manipulate_test_data(hass, hmip_device, "controlMode", "AUTO")
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
|
@ -185,7 +181,7 @@ async def test_hmip_heating_group_heat(hass, default_mock_hap_factory):
|
|||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
{"entity_id": entity_id, "hvac_mode": HVAC_MODE_HEAT},
|
||||
{"entity_id": entity_id, "hvac_mode": HVACMode.HEAT},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 20
|
||||
|
@ -193,7 +189,7 @@ async def test_hmip_heating_group_heat(hass, default_mock_hap_factory):
|
|||
assert hmip_device.mock_calls[-1][1] == ("MANUAL",)
|
||||
await async_manipulate_test_data(hass, hmip_device, "controlMode", "MANUAL")
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == HVAC_MODE_HEAT
|
||||
assert ha_state.state == HVACMode.HEAT
|
||||
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
|
@ -208,7 +204,7 @@ async def test_hmip_heating_group_heat(hass, default_mock_hap_factory):
|
|||
hmip_device.activeProfile = hmip_device.profiles[0]
|
||||
await async_manipulate_test_data(hass, hmip_device, "controlMode", "AUTOMATIC")
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
|
@ -223,13 +219,13 @@ async def test_hmip_heating_group_heat(hass, default_mock_hap_factory):
|
|||
await async_manipulate_test_data(hass, hmip_device, "floorHeatingMode", "RADIATOR")
|
||||
await async_manipulate_test_data(hass, hmip_device, "valvePosition", 0.1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_HEAT
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
assert ha_state.attributes[ATTR_HVAC_ACTION] == HVACAction.HEATING
|
||||
await async_manipulate_test_data(hass, hmip_device, "floorHeatingMode", "RADIATOR")
|
||||
await async_manipulate_test_data(hass, hmip_device, "valvePosition", 0.0)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_IDLE
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
assert ha_state.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE
|
||||
|
||||
|
||||
async def test_hmip_heating_group_cool(hass, default_mock_hap_factory):
|
||||
|
@ -251,7 +247,7 @@ async def test_hmip_heating_group_cool(hass, default_mock_hap_factory):
|
|||
await async_manipulate_test_data(hass, hmip_device, "coolingIgnored", False)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
assert ha_state.attributes["current_temperature"] == 23.8
|
||||
assert ha_state.attributes["min_temp"] == 5.0
|
||||
assert ha_state.attributes["max_temp"] == 30.0
|
||||
|
@ -265,7 +261,7 @@ async def test_hmip_heating_group_cool(hass, default_mock_hap_factory):
|
|||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
{"entity_id": entity_id, "hvac_mode": HVAC_MODE_COOL},
|
||||
{"entity_id": entity_id, "hvac_mode": HVACMode.COOL},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 1
|
||||
|
@ -273,12 +269,12 @@ async def test_hmip_heating_group_cool(hass, default_mock_hap_factory):
|
|||
assert hmip_device.mock_calls[-1][1] == ("MANUAL",)
|
||||
await async_manipulate_test_data(hass, hmip_device, "controlMode", "MANUAL")
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == HVAC_MODE_COOL
|
||||
assert ha_state.state == HVACMode.COOL
|
||||
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
{"entity_id": entity_id, "hvac_mode": HVAC_MODE_AUTO},
|
||||
{"entity_id": entity_id, "hvac_mode": HVACMode.AUTO},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 3
|
||||
|
@ -286,7 +282,7 @@ async def test_hmip_heating_group_cool(hass, default_mock_hap_factory):
|
|||
assert hmip_device.mock_calls[-1][1] == ("AUTOMATIC",)
|
||||
await async_manipulate_test_data(hass, hmip_device, "controlMode", "AUTO")
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
|
@ -305,7 +301,7 @@ async def test_hmip_heating_group_cool(hass, default_mock_hap_factory):
|
|||
await async_manipulate_test_data(hass, hmip_device, "coolingIgnored", False)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
|
||||
assert ha_state.state == HVAC_MODE_OFF
|
||||
assert ha_state.state == HVACMode.OFF
|
||||
assert ha_state.attributes[ATTR_PRESET_MODE] == "none"
|
||||
assert ha_state.attributes[ATTR_PRESET_MODES] == []
|
||||
|
||||
|
@ -315,7 +311,7 @@ async def test_hmip_heating_group_cool(hass, default_mock_hap_factory):
|
|||
await async_manipulate_test_data(hass, hmip_device, "coolingIgnored", True)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
|
||||
assert ha_state.state == HVAC_MODE_OFF
|
||||
assert ha_state.state == HVACMode.OFF
|
||||
assert ha_state.attributes[ATTR_PRESET_MODE] == "none"
|
||||
assert ha_state.attributes[ATTR_PRESET_MODES] == []
|
||||
|
||||
|
@ -336,7 +332,7 @@ async def test_hmip_heating_group_cool(hass, default_mock_hap_factory):
|
|||
await async_manipulate_test_data(hass, hmip_device, "coolingIgnored", False)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
assert ha_state.attributes[ATTR_PRESET_MODE] == "Cool2"
|
||||
assert ha_state.attributes[ATTR_PRESET_MODES] == ["Cool1", "Cool2"]
|
||||
|
||||
|
@ -366,7 +362,7 @@ async def test_hmip_heating_group_heat_with_switch(hass, default_mock_hap_factor
|
|||
)
|
||||
|
||||
assert hmip_device
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
assert ha_state.attributes["current_temperature"] == 24.7
|
||||
assert ha_state.attributes["min_temp"] == 5.0
|
||||
assert ha_state.attributes["max_temp"] == 30.0
|
||||
|
@ -390,7 +386,7 @@ async def test_hmip_heating_group_heat_with_radiator(hass, default_mock_hap_fact
|
|||
)
|
||||
|
||||
assert hmip_device
|
||||
assert ha_state.state == HVAC_MODE_AUTO
|
||||
assert ha_state.state == HVACMode.AUTO
|
||||
assert ha_state.attributes["current_temperature"] == 20
|
||||
assert ha_state.attributes["min_temp"] == 5.0
|
||||
assert ha_state.attributes["max_temp"] == 30.0
|
||||
|
|
Loading…
Reference in New Issue