Skip to content

Commit

Permalink
Update water boiler detection. Simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwolsink committed Aug 13, 2023
1 parent cce4c63 commit 993f875
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
38 changes: 14 additions & 24 deletions custom_components/aguaiot/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
AGUA_STATUS_OFF,
AGUA_STATUS_ON,
CURRENT_HVAC_MAP_AGUA_HEAT,
DEVICE_TYPE_AIR,
DEVICE_TYPE_WATER,
)
from py_agua_iot import Error as AguaIOTError

Expand All @@ -56,6 +58,11 @@ def __init__(self, coordinator, device):
CoordinatorEntity.__init__(self, coordinator)
self._device = device

if getattr(self._device, "water_temperature", 0) > 0:
self._device_type = DEVICE_TYPE_WATER
else:
self._device_type = DEVICE_TYPE_AIR

@property
def supported_features(self):
"""Return the list of supported features."""
Expand Down Expand Up @@ -108,34 +115,22 @@ def temperature_unit(self):
@property
def min_temp(self):
"""Return the minimum temperature to set."""
min_temp = self._device.min_air_temp
if min_temp is None:
min_temp = self._device.min_water_temp
return min_temp
return getattr(self._device, f"min_{self._device_type}_temp")

@property
def max_temp(self):
"""Return the maximum temperature to set."""
max_temp = self._device.max_air_temp
if max_temp is None:
max_temp = self._device.max_water_temp
return max_temp
return getattr(self._device, f"max_{self._device_type}_temp")

@property
def current_temperature(self):
"""Return the current temperature."""
temp = self._device.air_temperature
if temp is None:
temp = self._device.water_temperature
return temp
return getattr(self._device, f"{self._device_type}_temperature")

@property
def target_temperature(self):
"""Return the temperature we try to reach."""
set_temp = self._device.set_air_temperature
if set_temp is None:
set_temp = self._device.set_water_temperature
return set_temp
return getattr(self._device, f"set_{self._device_type}_temperature")

@property
def hvac_mode(self):
Expand Down Expand Up @@ -192,14 +187,9 @@ async def async_set_temperature(self, **kwargs):
return

try:
if self._device.air_temperature is not None:
await self.hass.async_add_executor_job(
setattr, self._device, "set_air_temperature", temperature
)
elif self._device.water_temperature is not None:
await self.hass.async_add_executor_job(
setattr, self._device, "set_water_temperature", temperature
)
await self.hass.async_add_executor_job(
setattr, self._device, f"set_{self._device_type}_temperature", temperature
)
await self.coordinator.async_request_refresh()
except (ValueError, AguaIOTError) as err:
_LOGGER.error("Failed to set temperature, error: %s", err)
Expand Down
3 changes: 3 additions & 0 deletions custom_components/aguaiot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
AGUA_STATUS_OFF: CURRENT_HVAC_OFF,
}

DEVICE_TYPE_AIR = "air"
DEVICE_TYPE_WATER = "water"

PLATFORMS = [
Platform.SENSOR,
Platform.CLIMATE,
Expand Down

0 comments on commit 993f875

Please sign in to comment.