Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #151 from oischinger/precisionminmax
Browse files Browse the repository at this point in the history
Use temp min/max/step from API
  • Loading branch information
oischinger authored Aug 23, 2023
2 parents 17d9d81 + aae7114 commit 062073e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
29 changes: 23 additions & 6 deletions custom_components/vicare/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
ATTR_TEMPERATURE,
PRECISION_HALVES,
PRECISION_TENTHS,
PRECISION_WHOLE,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -201,6 +200,9 @@ def __init__(self, name, api, circuit, device_config):
self._current_temperature = None
self._current_program = None
self._current_action = None
self._min_temp = None
self._max_temp = None
self._current_stepping = None
self.update()

@property
Expand Down Expand Up @@ -242,6 +244,21 @@ def update(self) -> None:
else:
self._current_temperature = None

with suppress(PyViCareNotSupportedFeatureError):
self._min_temp = self._circuit.getActiveProgramMinTemperature()
if not self._min_temp:
self._min_temp = VICARE_TEMP_HEATING_MIN

with suppress(PyViCareNotSupportedFeatureError):
self._max_temp = self._circuit.getActiveProgramMaxTemperature()
if not self._max_temp:
self._max_temp = VICARE_TEMP_HEATING_MAX

with suppress(PyViCareNotSupportedFeatureError):
self._current_stepping = self._circuit.getActiveProgramStepping()
if not self._current_stepping:
self._current_stepping = PRECISION_HALVES

with suppress(PyViCareNotSupportedFeatureError):
self._current_program = self._circuit.getActiveProgram()

Expand Down Expand Up @@ -359,17 +376,17 @@ def hvac_action(self) -> HVACAction:
@property
def min_temp(self):
"""Return the minimum temperature."""
return VICARE_TEMP_HEATING_MIN
return self._min_temp

@property
def max_temp(self):
"""Return the maximum temperature."""
return VICARE_TEMP_HEATING_MAX
return self._max_temp

@property
def target_temperature_step(self) -> float:
"""Set target temperature step to wholes."""
return PRECISION_WHOLE
"""Get current stepping."""
return self._current_stepping

def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperatures."""
Expand Down Expand Up @@ -516,7 +533,7 @@ def hvac_modes(self) -> list[HVACMode]:

@property
def target_temperature_step(self) -> float:
"""Set target temperature step to wholes."""
"""Set target temperature step to halves."""
return PRECISION_HALVES

def set_temperature(self, **kwargs: Any) -> None:
Expand Down
34 changes: 21 additions & 13 deletions custom_components/vicare/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
WaterHeaterEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_TENTHS,
PRECISION_WHOLE,
UnitOfTemperature,
)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -30,6 +25,9 @@

_LOGGER = logging.getLogger(__name__)

VICARE_TEMP_WATER_MIN = 10
VICARE_TEMP_WATER_MAX = 60

VICARE_MODE_DHW = "dhw"
VICARE_MODE_HEATING = "heating"
VICARE_MODE_DHWANDHEATING = "dhwAndHeating"
Expand All @@ -38,9 +36,6 @@
VICARE_MODE_FORCEDNORMAL = "forcedNormal"
VICARE_MODE_OFF = "standby"

VICARE_TEMP_WATER_MIN = 10
VICARE_TEMP_WATER_MAX = 60

OPERATION_MODE_ON = "on"
OPERATION_MODE_OFF = "off"

Expand Down Expand Up @@ -86,7 +81,7 @@ async def async_setup_entry(
class ViCareWater(WaterHeaterEntity):
"""Representation of the ViCare domestic hot water device."""

_attr_precision = PRECISION_TENTHS
_attr_precision = PRECISION_WHOLE
_attr_supported_features = WaterHeaterEntityFeature.TARGET_TEMPERATURE

def __init__(self, name, api, circuit, device_config):
Expand All @@ -100,6 +95,9 @@ def __init__(self, name, api, circuit, device_config):
self._target_temperature = None
self._current_temperature = None
self._current_mode = None
self._min_temp = None
self._max_temp = None
self.update()

def update(self) -> None:
"""Let HA know there has been an update from the ViCare API."""
Expand All @@ -117,6 +115,16 @@ def update(self) -> None:
with suppress(PyViCareNotSupportedFeatureError):
self._current_mode = self._circuit.getActiveMode()

with suppress(PyViCareNotSupportedFeatureError):
self._min_temp = self._api.getDomesticHotWaterMinTemperature()
if not self._min_temp:
self._min_temp = VICARE_TEMP_WATER_MIN

with suppress(PyViCareNotSupportedFeatureError):
self._max_temp = self._api.getDomesticHotWaterMaxTemperature()
if not self._max_temp:
self._max_temp = VICARE_TEMP_WATER_MAX

except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
_LOGGER.error("Unable to retrieve data from ViCare server")
except PyViCareRateLimitError as limit_exception:
Expand Down Expand Up @@ -176,16 +184,16 @@ def set_temperature(self, **kwargs: Any) -> None:
@property
def min_temp(self):
"""Return the minimum temperature."""
return VICARE_TEMP_WATER_MIN
return self._min_temp

@property
def max_temp(self):
"""Return the maximum temperature."""
return VICARE_TEMP_WATER_MAX
return self._max_temp

@property
def target_temperature_step(self) -> float:
"""Set target temperature step to wholes."""
"""Get current stepping."""
return PRECISION_WHOLE

@property
Expand Down

1 comment on commit 062073e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.