Skip to content

Commit

Permalink
19.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Jan 3, 2024
1 parent 486ef3e commit d07491a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions peaqevcore/models/hub/currentpeak.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, data_type: type, initval, startpeaks:dict, locale: LocaleData
self._options_peaks: dict = startpeaks
self._value = initval
self._history: dict[str, list[float|int]] = {}
self._locale: LocaleData|None = None
self._locale: LocaleData = locale
self._active: bool = options_use_history
super().__init__(data_type, initval)

Expand All @@ -34,13 +34,10 @@ def _get_peak(self) -> float:
current_mean = mean(self._history.get(current_key, [0]))
max_mean = max(past_mean, current_mean)
if max_mean == past_mean and past_mean > options_start:
print(f"returning last years * factor. past_mean = {past_mean}, options_start = {options_start}, current_mean = {current_mean} given values {self._history.get(current_key, [0])}")
return min(self._history[past_key]) * EXPORT_FACTOR
elif max_mean == current_mean and current_mean > options_start:
print("returning current mean")
return min(self._history[current_key])
else:
print("returning options start")
return options_start
except Exception as e:
_LOGGER.error(f"Error in get_peak: {e}")
Expand All @@ -56,11 +53,10 @@ async def async_update(self, peaks: list) -> None:
def update_history(self, peaks: list) -> None:
_key = self._make_key()
self._history[_key] = peaks
if self._locale:
if self._locale.data.query_model.get_currently_obeserved_peak() > min(peaks):
self._value = self._locale.data.query_model.observed_peak
else:
self._value = self._get_peak()
if self._locale.data.query_model.get_currently_obeserved_peak() > min(peaks):
self._value = self._locale.data.query_model.observed_peak
else:
self._value = self._get_peak()

def import_from_service(self, importdto: dict, current:bool = False) -> dict:
"""Import the dict passed from service or on loading hass"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="peaqevcore",
version="19.6.2",
version="19.6.3",
author="Magnus Eldén",
description="Core types for peaqev car charging",
url="https://github.com/elden1337/peaqev-core",
Expand Down

0 comments on commit d07491a

Please sign in to comment.