mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
airzone: implement turn on/off (#70095)
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
This commit is contained in:
parent
8ab9cd1695
commit
abea7d3245
@ -26,7 +26,6 @@ from aioairzone.const import (
|
|||||||
AZD_ZONES,
|
AZD_ZONES,
|
||||||
)
|
)
|
||||||
from aioairzone.exceptions import AirzoneError
|
from aioairzone.exceptions import AirzoneError
|
||||||
from aiohttp.client_exceptions import ClientConnectorError
|
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
@ -128,13 +127,33 @@ class AirzoneClimate(AirzoneEntity, ClimateEntity):
|
|||||||
"""Send HVAC parameters to API."""
|
"""Send HVAC parameters to API."""
|
||||||
try:
|
try:
|
||||||
await self.coordinator.airzone.put_hvac(params)
|
await self.coordinator.airzone.put_hvac(params)
|
||||||
except (AirzoneError, ClientConnectorError) as error:
|
except AirzoneError as error:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
f"Failed to set zone {self.name}: {error}"
|
f"Failed to set zone {self.name}: {error}"
|
||||||
) from error
|
) from error
|
||||||
else:
|
else:
|
||||||
self.coordinator.async_set_updated_data(self.coordinator.airzone.data())
|
self.coordinator.async_set_updated_data(self.coordinator.airzone.data())
|
||||||
|
|
||||||
|
async def async_turn_on(self) -> None:
|
||||||
|
"""Turn the entity on."""
|
||||||
|
params = {
|
||||||
|
API_SYSTEM_ID: self.system_id,
|
||||||
|
API_ZONE_ID: self.zone_id,
|
||||||
|
API_ON: 1,
|
||||||
|
}
|
||||||
|
_LOGGER.debug("Turn off params=%s", params)
|
||||||
|
await self._async_update_hvac_params(params)
|
||||||
|
|
||||||
|
async def async_turn_off(self) -> None:
|
||||||
|
"""Turn the entity off."""
|
||||||
|
params = {
|
||||||
|
API_SYSTEM_ID: self.system_id,
|
||||||
|
API_ZONE_ID: self.zone_id,
|
||||||
|
API_ON: 0,
|
||||||
|
}
|
||||||
|
_LOGGER.debug("Turn off params=%s", params)
|
||||||
|
await self._async_update_hvac_params(params)
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||||
"""Set hvac mode."""
|
"""Set hvac mode."""
|
||||||
params = {
|
params = {
|
||||||
|
@ -36,7 +36,12 @@ from homeassistant.components.climate.const import (
|
|||||||
SERVICE_SET_HVAC_MODE,
|
SERVICE_SET_HVAC_MODE,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE
|
from homeassistant.const import (
|
||||||
|
ATTR_ENTITY_ID,
|
||||||
|
ATTR_TEMPERATURE,
|
||||||
|
SERVICE_TURN_OFF,
|
||||||
|
SERVICE_TURN_ON,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
|
||||||
@ -134,6 +139,62 @@ async def test_airzone_create_climates(hass: HomeAssistant) -> None:
|
|||||||
assert state.attributes.get(ATTR_TEMPERATURE) == 19.1
|
assert state.attributes.get(ATTR_TEMPERATURE) == 19.1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_airzone_climate_turn_on_off(hass: HomeAssistant) -> None:
|
||||||
|
"""Test turning on."""
|
||||||
|
|
||||||
|
await async_init_integration(hass)
|
||||||
|
|
||||||
|
HVAC_MOCK = {
|
||||||
|
API_DATA: [
|
||||||
|
{
|
||||||
|
API_SYSTEM_ID: 1,
|
||||||
|
API_ZONE_ID: 1,
|
||||||
|
API_ON: 1,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.airzone.AirzoneLocalApi.http_request",
|
||||||
|
return_value=HVAC_MOCK,
|
||||||
|
):
|
||||||
|
await hass.services.async_call(
|
||||||
|
CLIMATE_DOMAIN,
|
||||||
|
SERVICE_TURN_ON,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "climate.salon",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
state = hass.states.get("climate.salon")
|
||||||
|
assert state.state == HVAC_MODE_HEAT
|
||||||
|
|
||||||
|
HVAC_MOCK = {
|
||||||
|
API_DATA: [
|
||||||
|
{
|
||||||
|
API_SYSTEM_ID: 1,
|
||||||
|
API_ZONE_ID: 1,
|
||||||
|
API_ON: 0,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.airzone.AirzoneLocalApi.http_request",
|
||||||
|
return_value=HVAC_MOCK,
|
||||||
|
):
|
||||||
|
await hass.services.async_call(
|
||||||
|
CLIMATE_DOMAIN,
|
||||||
|
SERVICE_TURN_OFF,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "climate.salon",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
state = hass.states.get("climate.salon")
|
||||||
|
assert state.state == HVAC_MODE_OFF
|
||||||
|
|
||||||
|
|
||||||
async def test_airzone_climate_set_hvac_mode(hass: HomeAssistant) -> None:
|
async def test_airzone_climate_set_hvac_mode(hass: HomeAssistant) -> None:
|
||||||
"""Test setting the HVAC mode."""
|
"""Test setting the HVAC mode."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user