Fix for setting some climate modes #84

This commit is contained in:
Andre Basche 2023-07-11 00:17:19 +02:00
parent fb8fba259a
commit a9e21608d8
2 changed files with 22 additions and 12 deletions

View File

@ -6,7 +6,6 @@ from homeassistant.components.climate import (
ClimateEntityDescription, ClimateEntityDescription,
) )
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
FAN_OFF,
SWING_OFF, SWING_OFF,
SWING_BOTH, SWING_BOTH,
SWING_VERTICAL, SWING_VERTICAL,
@ -22,7 +21,7 @@ from homeassistant.const import (
from homeassistant.core import callback from homeassistant.core import callback
from pyhon.appliance import HonAppliance from pyhon.appliance import HonAppliance
from .const import HON_HVAC_MODE, HON_FAN, DOMAIN from .const import HON_HVAC_MODE, HON_FAN, DOMAIN, HON_HVAC_PROGRAM
from .hon import HonEntity from .hon import HonEntity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -123,9 +122,6 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
self._attr_preset_modes = [] self._attr_preset_modes = []
for mode in device.settings["startProgram.program"].values: for mode in device.settings["startProgram.program"].values:
self._attr_preset_modes.append(mode) self._attr_preset_modes.append(mode)
self._attr_fan_modes = [FAN_OFF]
for mode in device.settings["settings.windSpeed"].values:
self._attr_fan_modes.append(HON_FAN[int(mode)])
self._attr_swing_modes = [ self._attr_swing_modes = [
SWING_OFF, SWING_OFF,
SWING_VERTICAL, SWING_VERTICAL,
@ -181,7 +177,11 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
self._device.settings["settings.onOffStatus"].value = "1" self._device.settings["settings.onOffStatus"].value = "1"
setting = self._device.settings["settings.machMode"] setting = self._device.settings["settings.machMode"]
modes = {HON_HVAC_MODE[int(number)]: number for number in setting.values} modes = {HON_HVAC_MODE[int(number)]: number for number in setting.values}
setting.value = modes[hvac_mode] if hvac_mode in modes:
setting.value = modes[hvac_mode]
else:
await self.async_set_preset_mode(HON_HVAC_PROGRAM[hvac_mode])
return
await self._device.commands["settings"].send() await self._device.commands["settings"].send()
self.async_write_ha_state() self.async_write_ha_state()
@ -192,7 +192,7 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
async def async_set_preset_mode(self, preset_mode: str) -> None: async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set the new preset mode.""" """Set the new preset mode."""
if program := self._device.settings.get(f"startProgram.program"): if program := self._device.settings.get("startProgram.program"):
program.value = preset_mode program.value = preset_mode
self._device.sync_command("startProgram", "settings") self._device.sync_command("startProgram", "settings")
self._set_temperature_bound() self._set_temperature_bound()
@ -202,15 +202,24 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
await self._device.commands["startProgram"].send() await self._device.commands["startProgram"].send()
self.async_write_ha_state() self.async_write_ha_state()
@property
def fan_modes(self) -> list[str]:
"""Return the list of available fan modes."""
fan_modes = []
for mode in reversed(self._device.settings["settings.windSpeed"].values):
fan_modes.append(HON_FAN[int(mode)])
return fan_modes
@property @property
def fan_mode(self) -> str | None: def fan_mode(self) -> str | None:
"""Return the fan setting.""" """Return the fan setting."""
return HON_FAN[self._device.get("windSpeed")] return HON_FAN[self._device.get("windSpeed")]
async def async_set_fan_mode(self, fan_mode): async def async_set_fan_mode(self, fan_mode):
mode_number = list(HON_FAN.values()).index(fan_mode) fan_modes = {}
mode = list(HON_FAN.keys())[mode_number] for mode in reversed(self._device.settings["settings.windSpeed"].values):
self._device.settings["settings.windSpeed"].value = str(mode) fan_modes[HON_FAN[int(mode)]] = mode
self._device.settings["settings.windSpeed"].value = str(fan_modes[fan_mode])
self._attr_fan_mode = fan_mode self._attr_fan_mode = fan_mode
await self._device.commands["settings"].send() await self._device.commands["settings"].send()
self.async_write_ha_state() self.async_write_ha_state()
@ -249,6 +258,7 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
self._attr_target_temperature = self.target_temperature self._attr_target_temperature = self.target_temperature
self._attr_current_temperature = self.current_temperature self._attr_current_temperature = self.current_temperature
self._attr_hvac_mode = self.hvac_mode self._attr_hvac_mode = self.hvac_mode
self._attr_fan_modes = self.fan_modes
self._attr_fan_mode = self.fan_mode self._attr_fan_mode = self.fan_mode
self._attr_swing_mode = self.swing_mode self._attr_swing_mode = self.swing_mode
if update: if update:

View File

@ -9,7 +9,7 @@
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"issue_tracker": "https://github.com/Andre0512/hon/issues", "issue_tracker": "https://github.com/Andre0512/hon/issues",
"requirements": [ "requirements": [
"pyhOn==0.14.8" "pyhOn==0.14.9"
], ],
"version": "0.9.0-beta.9" "version": "0.9.0-beta.10"
} }