Raise HomeAssistantError/ValueError for service calls in Honeywell (#100041)

This commit is contained in:
mkmer 2023-09-10 09:58:59 -04:00 committed by GitHub
parent d56ad14673
commit 59e87c0864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 310 additions and 216 deletions

View File

@ -27,6 +27,7 @@ from homeassistant.components.climate import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -315,6 +316,9 @@ class HoneywellUSThermostat(ClimateEntity):
except SomeComfortError as err: except SomeComfortError as err:
_LOGGER.error("Invalid temperature %.1f: %s", temperature, err) _LOGGER.error("Invalid temperature %.1f: %s", temperature, err)
raise ValueError(
f"Honeywell set temperature failed: invalid temperature {temperature}."
) from err
async def async_set_temperature(self, **kwargs: Any) -> None: async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
@ -328,14 +332,23 @@ class HoneywellUSThermostat(ClimateEntity):
except SomeComfortError as err: except SomeComfortError as err:
_LOGGER.error("Invalid temperature %.1f: %s", temperature, err) _LOGGER.error("Invalid temperature %.1f: %s", temperature, err)
raise ValueError(
f"Honeywell set temperature failed: invalid temperature: {temperature}."
) from err
async def async_set_fan_mode(self, fan_mode: str) -> None: async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode.""" """Set new target fan mode."""
await self._device.set_fan_mode(self._fan_mode_map[fan_mode]) try:
await self._device.set_fan_mode(self._fan_mode_map[fan_mode])
except SomeComfortError as err:
raise HomeAssistantError("Honeywell could not set fan mode.") from err
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode.""" """Set new target hvac mode."""
await self._device.set_system_mode(self._hvac_mode_map[hvac_mode]) try:
await self._device.set_system_mode(self._hvac_mode_map[hvac_mode])
except SomeComfortError as err:
raise HomeAssistantError("Honeywell could not set system mode.") from err
async def _turn_away_mode_on(self) -> None: async def _turn_away_mode_on(self) -> None:
"""Turn away on. """Turn away on.
@ -355,13 +368,16 @@ class HoneywellUSThermostat(ClimateEntity):
if mode in HEATING_MODES: if mode in HEATING_MODES:
await self._device.set_hold_heat(True, self._heat_away_temp) await self._device.set_hold_heat(True, self._heat_away_temp)
except SomeComfortError: except SomeComfortError as err:
_LOGGER.error( _LOGGER.error(
"Temperature out of range. Mode: %s, Heat Temperature: %.1f, Cool Temperature: %.1f", "Temperature out of range. Mode: %s, Heat Temperature: %.1f, Cool Temperature: %.1f",
mode, mode,
self._heat_away_temp, self._heat_away_temp,
self._cool_away_temp, self._cool_away_temp,
) )
raise ValueError(
f"Honeywell set temperature failed: temperature out of range. Mode: {mode}, Heat Temperuature: {self._heat_away_temp}, Cool Temperature: {self._cool_away_temp}."
) from err
async def _turn_hold_mode_on(self) -> None: async def _turn_hold_mode_on(self) -> None:
"""Turn permanent hold on.""" """Turn permanent hold on."""
@ -376,10 +392,14 @@ class HoneywellUSThermostat(ClimateEntity):
if mode in HEATING_MODES: if mode in HEATING_MODES:
await self._device.set_hold_heat(True) await self._device.set_hold_heat(True)
except SomeComfortError: except SomeComfortError as err:
_LOGGER.error("Couldn't set permanent hold") _LOGGER.error("Couldn't set permanent hold")
raise HomeAssistantError(
"Honeywell couldn't set permanent hold."
) from err
else: else:
_LOGGER.error("Invalid system mode returned: %s", mode) _LOGGER.error("Invalid system mode returned: %s", mode)
raise HomeAssistantError(f"Honeywell invalid system mode returned {mode}.")
async def _turn_away_mode_off(self) -> None: async def _turn_away_mode_off(self) -> None:
"""Turn away/hold off.""" """Turn away/hold off."""
@ -388,8 +408,9 @@ class HoneywellUSThermostat(ClimateEntity):
# Disabling all hold modes # Disabling all hold modes
await self._device.set_hold_cool(False) await self._device.set_hold_cool(False)
await self._device.set_hold_heat(False) await self._device.set_hold_heat(False)
except SomeComfortError: except SomeComfortError as err:
_LOGGER.error("Can not stop hold mode") _LOGGER.error("Can not stop hold mode")
raise HomeAssistantError("Honeywell could not stop hold mode") from err
async def async_set_preset_mode(self, preset_mode: str) -> None: async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode.""" """Set new preset mode."""
@ -403,14 +424,22 @@ class HoneywellUSThermostat(ClimateEntity):
async def async_turn_aux_heat_on(self) -> None: async def async_turn_aux_heat_on(self) -> None:
"""Turn auxiliary heater on.""" """Turn auxiliary heater on."""
await self._device.set_system_mode("emheat") try:
await self._device.set_system_mode("emheat")
except SomeComfortError as err:
raise HomeAssistantError(
"Honeywell could not set system mode to aux heat."
) from err
async def async_turn_aux_heat_off(self) -> None: async def async_turn_aux_heat_off(self) -> None:
"""Turn auxiliary heater off.""" """Turn auxiliary heater off."""
if HVACMode.HEAT in self.hvac_modes: try:
await self.async_set_hvac_mode(HVACMode.HEAT) if HVACMode.HEAT in self.hvac_modes:
else: await self.async_set_hvac_mode(HVACMode.HEAT)
await self.async_set_hvac_mode(HVACMode.OFF) else:
await self.async_set_hvac_mode(HVACMode.OFF)
except HomeAssistantError as err:
raise HomeAssistantError("Honeywell could turn off aux heat mode.") from err
async def async_update(self) -> None: async def async_update(self) -> None:
"""Get the latest state from the service.""" """Get the latest state from the service."""

View File

@ -37,6 +37,7 @@ from homeassistant.const import (
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
@ -193,6 +194,15 @@ async def test_mode_service_calls(
device.set_system_mode.assert_called_once_with("auto") device.set_system_mode.assert_called_once_with("auto")
device.set_system_mode.reset_mock() device.set_system_mode.reset_mock()
device.set_system_mode.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_HVAC_MODE: HVACMode.HEAT_COOL},
blocking=True,
)
device.set_system_mode.assert_called_once_with("auto")
async def test_auxheat_service_calls( async def test_auxheat_service_calls(
@ -211,6 +221,7 @@ async def test_auxheat_service_calls(
device.set_system_mode.assert_called_once_with("emheat") device.set_system_mode.assert_called_once_with("emheat")
device.set_system_mode.reset_mock() device.set_system_mode.reset_mock()
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_AUX_HEAT, SERVICE_SET_AUX_HEAT,
@ -219,6 +230,27 @@ async def test_auxheat_service_calls(
) )
device.set_system_mode.assert_called_once_with("heat") device.set_system_mode.assert_called_once_with("heat")
device.set_system_mode.reset_mock()
device.set_system_mode.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_AUX_HEAT,
{ATTR_ENTITY_ID: entity_id, ATTR_AUX_HEAT: True},
blocking=True,
)
device.set_system_mode.assert_called_once_with("emheat")
device.set_system_mode.reset_mock()
device.set_system_mode.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_AUX_HEAT,
{ATTR_ENTITY_ID: entity_id, ATTR_AUX_HEAT: False},
blocking=True,
)
async def test_fan_modes_service_calls( async def test_fan_modes_service_calls(
hass: HomeAssistant, device: MagicMock, config_entry: MagicMock hass: HomeAssistant, device: MagicMock, config_entry: MagicMock
@ -256,6 +288,17 @@ async def test_fan_modes_service_calls(
device.set_fan_mode.assert_called_once_with("circulate") device.set_fan_mode.assert_called_once_with("circulate")
device.set_fan_mode.reset_mock()
device.set_fan_mode.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_FAN_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_FAN_MODE: FAN_DIFFUSE},
blocking=True,
)
async def test_service_calls_off_mode( async def test_service_calls_off_mode(
hass: HomeAssistant, hass: HomeAssistant,
@ -299,16 +342,18 @@ async def test_service_calls_off_mode(
device.set_setpoint_heat.reset_mock() device.set_setpoint_heat.reset_mock()
device.set_setpoint_heat.side_effect = aiosomecomfort.SomeComfortError device.set_setpoint_heat.side_effect = aiosomecomfort.SomeComfortError
caplog.clear() caplog.clear()
await hass.services.async_call(
CLIMATE_DOMAIN, with pytest.raises(ValueError):
SERVICE_SET_TEMPERATURE, await hass.services.async_call(
{ CLIMATE_DOMAIN,
ATTR_ENTITY_ID: entity_id, SERVICE_SET_TEMPERATURE,
ATTR_TARGET_TEMP_LOW: 25.0, {
ATTR_TARGET_TEMP_HIGH: 35.0, ATTR_ENTITY_ID: entity_id,
}, ATTR_TARGET_TEMP_LOW: 25.0,
blocking=True, ATTR_TARGET_TEMP_HIGH: 35.0,
) },
blocking=True,
)
device.set_setpoint_cool.assert_called_with(95) device.set_setpoint_cool.assert_called_with(95)
device.set_setpoint_heat.assert_called_with(77) device.set_setpoint_heat.assert_called_with(77)
assert "Invalid temperature" in caplog.text assert "Invalid temperature" in caplog.text
@ -387,7 +432,6 @@ async def test_service_calls_off_mode(
device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
@ -443,16 +487,18 @@ async def test_service_calls_cool_mode(
caplog.clear() caplog.clear()
device.set_setpoint_cool.reset_mock() device.set_setpoint_cool.reset_mock()
device.set_setpoint_cool.side_effect = aiosomecomfort.SomeComfortError device.set_setpoint_cool.side_effect = aiosomecomfort.SomeComfortError
await hass.services.async_call(
CLIMATE_DOMAIN, with pytest.raises(ValueError):
SERVICE_SET_TEMPERATURE, await hass.services.async_call(
{ CLIMATE_DOMAIN,
ATTR_ENTITY_ID: entity_id, SERVICE_SET_TEMPERATURE,
ATTR_TARGET_TEMP_LOW: 25.0, {
ATTR_TARGET_TEMP_HIGH: 35.0, ATTR_ENTITY_ID: entity_id,
}, ATTR_TARGET_TEMP_LOW: 25.0,
blocking=True, ATTR_TARGET_TEMP_HIGH: 35.0,
) },
blocking=True,
)
device.set_setpoint_cool.assert_called_with(95) device.set_setpoint_cool.assert_called_with(95)
device.set_setpoint_heat.assert_called_with(77) device.set_setpoint_heat.assert_called_with(77)
assert "Invalid temperature" in caplog.text assert "Invalid temperature" in caplog.text
@ -474,12 +520,13 @@ async def test_service_calls_cool_mode(
device.set_hold_cool.side_effect = aiosomecomfort.SomeComfortError device.set_hold_cool.side_effect = aiosomecomfort.SomeComfortError
caplog.clear() caplog.clear()
await hass.services.async_call( with pytest.raises(ValueError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY},
) blocking=True,
)
device.set_hold_cool.assert_called_once_with(True, 12) device.set_hold_cool.assert_called_once_with(True, 12)
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
@ -491,12 +538,13 @@ async def test_service_calls_cool_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_cool.assert_called_once_with(True) device.set_hold_cool.assert_called_once_with(True)
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
@ -504,12 +552,13 @@ async def test_service_calls_cool_mode(
device.hold_heat = True device.hold_heat = True
device.hold_cool = True device.hold_cool = True
await hass.services.async_call( with pytest.raises(ValueError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_TEMPERATURE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: "20"}, SERVICE_SET_TEMPERATURE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: "20"},
) blocking=True,
)
device.set_setpoint_cool.assert_called_once() device.set_setpoint_cool.assert_called_once()
@ -519,25 +568,25 @@ async def test_service_calls_cool_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
caplog.clear() caplog.clear()
with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
blocking=True, blocking=True,
) )
device.set_hold_cool.assert_called_once_with(True) device.set_hold_cool.assert_called_once_with(True)
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
assert "Couldn't set permanent hold" in caplog.text assert "Couldn't set permanent hold" in caplog.text
reset_mock(device) reset_mock(device)
with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE},
blocking=True, blocking=True,
) )
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
device.set_hold_cool.assert_called_once_with(False) device.set_hold_cool.assert_called_once_with(False)
@ -546,13 +595,13 @@ async def test_service_calls_cool_mode(
caplog.clear() caplog.clear()
device.set_hold_cool.side_effect = aiosomecomfort.SomeComfortError device.set_hold_cool.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE},
blocking=True, blocking=True,
) )
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
device.set_hold_cool.assert_called_once_with(False) device.set_hold_cool.assert_called_once_with(False)
@ -563,12 +612,13 @@ async def test_service_calls_cool_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_cool.assert_called_once_with(True) device.set_hold_cool.assert_called_once_with(True)
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
@ -580,13 +630,13 @@ async def test_service_calls_cool_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
blocking=True, blocking=True,
) )
device.set_hold_cool.assert_called_once_with(True) device.set_hold_cool.assert_called_once_with(True)
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
@ -599,12 +649,13 @@ async def test_service_calls_cool_mode(
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
device.system_mode = "Junk" device.system_mode = "Junk"
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_cool.assert_not_called() device.set_hold_cool.assert_not_called()
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
@ -640,13 +691,13 @@ async def test_service_calls_heat_mode(
device.set_hold_heat.reset_mock() device.set_hold_heat.reset_mock()
device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(ValueError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE, SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 15}, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 15},
blocking=True, blocking=True,
) )
device.set_hold_heat.assert_called_once_with(datetime.time(2, 30), 59) device.set_hold_heat.assert_called_once_with(datetime.time(2, 30), 59)
device.set_hold_heat.reset_mock() device.set_hold_heat.reset_mock()
assert "Invalid temperature" in caplog.text assert "Invalid temperature" in caplog.text
@ -667,16 +718,17 @@ async def test_service_calls_heat_mode(
device.set_setpoint_heat.reset_mock() device.set_setpoint_heat.reset_mock()
device.set_setpoint_heat.side_effect = aiosomecomfort.SomeComfortError device.set_setpoint_heat.side_effect = aiosomecomfort.SomeComfortError
await hass.services.async_call( with pytest.raises(ValueError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_TEMPERATURE, CLIMATE_DOMAIN,
{ SERVICE_SET_TEMPERATURE,
ATTR_ENTITY_ID: entity_id, {
ATTR_TARGET_TEMP_LOW: 25.0, ATTR_ENTITY_ID: entity_id,
ATTR_TARGET_TEMP_HIGH: 35.0, ATTR_TARGET_TEMP_LOW: 25.0,
}, ATTR_TARGET_TEMP_HIGH: 35.0,
blocking=True, },
) blocking=True,
)
device.set_setpoint_cool.assert_called_with(95) device.set_setpoint_cool.assert_called_with(95)
device.set_setpoint_heat.assert_called_with(77) device.set_setpoint_heat.assert_called_with(77)
assert "Invalid temperature" in caplog.text assert "Invalid temperature" in caplog.text
@ -685,12 +737,13 @@ async def test_service_calls_heat_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_heat.assert_called_once_with(True) device.set_hold_heat.assert_called_once_with(True)
device.set_hold_cool.assert_not_called() device.set_hold_cool.assert_not_called()
@ -698,12 +751,13 @@ async def test_service_calls_heat_mode(
device.hold_heat = True device.hold_heat = True
device.hold_cool = True device.hold_cool = True
await hass.services.async_call( with pytest.raises(ValueError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_TEMPERATURE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: "20"}, SERVICE_SET_TEMPERATURE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: "20"},
) blocking=True,
)
device.set_setpoint_heat.assert_called_once() device.set_setpoint_heat.assert_called_once()
@ -715,24 +769,26 @@ async def test_service_calls_heat_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_heat.assert_called_once_with(True) device.set_hold_heat.assert_called_once_with(True)
device.set_hold_cool.assert_not_called() device.set_hold_cool.assert_not_called()
assert "Couldn't set permanent hold" in caplog.text assert "Couldn't set permanent hold" in caplog.text
reset_mock(device) reset_mock(device)
await hass.services.async_call( with pytest.raises(ValueError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY},
) blocking=True,
)
device.set_hold_heat.assert_called_once_with(True, 22) device.set_hold_heat.assert_called_once_with(True, 22)
device.set_hold_cool.assert_not_called() device.set_hold_cool.assert_not_called()
@ -743,12 +799,13 @@ async def test_service_calls_heat_mode(
device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError
await hass.services.async_call( with pytest.raises(ValueError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY},
) blocking=True,
)
device.set_hold_heat.assert_called_once_with(True, 22) device.set_hold_heat.assert_called_once_with(True, 22)
device.set_hold_cool.assert_not_called() device.set_hold_cool.assert_not_called()
@ -757,13 +814,13 @@ async def test_service_calls_heat_mode(
reset_mock(device) reset_mock(device)
caplog.clear() caplog.clear()
with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE},
blocking=True, blocking=True,
) )
device.set_hold_heat.assert_called_once_with(False) device.set_hold_heat.assert_called_once_with(False)
device.set_hold_cool.assert_called_once_with(False) device.set_hold_cool.assert_called_once_with(False)
@ -771,13 +828,13 @@ async def test_service_calls_heat_mode(
device.set_hold_heat.reset_mock() device.set_hold_heat.reset_mock()
device.set_hold_cool.reset_mock() device.set_hold_cool.reset_mock()
device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE},
blocking=True, blocking=True,
) )
device.set_hold_heat.assert_called_once_with(False) device.set_hold_heat.assert_called_once_with(False)
assert "Can not stop hold mode" in caplog.text assert "Can not stop hold mode" in caplog.text
@ -786,12 +843,13 @@ async def test_service_calls_heat_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_heat.assert_called_once_with(True) device.set_hold_heat.assert_called_once_with(True)
device.set_hold_cool.assert_not_called() device.set_hold_cool.assert_not_called()
@ -802,12 +860,13 @@ async def test_service_calls_heat_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_heat.assert_called_once_with(True) device.set_hold_heat.assert_called_once_with(True)
device.set_hold_cool.assert_not_called() device.set_hold_cool.assert_not_called()
@ -863,13 +922,13 @@ async def test_service_calls_auto_mode(
device.set_hold_cool.side_effect = aiosomecomfort.SomeComfortError device.set_hold_cool.side_effect = aiosomecomfort.SomeComfortError
device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError device.set_hold_heat.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(ValueError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE, SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 15}, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 15},
blocking=True, blocking=True,
) )
device.set_setpoint_heat.assert_not_called() device.set_setpoint_heat.assert_not_called()
assert "Invalid temperature" in caplog.text assert "Invalid temperature" in caplog.text
@ -878,16 +937,17 @@ async def test_service_calls_auto_mode(
device.set_setpoint_heat.side_effect = aiosomecomfort.SomeComfortError device.set_setpoint_heat.side_effect = aiosomecomfort.SomeComfortError
device.set_setpoint_cool.side_effect = aiosomecomfort.SomeComfortError device.set_setpoint_cool.side_effect = aiosomecomfort.SomeComfortError
await hass.services.async_call( with pytest.raises(ValueError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_TEMPERATURE, CLIMATE_DOMAIN,
{ SERVICE_SET_TEMPERATURE,
ATTR_ENTITY_ID: entity_id, {
ATTR_TARGET_TEMP_LOW: 25.0, ATTR_ENTITY_ID: entity_id,
ATTR_TARGET_TEMP_HIGH: 35.0, ATTR_TARGET_TEMP_LOW: 25.0,
}, ATTR_TARGET_TEMP_HIGH: 35.0,
blocking=True, },
) blocking=True,
)
device.set_setpoint_heat.assert_not_called() device.set_setpoint_heat.assert_not_called()
assert "Invalid temperature" in caplog.text assert "Invalid temperature" in caplog.text
@ -917,12 +977,13 @@ async def test_service_calls_auto_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_cool.assert_called_once_with(True) device.set_hold_cool.assert_called_once_with(True)
device.set_hold_heat.assert_called_once_with(True) device.set_hold_heat.assert_called_once_with(True)
assert "Couldn't set permanent hold" in caplog.text assert "Couldn't set permanent hold" in caplog.text
@ -931,12 +992,13 @@ async def test_service_calls_auto_mode(
device.set_setpoint_heat.side_effect = None device.set_setpoint_heat.side_effect = None
device.set_setpoint_cool.side_effect = None device.set_setpoint_cool.side_effect = None
await hass.services.async_call( with pytest.raises(ValueError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY},
) blocking=True,
)
device.set_hold_cool.assert_called_once_with(True, 12) device.set_hold_cool.assert_called_once_with(True, 12)
device.set_hold_heat.assert_called_once_with(True, 22) device.set_hold_heat.assert_called_once_with(True, 22)
@ -944,25 +1006,26 @@ async def test_service_calls_auto_mode(
reset_mock(device) reset_mock(device)
caplog.clear() caplog.clear()
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE},
) blocking=True,
)
device.set_hold_heat.assert_called_once_with(False) device.set_hold_heat.assert_called_once_with(False)
device.set_hold_cool.assert_called_once_with(False) device.set_hold_cool.assert_called_once_with(False)
reset_mock(device) reset_mock(device)
device.set_hold_cool.side_effect = aiosomecomfort.SomeComfortError device.set_hold_cool.side_effect = aiosomecomfort.SomeComfortError
with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE},
blocking=True, blocking=True,
) )
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
device.set_hold_cool.assert_called_once_with(False) device.set_hold_cool.assert_called_once_with(False)
@ -974,12 +1037,13 @@ async def test_service_calls_auto_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_cool.assert_called_once_with(True) device.set_hold_cool.assert_called_once_with(True)
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()
@ -990,12 +1054,13 @@ async def test_service_calls_auto_mode(
device.raw_ui_data["StatusHeat"] = 2 device.raw_ui_data["StatusHeat"] = 2
device.raw_ui_data["StatusCool"] = 2 device.raw_ui_data["StatusCool"] = 2
await hass.services.async_call( with pytest.raises(HomeAssistantError):
CLIMATE_DOMAIN, await hass.services.async_call(
SERVICE_SET_PRESET_MODE, CLIMATE_DOMAIN,
{ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD}, SERVICE_SET_PRESET_MODE,
blocking=True, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_HOLD},
) blocking=True,
)
device.set_hold_cool.assert_called_once_with(True) device.set_hold_cool.assert_called_once_with(True)
device.set_hold_heat.assert_not_called() device.set_hold_heat.assert_not_called()