Skip to content

Commit

Permalink
remove temp extremas
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Sep 14, 2024
1 parent 498decb commit 872a5cb
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 40 deletions.
3 changes: 0 additions & 3 deletions custom_components/peaqhvac/sensors/offsetsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def __init__(self, hub, entry_id, name):
self._raw_offsets = []
self._current_offset = None
self._tempdiff_offset = None
self._tempextremas_offset = None
self._temptrend_offset = None
self._peaks_today = []
self._peaks_tomorrow = []
Expand Down Expand Up @@ -51,7 +50,6 @@ async def async_update(self) -> None:

self._current_offset = self._hub.offset.current_offset
self._tempdiff_offset = data.current_tempdiff
self._tempextremas_offset = data.current_temp_extremas
self._temptrend_offset = data.current_temp_trend_offset
self._aux_dict = self._hub.hvac.house_heater.aux_offset_adjustments

Expand All @@ -60,7 +58,6 @@ def extra_state_attributes(self) -> dict:
ret = {
"Current hour offset": self._current_offset,
"Tempdiff offset": self._tempdiff_offset,
"Temp extremas offset": self._tempextremas_offset,
"Temp trend offset": self._temptrend_offset,
"Today": self._offsets,
"Tomorrow": self._offsets_tomorrow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from custom_components.peaqhvac.service.hvac.house_heater.house_heater_helpers import HouseHeaterHelpers
from custom_components.peaqhvac.service.hvac.house_heater.models.calculated_offset import CalculatedOffsetModel
from custom_components.peaqhvac.service.hvac.house_heater.models.offset_adjustments import OffsetAdjustments
from custom_components.peaqhvac.service.hvac.house_heater.temperature_helper import get_tempdiff_inverted, \
get_temp_extremas, get_temp_trend_offset
from custom_components.peaqhvac.service.hvac.house_heater.temperature_helper import get_tempdiff_inverted, get_temp_trend_offset
from custom_components.peaqhvac.service.hvac.interfaces.iheater import IHeater
from custom_components.peaqhvac.service.hvac.offset.offset_utils import adjust_to_threshold
from custom_components.peaqhvac.service.models.enums.demand import Demand
Expand Down Expand Up @@ -99,12 +98,6 @@ async def async_calculated_offsetdata(self, current_offset: int) -> CalculatedOf
self.hub.sensors.get_tempdiff(),
self._current_tolerances
)
tempextremas = get_temp_extremas(
current_offset,
[self.hub.sensors.set_temp_indoors.adjusted_temp - t for t in
self.hub.sensors.average_temp_indoors.all_values],
self._current_tolerances
)
temptrend = get_temp_trend_offset(
self.hub.sensors.temp_trend_indoors.is_clean,
self.hub.sensors.predicted_temp,
Expand All @@ -113,7 +106,6 @@ async def async_calculated_offsetdata(self, current_offset: int) -> CalculatedOf

return CalculatedOffsetModel(current_offset=current_offset,
current_tempdiff=tempdiff,
current_temp_extremas=tempextremas,
current_temp_trend_offset=temptrend)

async def async_update_operation(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class CalculatedOffsetModel:
current_offset: int
current_tempdiff: float
current_temp_extremas: float
current_temp_trend_offset: float

def sum_values(self, extra_current: int = None) -> float:
Expand All @@ -16,7 +15,6 @@ def sum_values(self, extra_current: int = None) -> float:
[
current,
self.current_tempdiff,
self.current_temp_extremas,
self.current_temp_trend_offset,
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ def get_tempdiff_inverted(current_offset: int, temp_diff: float, determine_toler
return ret * -1


def get_temp_extremas(current_offset: int, all_temps: list, determine_tolerance: callable) -> float:
diffs = all_temps
cold_diffs, hot_diffs = [d for d in diffs if d > 0] + [0], [d for d in diffs if d < 0] + [0]
hot_large = abs(min(hot_diffs))
cold_large = abs(max(cold_diffs))
if hot_large == cold_large:
return 0
is_cold = cold_large > hot_large
tolerance = determine_tolerance(is_cold, current_offset, False)
if is_cold:
ret = _temp_extremas_return(cold_diffs, tolerance)
return ret / max(len(hot_diffs), 1)
ret = _temp_extremas_return(hot_diffs, tolerance)
return ret / max(len(cold_diffs), 1)


def get_temp_trend_offset(temp_trend_is_clean: bool, predicted_temp: float, adjusted_temp: float) -> float:
if not temp_trend_is_clean:
return 0
Expand Down
2 changes: 1 addition & 1 deletion custom_components/peaqhvac/test/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_adjust_to_treshold_no_exceeding_values():
)

for k,v in smooth.items():
model = CalculatedOffsetModel(current_offset=v, current_tempdiff=random.uniform(-1, 1), current_temp_extremas=random.uniform(-1, 1), current_temp_trend_offset=random.uniform(-1, 1))
model = CalculatedOffsetModel(current_offset=v, current_tempdiff=random.uniform(-1, 1), current_temp_trend_offset=random.uniform(-1, 1))
adj = adjust_to_threshold(model, 0, _tolerance)
assert abs(adj) <= _tolerance

10 changes: 1 addition & 9 deletions custom_components/peaqhvac/test/test_temperature_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from ..service.hub.target_temp import adjusted_tolerances
from ..service.hvac.house_heater.temperature_helper import get_temp_extremas, get_tempdiff_inverted
from ..service.hvac.house_heater.temperature_helper import get_tempdiff_inverted

MINTOLERANCE = 0.2
MAXTOLERANCE = 0.5
Expand All @@ -13,14 +13,6 @@ def _current_tolerances(determinator: bool, current_offset: int, adjust_toleranc
tolerances = MINTOLERANCE, MAXTOLERANCE
return tolerances[0] if (determinator > 0 or determinator is True) else tolerances[1]

def test_temp_extremas_one_positive():
ter = get_temp_extremas(0, [0, 0, 0, 0, 1, 0, 0, 0, 0], _current_tolerances)
assert ter == 0.8

def test_temp_extremas_one_negative():
ter = get_temp_extremas(0, [0, 0, 0, 0, -1, 0, 0, 0, 0], _current_tolerances)
assert ter == -0.5


def test_tempdiff_cold():
tempdiff = -0.5
Expand Down

0 comments on commit 872a5cb

Please sign in to comment.