Raise ServiceValidationError in Nibe climate services (#117171)
Fix ClimateService to rise ServiceValidationError for stack free logs
This commit is contained in:
parent
4138c7a0ef
commit
d4fbaef4f6
2 changed files with 13 additions and 7 deletions
|
@ -26,6 +26,7 @@ from homeassistant.components.climate import (
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
@ -219,9 +220,11 @@ class NibeClimateEntity(CoordinatorEntity[Coordinator], ClimateEntity):
|
||||||
self._coil_setpoint_cool, temperature
|
self._coil_setpoint_cool, temperature
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"{hvac_mode} mode not supported for {self.name}")
|
raise ServiceValidationError(
|
||||||
|
f"{hvac_mode} mode not supported for {self.name}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ServiceValidationError(
|
||||||
"'set_temperature' requires 'hvac_mode' when passing"
|
"'set_temperature' requires 'hvac_mode' when passing"
|
||||||
" 'temperature' and 'hvac_mode' is not already set to"
|
" 'temperature' and 'hvac_mode' is not already set to"
|
||||||
" 'heat' or 'cool'"
|
" 'heat' or 'cool'"
|
||||||
|
@ -256,4 +259,6 @@ class NibeClimateEntity(CoordinatorEntity[Coordinator], ClimateEntity):
|
||||||
)
|
)
|
||||||
await coordinator.async_write_coil(self._coil_use_room_sensor, "OFF")
|
await coordinator.async_write_coil(self._coil_use_room_sensor, "OFF")
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"{hvac_mode} mode not supported for {self.name}")
|
raise ServiceValidationError(
|
||||||
|
f"{hvac_mode} mode not supported for {self.name}"
|
||||||
|
)
|
||||||
|
|
|
@ -26,6 +26,7 @@ from homeassistant.components.climate import (
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
|
|
||||||
from . import MockConnection, async_add_model
|
from . import MockConnection, async_add_model
|
||||||
|
|
||||||
|
@ -196,7 +197,7 @@ async def test_set_temperature_supported_cooling(
|
||||||
]
|
]
|
||||||
mock_connection.write_coil.reset_mock()
|
mock_connection.write_coil.reset_mock()
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ServiceValidationError):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
PLATFORM_DOMAIN,
|
PLATFORM_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
@ -268,8 +269,8 @@ async def test_set_temperature_unsupported_cooling(
|
||||||
call(CoilData(coil_setpoint_heat, 22))
|
call(CoilData(coil_setpoint_heat, 22))
|
||||||
]
|
]
|
||||||
|
|
||||||
# Attempt to set temperature to cool should raise ValueError
|
# Attempt to set temperature to cool should raise ServiceValidationError
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ServiceValidationError):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
PLATFORM_DOMAIN,
|
PLATFORM_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
@ -362,7 +363,7 @@ async def test_set_invalid_hvac_mode(
|
||||||
_setup_climate_group(coils, model, climate_id)
|
_setup_climate_group(coils, model, climate_id)
|
||||||
|
|
||||||
await async_add_model(hass, model)
|
await async_add_model(hass, model)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ServiceValidationError):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
PLATFORM_DOMAIN,
|
PLATFORM_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
SERVICE_SET_HVAC_MODE,
|
||||||
|
|
Loading…
Add table
Reference in a new issue