jeatheak / Mitsubishi-WF-RAC-Integration

WF-RAC homeassistant integration
MIT License
101 stars 19 forks source link

The `set_temperature` service on the climate entity should also set the hvac mode #47

Closed Akeboshiwind closed 1 year ago

Akeboshiwind commented 1 year ago

Looking at the docs for the climate entity, there's an optional parameter hvac_mode which it looks like your climate entity doesn't support.

Would it be possible to add it? I've tried this out locally and it seems to work:

diff --git a/custom_components/mitsubishi_wf_rac/climate.py b/custom_components/mitsubishi_wf_rac/climate.py
index 197b728..561766e 100644
--- a/custom_components/mitsubishi_wf_rac/climate.py
+++ b/custom_components/mitsubishi_wf_rac/climate.py
@@ -87,10 +87,16 @@ class AircoClimate(ClimateEntity):
         self._attr_unique_id = f"{DOMAIN}-{self._device.airco_id}-climate"
         self._update_state()

-    async def async_set_temperature(self, **kwargs) -> None:
+    async def async_set_temperature(self, hvac_mode: HVACMode, **kwargs) -> None:
         """Set new target temperature."""
         await self._device.set_airco(
-            {AirconCommands.PresetTemp: kwargs.get(ATTR_TEMPERATURE)}
+            {
+                AirconCommands.PresetTemp: kwargs.get(ATTR_TEMPERATURE),
+                AirconCommands.OperationMode: self._device.airco.OperationMode
+                if hvac_mode == HVACMode.OFF
+                else HVAC_TRANSLATION[hvac_mode],
+                AirconCommands.Operation: hvac_mode != HVACMode.OFF,
+            }
         )
         self._update_state()

Another option would be to call await self.async_set_hvac_mode(**kwargs) and remove one call to self._update_state()

Akeboshiwind commented 1 year ago

Actually my two options here don't make hvac_mode optional. I've submitted a PR to allow optionally setting it :)