Skip to content

Commit

Permalink
Add suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
CoMPaTech committed Dec 3, 2024
1 parent a4b36d0 commit 867892c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
15 changes: 13 additions & 2 deletions homeassistant/components/plugwise/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
if temperature is None or not (
self._attr_min_temp <= temperature <= self._attr_max_temp
):
raise ValueError("Invalid temperature change requested")
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="invalid_temperature_change_requested",
)

if mode := kwargs.get(ATTR_HVAC_MODE):
await self.async_set_hvac_mode(mode)
Expand All @@ -244,7 +247,15 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set the hvac mode."""
if hvac_mode not in self.hvac_modes:
raise ServiceValidationError("Unsupported hvac_mode")
hvac_modes = ", ".join(self.hvac_modes)
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="unsupported_hvac_mode_requested",
translation_placeholders={
"hvac_mode": hvac_mode,
"hvac_modes": hvac_modes,
},
)

if hvac_mode == self.hvac_mode:
return
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/plugwise/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ rules:
diagnostics: done
exception-translations:
status: todo
comment: Add coordinator, util and climate exceptions
comment: Add coordinator, util exceptions (climate done in core 132175)
icon-translations: done
reconfiguration-flow:
status: todo
comment: This integration does not have any reconfiguration steps (yet) investigate how/why
dynamic-devices:
status: todo
comment: Investigate missing logic to button for unloading and creation
dynamic-devices: done
discovery-update-info: done
repair-issues:
status: exempt
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/plugwise/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,13 @@
"name": "Relay"
}
}
},
"exceptions": {
"invalid_temperature_change_requested": {
"message": "Invalid temperature change requested."
},
"unsupported_hvac_mode_requested": {
"message": "Unsupported mode {hvac_mode} requested, valid modes are: {hvac_modes}."
}
}
}
2 changes: 1 addition & 1 deletion tests/components/plugwise/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ async def test_adam_climate_entity_climate_changes(
"c50f167537524366a5af7aa3942feb1e", "off"
)

with pytest.raises(HomeAssistantError):
with pytest.raises(ServiceValidationError):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
Expand Down

0 comments on commit 867892c

Please sign in to comment.