Skip to content

Commit

Permalink
various adj
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Oct 8, 2024
1 parent 6e860a2 commit d02653c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion custom_components/peaqhvac/service/hub/average.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import statistics
import math

from peaqevcore.common.models.observer_types import ObserverTypes

Expand Down Expand Up @@ -45,7 +46,7 @@ def value(self) -> float:
@value.setter
def value(self, val) -> None:
if isinstance(val, (float, int)):
if round(val, 2) != round(self._value, 2):
if not math.isclose(val, self._value, rel_tol=1e-02):
self._value = val
self._broadcast_changes(self._value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def _update_aux_offset_adjustments(self, max_lower: bool) -> None:

async def async_adjusted_offset(self, current_offset: int) -> Tuple[int, bool]:
async with self._lock:
force_update: bool = False

outdoor_temp = self.hub.sensors.average_temp_outdoors.value
temp_diff = self.hub.sensors.get_tempdiff()

Expand All @@ -69,7 +67,7 @@ async def async_adjusted_offset(self, current_offset: int) -> Tuple[int, bool]:
self._helpers.aux_offset_adjustments[OffsetAdjustments.PeakHour] = 0

offset_data = await self.async_calculated_offsetdata(current_offset)
force_update = self._helpers.temporarily_lower_offset(offset_data, force_update)
force_update = self._helpers.temporarily_lower_offset(offset_data)

if self.current_adjusted_offset != round(offset_data.sum_values(), 0):
ret = adjust_to_threshold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,15 @@ def _keep_compressor_running(self, offsetdata: CalculatedOffsetModel, force_upda
self.aux_offset_adjustments[OffsetAdjustments.KeepCompressorRunning] = 0
return force_update

def temporarily_lower_offset(self, offsetdata: CalculatedOffsetModel, force_update: bool) -> bool:
def temporarily_lower_offset(self, offsetdata: CalculatedOffsetModel) -> bool:
if self._wait_timer_breach.is_timeout():
if any([self._lower_offset_threshold_breach(), self._lower_offset_addon()]):
self.aux_offset_adjustments[OffsetAdjustments.TemporarilyLowerOffset] = -2
offsetdata.current_offset -= 2
force_update = True
elif self._hvac.hub.sensors.peaqev_installed:
if self._hvac.hvac_dm <= self._hvac.hub.options.heating_options.low_degree_minutes and self._hvac.hub.sensors.average_temp_outdoors.value > -10:
self.aux_offset_adjustments[OffsetAdjustments.TemporarilyLowerOffset] = -1
offsetdata.current_offset -= 1
force_update = True
else:
self.aux_offset_adjustments[OffsetAdjustments.TemporarilyLowerOffset] = 0
return force_update
return True
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def async_update_offset(self, raw_offset:int|None = None) -> bool:
self.raw_offset
)
if new_offset != self.model.current_offset:
_LOGGER.debug(f"Offset changed from {self.model.current_offset} to {new_offset}, with raw input {self.raw_offset}.")
self.model.current_offset = new_offset
self._force_update = force_update
if self.model.current_offset != _hvac_offset:
Expand Down

0 comments on commit d02653c

Please sign in to comment.