mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Support hvac mode in melcloud climate.set_temperature service (#56082)
Setting the HVAC_MODE via the set_temperature service has not been possible before this change.
This commit is contained in:
parent
5ccc3c17d9
commit
ee616ed992
@ -16,6 +16,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
|
ATTR_HVAC_MODE,
|
||||||
DEFAULT_MAX_TEMP,
|
DEFAULT_MAX_TEMP,
|
||||||
DEFAULT_MIN_TEMP,
|
DEFAULT_MIN_TEMP,
|
||||||
HVAC_MODE_COOL,
|
HVAC_MODE_COOL,
|
||||||
@ -29,7 +30,7 @@ from homeassistant.components.climate.const import (
|
|||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import TEMP_CELSIUS
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
|
|
||||||
@ -169,20 +170,25 @@ class AtaDeviceClimate(MelCloudClimate):
|
|||||||
return HVAC_MODE_OFF
|
return HVAC_MODE_OFF
|
||||||
return ATA_HVAC_MODE_LOOKUP.get(mode)
|
return ATA_HVAC_MODE_LOOKUP.get(mode)
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
def _apply_set_hvac_mode(self, hvac_mode: str, set_dict: dict[str, Any]) -> None:
|
||||||
"""Set new target hvac mode."""
|
"""Apply hvac mode changes to a dict used to call _device.set."""
|
||||||
if hvac_mode == HVAC_MODE_OFF:
|
if hvac_mode == HVAC_MODE_OFF:
|
||||||
await self._device.set({"power": False})
|
set_dict["power"] = False
|
||||||
return
|
return
|
||||||
|
|
||||||
operation_mode = ATA_HVAC_MODE_REVERSE_LOOKUP.get(hvac_mode)
|
operation_mode = ATA_HVAC_MODE_REVERSE_LOOKUP.get(hvac_mode)
|
||||||
if operation_mode is None:
|
if operation_mode is None:
|
||||||
raise ValueError(f"Invalid hvac_mode [{hvac_mode}]")
|
raise ValueError(f"Invalid hvac_mode [{hvac_mode}]")
|
||||||
|
|
||||||
props = {"operation_mode": operation_mode}
|
set_dict["operation_mode"] = operation_mode
|
||||||
if self.hvac_mode == HVAC_MODE_OFF:
|
if self.hvac_mode == HVAC_MODE_OFF:
|
||||||
props["power"] = True
|
set_dict["power"] = True
|
||||||
await self._device.set(props)
|
|
||||||
|
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||||
|
"""Set new target hvac mode."""
|
||||||
|
set_dict = {}
|
||||||
|
self._apply_set_hvac_mode(hvac_mode, set_dict)
|
||||||
|
await self._device.set(set_dict)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_modes(self) -> list[str]:
|
def hvac_modes(self) -> list[str]:
|
||||||
@ -203,9 +209,17 @@ class AtaDeviceClimate(MelCloudClimate):
|
|||||||
|
|
||||||
async def async_set_temperature(self, **kwargs) -> None:
|
async def async_set_temperature(self, **kwargs) -> None:
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
await self._device.set(
|
set_dict = {}
|
||||||
{"target_temperature": kwargs.get("temperature", self.target_temperature)}
|
if ATTR_HVAC_MODE in kwargs:
|
||||||
)
|
self._apply_set_hvac_mode(
|
||||||
|
kwargs.get(ATTR_HVAC_MODE, self.hvac_mode), set_dict
|
||||||
|
)
|
||||||
|
|
||||||
|
if ATTR_TEMPERATURE in kwargs:
|
||||||
|
set_dict["target_temperature"] = kwargs.get(ATTR_TEMPERATURE)
|
||||||
|
|
||||||
|
if set_dict:
|
||||||
|
await self._device.set(set_dict)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_mode(self) -> str | None:
|
def fan_mode(self) -> str | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user