mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Raise translatable exceptions in entity set methods for BSBLan (#105693)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
3392660537
commit
80b404f351
@ -17,6 +17,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, ServiceValidationError
|
||||||
from homeassistant.helpers.device_registry import format_mac
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
@ -26,7 +27,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||||||
from homeassistant.util.enum import try_parse_enum
|
from homeassistant.util.enum import try_parse_enum
|
||||||
|
|
||||||
from . import HomeAssistantBSBLANData
|
from . import HomeAssistantBSBLANData
|
||||||
from .const import ATTR_TARGET_TEMPERATURE, DOMAIN, LOGGER
|
from .const import ATTR_TARGET_TEMPERATURE, DOMAIN
|
||||||
from .entity import BSBLANEntity
|
from .entity import BSBLANEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -147,7 +148,12 @@ class BSBLANClimate(
|
|||||||
if self.hvac_mode == HVACMode.AUTO:
|
if self.hvac_mode == HVACMode.AUTO:
|
||||||
await self.async_set_data(preset_mode=preset_mode)
|
await self.async_set_data(preset_mode=preset_mode)
|
||||||
else:
|
else:
|
||||||
LOGGER.error("Can't set preset mode when hvac mode is not auto")
|
raise ServiceValidationError(
|
||||||
|
"Can't set preset mode when hvac mode is not auto",
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="set_preset_mode_error",
|
||||||
|
translation_placeholders={"preset_mode": preset_mode},
|
||||||
|
)
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||||
"""Set new target temperatures."""
|
"""Set new target temperatures."""
|
||||||
@ -168,6 +174,10 @@ class BSBLANClimate(
|
|||||||
data[ATTR_HVAC_MODE] = kwargs[ATTR_PRESET_MODE]
|
data[ATTR_HVAC_MODE] = kwargs[ATTR_PRESET_MODE]
|
||||||
try:
|
try:
|
||||||
await self.client.thermostat(**data)
|
await self.client.thermostat(**data)
|
||||||
except BSBLANError:
|
except BSBLANError as err:
|
||||||
LOGGER.error("An error occurred while updating the BSBLAN device")
|
raise HomeAssistantError(
|
||||||
|
"An error occurred while updating the BSBLAN device",
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="set_data_error",
|
||||||
|
) from err
|
||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
|
@ -24,5 +24,13 @@
|
|||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"exceptions": {
|
||||||
|
"set_preset_mode_error": {
|
||||||
|
"message": "Can't set preset mode to {preset_mode} when HVAC mode is not set to auto"
|
||||||
|
},
|
||||||
|
"set_data_error": {
|
||||||
|
"message": "An error occurred while sending the data to the BSBLAN device"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user