Skip to content

Commit

Permalink
Merge pull request #26 from vincentwolsink/water_air_detection
Browse files Browse the repository at this point in the history
Update water boiler detection. Simplify code.
  • Loading branch information
vincentwolsink authored Aug 14, 2023
2 parents 29b0474 + 7e054bc commit 5517486
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
41 changes: 17 additions & 24 deletions custom_components/aguaiot/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -52,6 +54,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 @@ -104,34 +111,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 @@ -188,14 +183,12 @@ 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 @@ -34,6 +34,9 @@
AGUA_STATUS_OFF: HVACAction.OFF,
}

DEVICE_TYPE_AIR = "air"
DEVICE_TYPE_WATER = "water"

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

0 comments on commit 5517486

Please sign in to comment.