Skip to content

Commit

Permalink
Split program and mach mode of ac #75
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed Jun 21, 2023
1 parent 78727e8 commit fbd1bdf
Show file tree
Hide file tree
Showing 23 changed files with 508 additions and 31 deletions.
47 changes: 37 additions & 10 deletions custom_components/hon/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from homeassistant.core import callback
from pyhon.appliance import HonAppliance

from .const import HON_HVAC_MODE, HON_FAN, HON_HVAC_PROGRAM, DOMAIN
from .const import HON_HVAC_MODE, HON_FAN, DOMAIN
from .hon import HonEntity

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -115,13 +115,14 @@ def __init__(self, hass, entry, device: HonAppliance, description) -> None:
super().__init__(hass, entry, device, description)

self._attr_temperature_unit = TEMP_CELSIUS
self._attr_target_temperature_step = device.settings["settings.tempSel"].step
self._attr_max_temp = device.settings["settings.tempSel"].max
self._attr_min_temp = device.settings["settings.tempSel"].min
self._set_temperature_bound()

self._attr_hvac_modes = [HVACMode.OFF]
for mode in device.settings["settings.machMode"].values:
self._attr_hvac_modes.append(HON_HVAC_MODE[mode])
self._attr_preset_modes = []
for mode in device.settings["startProgram.program"].values:
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[mode])
Expand All @@ -135,10 +136,18 @@ def __init__(self, hass, entry, device: HonAppliance, description) -> None:
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.PRESET_MODE
)

self._handle_coordinator_update(update=False)

def _set_temperature_bound(self) -> None:
self._attr_target_temperature_step = self._device.settings[
"settings.tempSel"
].step
self._attr_max_temp = self._device.settings["settings.tempSel"].max
self._attr_min_temp = self._device.settings["settings.tempSel"].min

@property
def target_temperature(self) -> int | None:
"""Return the temperature we try to reach."""
Expand Down Expand Up @@ -166,13 +175,31 @@ def hvac_mode(self) -> HVACMode | str | None:
async def async_set_hvac_mode(self, hvac_mode):
self._attr_hvac_mode = hvac_mode
if hvac_mode == HVACMode.OFF:
command = "stopProgram"
await self._device.commands["stopProgram"].send()
self._device.sync_command("stopProgram", "settings")
else:
mode = HON_HVAC_PROGRAM[hvac_mode]
self._device.settings["startProgram.program"].value = mode
command = "startProgram"
await self._device.commands[command].send()
self._device.sync_command(command, "settings")
self._device.settings["settings.onOffStatus"].value = "1"
setting = self._device.settings["settings.machMode"]
modes = {HON_HVAC_MODE[number]: number for number in setting.values}
setting.value = modes[hvac_mode]
await self._device.commands["settings"].send()
self.async_write_ha_state()

@property
def preset_mode(self) -> str | None:
"""Return the current Preset for this channel."""
return None

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set the new preset mode."""
if program := self._device.settings.get(f"startProgram.program"):
program.value = preset_mode
self._device.sync_command("startProgram", "settings")
self._set_temperature_bound()
self._handle_coordinator_update(update=False)
await self.coordinator.async_refresh()
self._attr_preset_mode = preset_mode
await self._device.commands["startProgram"].send()
self.async_write_ha_state()

@property
Expand Down
2 changes: 2 additions & 0 deletions custom_components/hon/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ async def async_set_native_value(self, value: float) -> None:
setting.value = value
command = self.entity_description.key.split(".")[0]
await self._device.commands[command].send()
if command != "settings":
self._device.sync_command(command, "settings")
await self.coordinator.async_refresh()

@callback
Expand Down
6 changes: 4 additions & 2 deletions custom_components/hon/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ def _option_to_number(self, option: str, values: List[str]):
async def async_select_option(self, option: str) -> None:
setting = self._device.settings[self.entity_description.key]
setting.value = self._option_to_number(option, setting.values)
command = self.entity_description.key.split(".")[0]
await self._device.commands[command].send()
await self.coordinator.async_refresh()

@callback
Expand All @@ -224,6 +222,10 @@ class HonSelectEntity(HonConfigSelectEntity):
async def async_select_option(self, option: str) -> None:
setting = self._device.settings[self.entity_description.key]
setting.value = self._option_to_number(option, setting.values)
command = self.entity_description.key.split(".")[0]
await self._device.commands[command].send()
if command != "settings":
self._device.sync_command(command, "settings")
await self.coordinator.async_refresh()

@property
Expand Down
26 changes: 25 additions & 1 deletion custom_components/hon/translations/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,31 @@
},
"climate": {
"air_conditioner": {
"name": "Klimatizační jednotka"
"name": "Klimatizační jednotka",
"state_attributes": {
"preset_mode": {
"name": "Programy",
"state": {
"iot_10_heating": "Funkce Vytápění 10 °C",
"iot_auto": "Auto",
"iot_cool": "Chlazení",
"iot_dry": "Odvlhčování",
"iot_fan": "Ventilátor",
"iot_heat": "Vytápění",
"iot_nano_aqua": "Nano Aqua",
"iot_purify": "Automatické čištění",
"iot_self_clean": "Samočištění zamrazením",
"iot_self_clean_56": "Samočištění 56°C sterilizace ",
"iot_simple_start": "Spustit nyní",
"iot_uv": "UV",
"iot_uv_and_auto": "UV + auto",
"iot_uv_and_cool": "UV + zchlazení",
"iot_uv_and_dry": "UV + odstranění vlhkosti",
"iot_uv_and_fan": "UV + ventilátor",
"iot_uv_and_heat": "UV + ohřev"
}
}
}
},
"fridge": {
"name": "Chladnička",
Expand Down
26 changes: 25 additions & 1 deletion custom_components/hon/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,31 @@
},
"climate": {
"air_conditioner": {
"name": "Klimaanlage"
"name": "Klimaanlage",
"state_attributes": {
"preset_mode": {
"name": "Programme",
"state": {
"iot_10_heating": "10°C Heizfunktion",
"iot_auto": "Auto",
"iot_cool": "Kühl",
"iot_dry": "Trocken",
"iot_fan": "Ventilator",
"iot_heat": "Heizen",
"iot_nano_aqua": "Nano Aqua",
"iot_purify": "Selbst reinigen",
"iot_self_clean": "Self-Clean",
"iot_self_clean_56": "Steri-Clean 56°C",
"iot_simple_start": "Jetzt beginnen",
"iot_uv": "UV",
"iot_uv_and_auto": "UV + Auto",
"iot_uv_and_cool": "UV + Kalt",
"iot_uv_and_dry": "UV + Entfeuchter",
"iot_uv_and_fan": "UV + Gebläse",
"iot_uv_and_heat": "UV + Heizen"
}
}
}
},
"fridge": {
"name": "Kühlschrank",
Expand Down
26 changes: 25 additions & 1 deletion custom_components/hon/translations/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,31 @@
},
"climate": {
"air_conditioner": {
"name": "Κλιματιστικό"
"name": "Κλιματιστικό",
"state_attributes": {
"preset_mode": {
"name": "Προγράμματα",
"state": {
"iot_10_heating": "10° C Λειτουργία θέρμανσης",
"iot_auto": "Αυτόματο",
"iot_cool": "Ψύξη",
"iot_dry": "Στέγνωμα",
"iot_fan": "Ανεμιστήρας",
"iot_heat": "Ζέστη",
"iot_nano_aqua": "Nano Aqua",
"iot_purify": "Αυτοκαθαρισμός",
"iot_self_clean": "Αυτοκαθαρισμός",
"iot_self_clean_56": "Steri-Clean 56°C",
"iot_simple_start": "Εκκίνηση τώρα",
"iot_uv": "UV",
"iot_uv_and_auto": "UV + Auto",
"iot_uv_and_cool": "UV + Ψύξη",
"iot_uv_and_dry": "UV + Αφυγραντήρας",
"iot_uv_and_fan": "UV + Ανεμιστήρας",
"iot_uv_and_heat": "UV + Θέρμανση"
}
}
}
},
"fridge": {
"name": "Ψυγείο",
Expand Down
26 changes: 25 additions & 1 deletion custom_components/hon/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,31 @@
},
"climate": {
"air_conditioner": {
"name": "Air conditioner"
"name": "Air conditioner",
"state_attributes": {
"preset_mode": {
"name": "Programs",
"state": {
"iot_10_heating": "10°C Heating function",
"iot_auto": "Auto",
"iot_cool": "Cool",
"iot_dry": "Dry",
"iot_fan": "Fan",
"iot_heat": "Heat",
"iot_nano_aqua": "Nano Aqua",
"iot_purify": "Self-purify",
"iot_self_clean": "Self-clean",
"iot_self_clean_56": "Steri-Clean 56°C",
"iot_simple_start": "Start now",
"iot_uv": "UV",
"iot_uv_and_auto": "UV + Auto",
"iot_uv_and_cool": "UV + Cold",
"iot_uv_and_dry": "UV + Dehumidifier",
"iot_uv_and_fan": "UV + Fan",
"iot_uv_and_heat": "UV + Heat"
}
}
}
},
"fridge": {
"name": "Fridge",
Expand Down
26 changes: 25 additions & 1 deletion custom_components/hon/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,31 @@
},
"climate": {
"air_conditioner": {
"name": "Aire acondicionado"
"name": "Aire acondicionado",
"state_attributes": {
"preset_mode": {
"name": "Programas",
"state": {
"iot_10_heating": "Función de calentamiento de 10° C",
"iot_auto": "Automático",
"iot_cool": "Frío",
"iot_dry": "Deshumidificar",
"iot_fan": "Ventilador",
"iot_heat": "Calor",
"iot_nano_aqua": "Nano Aqua",
"iot_purify": "Autopurificar",
"iot_self_clean": "Autolimpieza",
"iot_self_clean_56": "Limpieza desinfectante 56°",
"iot_simple_start": "Iniciar ahora",
"iot_uv": "UV",
"iot_uv_and_auto": "UV + Automático",
"iot_uv_and_cool": "UV + Frío",
"iot_uv_and_dry": "UV + Deshumidificador",
"iot_uv_and_fan": "UV + Ventilador",
"iot_uv_and_heat": "UV + Calor"
}
}
}
},
"fridge": {
"name": "Frigorífico",
Expand Down
26 changes: 25 additions & 1 deletion custom_components/hon/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,31 @@
},
"climate": {
"air_conditioner": {
"name": "Climatiseur"
"name": "Climatiseur",
"state_attributes": {
"preset_mode": {
"name": "Programmes",
"state": {
"iot_10_heating": "Fonction Chauffage 10 °C",
"iot_auto": "Automatique",
"iot_cool": "Frais",
"iot_dry": "Sec",
"iot_fan": "Ventilateur",
"iot_heat": "Chaleur",
"iot_nano_aqua": "Nano Aqua",
"iot_purify": "Auto-purification",
"iot_self_clean": "Auto-nettoyage",
"iot_self_clean_56": "Steri-Clean 56°C",
"iot_simple_start": "Démarrez maintenant",
"iot_uv": "UV",
"iot_uv_and_auto": "UV + Auto",
"iot_uv_and_cool": "UV + Froid",
"iot_uv_and_dry": "UV + Déshumidificateur",
"iot_uv_and_fan": "UV + ventilateur",
"iot_uv_and_heat": "UV + Chaleur"
}
}
}
},
"fridge": {
"name": "Réfrigérateur",
Expand Down
10 changes: 9 additions & 1 deletion custom_components/hon/translations/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,15 @@
},
"climate": {
"air_conditioner": {
"name": "Air conditioner"
"name": "Air conditioner",
"state_attributes": {
"preset_mode": {
"name": "Programs",
"state": {
"iot_simple_start": "התחל עכשיו"
}
}
}
},
"fridge": {
"name": "Fridge",
Expand Down
26 changes: 25 additions & 1 deletion custom_components/hon/translations/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,31 @@
},
"climate": {
"air_conditioner": {
"name": "Klimatizacijski uređaj"
"name": "Klimatizacijski uređaj",
"state_attributes": {
"preset_mode": {
"name": "Programi",
"state": {
"iot_10_heating": "Funkcija grijanja na 10 °C",
"iot_auto": "Automatski",
"iot_cool": "Hlađenje",
"iot_dry": "Sušenje",
"iot_fan": "Ventilator",
"iot_heat": "Zagrijavanje",
"iot_nano_aqua": "Nano Aqua",
"iot_purify": "Sampročišćavanje",
"iot_self_clean": "Samočišćenje",
"iot_self_clean_56": "Sterilno čišćenje 56°C",
"iot_simple_start": "Pokreni sada",
"iot_uv": "UV",
"iot_uv_and_auto": "UV + automatski",
"iot_uv_and_cool": "UV + hladno",
"iot_uv_and_dry": "UV + odvlaživač",
"iot_uv_and_fan": "UV + ventilator",
"iot_uv_and_heat": "UV + grijanje"
}
}
}
},
"fridge": {
"name": "Hladnjak",
Expand Down
26 changes: 25 additions & 1 deletion custom_components/hon/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,31 @@
},
"climate": {
"air_conditioner": {
"name": "Condizionatore"
"name": "Condizionatore",
"state_attributes": {
"preset_mode": {
"name": "Programmi",
"state": {
"iot_10_heating": "Funzione 10°C Heating ",
"iot_auto": "Auto",
"iot_cool": "Freddo",
"iot_dry": "Deumidificazione",
"iot_fan": "Ventilatore",
"iot_heat": "Caldo",
"iot_nano_aqua": "Nano Aqua",
"iot_purify": "Self purify",
"iot_self_clean": "Self clean",
"iot_self_clean_56": "Steri-Clean 56°C",
"iot_simple_start": "Avvia ora",
"iot_uv": "UV",
"iot_uv_and_auto": "UV + Auto",
"iot_uv_and_cool": "UV + Freddo",
"iot_uv_and_dry": "UV + Deumidificatore",
"iot_uv_and_fan": "UV + Ventola",
"iot_uv_and_heat": "UV + Caldo"
}
}
}
},
"fridge": {
"name": "Frigorifero",
Expand Down
Loading

0 comments on commit fbd1bdf

Please sign in to comment.