I’m looking for some examples to code the ServiceValidationError in my function… I have a function to set the hvac mode of a thermostat based on an array of possible modes… if the user still sends a mode that is not supported, it needs to raise a ServiceValidationError…
This is my original code
@api_call
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set the new hvac mode."""
if hvac_mode not in self.hvac_mode:
await self._channel.set_mode(hvac_mode)
self.async_write_ha_state()
in which i need to raise an exception; the feedback language was:
if hvac_mode not in self.hvac_modes:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key=unsupported_hvac_mode
translation_placeholders={"hvac_mode":hvac_mode}
but that obviously is not yet fully complete… but not sure how to make it completely work…
The translation_key needs to be a string and then you need to make the translation in the translation json files
But in climate we will anyway validate your now setting a mode which isn’t part of hvac_modes so this validation your making won’t be necessary mid-term (6m deprecation before failing)