mirror of
https://github.com/Andre0512/hon.git
synced 2026-06-15 03:36:27 +00:00
Fix AC reverting to AUTO mode when changing settings after Home Assistant restart (#21)
After restarting Home Assistant, the AC entity correctly restores its previous state (e.g. HEAT mode at a given temperature). However, changing any setting (temperature, fan speed, or swing mode) caused the device to switch back to AUTO mode. Root cause The settings command was being sent with partially initialized parameters after a restart. When only a single value (e.g. temperature) was updated, other parameters such as machMode and onOffStatus were implicitly sent with their default values, which for many devices means AUTO mode. Solution Before sending the settings command, the current machMode and onOffStatus are now explicitly copied from the device state into the command parameters. This ensures that changing temperature, fan mode, or swing mode does not unintentionally reset the HVAC mode. Result The AC keeps the selected HVAC mode (HEAT/COOL/etc.) after a Home Assistant restart. Updating temperature, fan speed, or swing no longer forces the device back to AUTO. No change in behavior when explicitly changing HVAC mode or presets.
This commit is contained in:
parent
e3205e4255
commit
5cf7f812f4
|
|
@ -184,16 +184,41 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
|
|||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
|
||||
if "settings.machMode" in self._device.settings:
|
||||
current_mach = self._device.get("machMode")
|
||||
if current_mach is not None:
|
||||
self._device.settings["settings.machMode"].value = str(int(current_mach))
|
||||
if "settings.onOffStatus" in self._device.settings:
|
||||
current_onoff = self._device.get("onOffStatus")
|
||||
if current_onoff is not None:
|
||||
self._device.settings["settings.onOffStatus"].value = str(int(current_onoff))
|
||||
|
||||
self._device.settings["settings.tempSel"].value = str(int(temperature))
|
||||
await self._device.commands["settings"].send()
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> HVACMode:
|
||||
if self._device.get("onOffStatus") == 0:
|
||||
on_off = self._device.get("onOffStatus")
|
||||
mach = self._device.get("machMode")
|
||||
|
||||
if on_off == 0:
|
||||
return HVACMode.OFF
|
||||
else:
|
||||
return HON_HVAC_MODE[self._device.get("machMode")]
|
||||
|
||||
if mach not in HON_HVAC_MODE:
|
||||
return getattr(self, "_attr_hvac_mode", HVACMode.AUTO)
|
||||
|
||||
mode = HON_HVAC_MODE[mach]
|
||||
|
||||
if mode == HVACMode.AUTO and getattr(self, "_attr_hvac_mode", None) not in (
|
||||
None,
|
||||
HVACMode.OFF,
|
||||
HVACMode.AUTO,
|
||||
):
|
||||
return self._attr_hvac_mode
|
||||
|
||||
return mode
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
self._attr_hvac_mode = hvac_mode
|
||||
|
|
@ -251,7 +276,16 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
|
|||
return HON_FAN[self._device.get("windSpeed")]
|
||||
|
||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
||||
fan_modes = {}
|
||||
if "settings.machMode" in self._device.settings:
|
||||
current_mach = self._device.get("machMode")
|
||||
if current_mach is not None:
|
||||
self._device.settings["settings.machMode"].value = str(int(current_mach))
|
||||
if "settings.onOffStatus" in self._device.settings:
|
||||
current_onoff = self._device.get("onOffStatus")
|
||||
if current_onoff is not None:
|
||||
self._device.settings["settings.onOffStatus"].value = str(int(current_onoff))
|
||||
|
||||
fan_modes: dict[str, str] = {}
|
||||
for mode in reversed(self._device.settings["settings.windSpeed"].values):
|
||||
fan_modes[HON_FAN[int(mode)]] = mode
|
||||
self._device.settings["settings.windSpeed"].value = str(fan_modes[fan_mode])
|
||||
|
|
@ -273,6 +307,15 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
|
|||
return SWING_OFF
|
||||
|
||||
async def async_set_swing_mode(self, swing_mode: str) -> None:
|
||||
if "settings.machMode" in self._device.settings:
|
||||
current_mach = self._device.get("machMode")
|
||||
if current_mach is not None:
|
||||
self._device.settings["settings.machMode"].value = str(int(current_mach))
|
||||
if "settings.onOffStatus" in self._device.settings:
|
||||
current_onoff = self._device.get("onOffStatus")
|
||||
if current_onoff is not None:
|
||||
self._device.settings["settings.onOffStatus"].value = str(int(current_onoff))
|
||||
|
||||
horizontal = self._device.settings["settings.windDirectionHorizontal"]
|
||||
vertical = self._device.settings["settings.windDirectionVertical"]
|
||||
if swing_mode in [SWING_BOTH, SWING_HORIZONTAL]:
|
||||
|
|
@ -317,7 +360,7 @@ class HonClimateEntity(HonEntity, ClimateEntity):
|
|||
if "stopProgram" in device.commands:
|
||||
self._attr_supported_features |= ClimateEntityFeature.TURN_OFF
|
||||
self._attr_hvac_modes += [HVACMode.OFF]
|
||||
modes = []
|
||||
modes: list[str] = []
|
||||
else:
|
||||
modes = ["no_mode"]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue