Skip to content

Commit

Permalink
🐛 Distinguish between cool/heat climate mode
Browse files Browse the repository at this point in the history
Without this, receiving Cooling_Mode=0 can wrongly set the heating mode
in compensation mode.

Relates to #220, possibly fixing it.
  • Loading branch information
kamaradclimber committed Jul 8, 2024
1 parent 77a6131 commit 3101b91
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions custom_components/aquarea/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from dataclasses import dataclass
from enum import Enum, Flag, auto
from functools import partial

from homeassistant.components import mqtt
from homeassistant.components.mqtt.client import async_publish
Expand Down Expand Up @@ -134,7 +135,7 @@ def __init__(
self._operating_mode = OperatingMode(0) # i.e None

self._sensor_mode = ZoneSensorMode.WATER
self._climate_mode = ZoneClimateMode.DIRECT
self._climate_mode = {"HEATING": ZoneClimateMode.DIRECT, "COOLING": ZoneClimateMode.DIRECT}
self._mode = ZoneTemperatureMode.DIRECT
self.change_mode(ZoneTemperatureMode.DIRECT, initialization=True)

Expand All @@ -154,9 +155,13 @@ def evaluate_temperature_mode(self):
elif self._sensor_mode == ZoneSensorMode.EXTERNAL:
mode = ZoneTemperatureMode.NAN
elif self._sensor_mode == ZoneSensorMode.WATER:
if self._climate_mode == ZoneClimateMode.DIRECT:
if OperatingMode.HEAT in self._operating_mode:
key_mode = "HEATING"
else:
key_mode = "COOLING"
if self._climate_mode[key_mode] == ZoneClimateMode.DIRECT:
mode = ZoneTemperatureMode.DIRECT
elif self._climate_mode == ZoneClimateMode.COMPENSATION:
elif self._climate_mode[key_mode] == ZoneClimateMode.COMPENSATION:
mode = ZoneTemperatureMode.COMPENSATION
else:
assert False, f"Unknown combination of Sensor Mode and Climate Mode"
Expand Down Expand Up @@ -248,28 +253,28 @@ def sensor_mode_received(message):
)

@callback
def mode_received(message):
def mode_received(mod_key: str, message):
if message.payload == "0":
climate_mode = ZoneClimateMode.COMPENSATION
elif message.payload == "1":
climate_mode = ZoneClimateMode.DIRECT
else:
assert False, f"Climate Mode received is not a known value"
if climate_mode != self._climate_mode: # if climate mode was changed
self._climate_mode = climate_mode # updated it
if climate_mode != self._climate_mode[mod_key]: # if climate mode was changed
self._climate_mode[mod_key] = climate_mode # updated it
self.evaluate_temperature_mode() # and trigger temp eval

await mqtt.async_subscribe(
self.hass,
f"{self.discovery_prefix}main/Heating_Mode",
mode_received,
partial(mode_received, "HEATING"),
1,
)

await mqtt.async_subscribe(
self.hass,
f"{self.discovery_prefix}main/Cooling_Mode",
mode_received,
partial(mode_received, "COOLING"),
1,
)

Expand Down

0 comments on commit 3101b91

Please sign in to comment.