Skip to content

Commit

Permalink
#58
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Oct 25, 2023
1 parent c60fbbf commit 0535a50
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,27 @@ def __init__(self, hub):

@property #todo: move to hub
def prices(self) -> list:
if not self._hub.sensors.peaqev_installed:
return self.hours.prices
return self._prices
if self._hub.sensors.peaqev_installed:
return self._prices
return self.hours.prices


@property #todo: move to hub
def prices_tomorrow(self) -> list:
if not self._hub.sensors.peaqev_installed:
return self.hours.prices_tomorrow
return self._prices_tomorrow
if self._hub.sensors.peaqev_installed:
return self._prices_tomorrow
return self.hours.prices_tomorrow


@property
def offsets(self) -> dict:
if not self._hub.sensors.peaqev_installed:
ret = self.hours.offsets
else:
if self._hub.sensors.peaqev_installed:
ret = self._hub.sensors.peaqev_facade.offsets
if len(ret) == 0 or not ret:
_LOGGER.warning("Tried to get offsets from peaqev, but got nothing")
return ret
ret = self.hours.offsets
_LOGGER.debug("offsets from core: %s", ret)
return ret


Expand Down Expand Up @@ -82,8 +85,8 @@ async def async_update_prices(self, prices) -> None:
self._prices = prices[0]
if self._prices_tomorrow != prices[1]:
self._prices_tomorrow = prices[1]
self._set_offset()
self._update_model()
await self.async_set_offset()
await self.async_update_model()

def max_price_lower(self, tempdiff: float) -> bool:
"""Temporarily lower to -10 if this hour is a peak for today and temp > set-temp + 0.5C"""
Expand Down Expand Up @@ -116,6 +119,9 @@ def _calculate_offset_per_day(self, day_values: dict, weather_adjusted_today: di
else:
return list(weather_adjusted_today.values())

async def async_set_offset(self):
self._set_offset()

def _set_offset(self) -> None:
if all([self.prices is not None, self.model.prognosis is not None]):
self.model.raw_offsets = self._update_offset()
Expand Down Expand Up @@ -149,7 +155,7 @@ def adjust_to_threshold(self, offsetdata: CalculatedOffsetModel) -> int:
)
return int(round(ret, 0))

def _update_model(self) -> None:
async def async_update_model(self) -> None:
self.model.peaks_today = identify_peaks(self.prices)
self.model.peaks_tomorrow = identify_peaks(self.prices_tomorrow)

Expand Down

0 comments on commit 0535a50

Please sign in to comment.