Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Oct 3, 2023
1 parent c3c30b7 commit fe43af2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
2 changes: 1 addition & 1 deletion custom_components/peaqhvac/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"iot_class": "calculated",
"issue_tracker": "https://github.com/elden1337/hass-peaqhvac/issues",
"requirements": [
"peaqevcore==19.4.2"
"peaqevcore==19.5.1"
],
"version": "2.0.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from datetime import datetime
from datetime import datetime, timedelta
from typing import Tuple

from custom_components.peaqhvac.service.hvac.const import LOW_DEGREE_MINUTES, WAITTIMER_TIMEOUT, HEATBOOST_TIMER
Expand Down Expand Up @@ -76,8 +76,8 @@ def get_current_offset(self, offsets: dict) -> Tuple[int, bool]:
self._hvac.hub.offset.max_price_lower(self._hvac.hub.sensors.get_tempdiff())]):
return OFFSET_MIN_VALUE, True

desired_offset = self._set_calculated_offset(offsets)
_force_update: bool = False
desired_offset = self._set_calculated_offset(offsets, _force_update)

if desired_offset <= 0 and self.current_tempdiff <= 0:
return self._get_lower_offset(), _force_update
Expand All @@ -90,6 +90,8 @@ def get_current_offset(self, offsets: dict) -> Tuple[int, bool]:
desired_offset = lowered_offset
_force_update = True

if _force_update:
self._hvac.hub.observer.broadcast("update operation")
return self._hvac.hub.offset.adjust_to_threshold(desired_offset), _force_update

def _get_lower_offset(self) -> int:
Expand Down Expand Up @@ -149,8 +151,8 @@ def _get_demand(self) -> Demand:
)
return Demand.NoDemand

def _set_calculated_offset(self, offsets: dict) -> int:
self._update_current_offset(offsets=offsets)
def _set_calculated_offset(self, offsets: dict, _force_update: bool) -> int:
self._check_next_hour_offset(offsets=offsets, force_update=_force_update)
ret = sum(
[
self.current_offset,
Expand All @@ -161,39 +163,20 @@ def _set_calculated_offset(self, offsets: dict) -> int:
)
return int(round(ret, 0))

def _update_current_offset(self, offsets: dict) -> None:
hour = datetime.now().hour
if datetime.now().hour < 23 and datetime.now().minute >= 50:
hour = datetime.now().hour + 1
def _check_next_hour_offset(self, offsets: dict, force_update: bool) -> None:
hour = datetime.now().replace(minute=0, second=0, microsecond=0)
if datetime.now().minute >= 40:
hour += timedelta(hours=1)
try:
_offset = offsets[hour]
except:
_LOGGER.warning(
"No Price-offsets have been calculated. Setting base-offset to 0."
)
_offset = 0
self.current_offset = _offset

# def _add_temp_boost(self, pre_offset: int) -> int:
# if self._latest_boost.is_timeout():
# if all(
# [
# self._hvac.hvac_mode == HvacMode.Idle,
# self._hvac.hub.sensors.get_tempdiff() < 0,
# self._hvac.hub.sensors.temp_trend_indoors.gradient <= 0.3,
# ]
# ):
# _LOGGER.debug(
# "adding additional heating since there is no sunwarming happening and house is too cold."
# )
# pre_offset += 1
# self._latest_boost.update()
# else:
# pre_offset += 1
# if self._hvac.hub.sensors.get_tempdiff() > 1:
# pre_offset -= 1
# self._latest_boost.reset()
# return pre_offset
if self.current_offset != _offset:
force_update = True
self.current_offset = _offset

def _add_temp_boost(self, pre_offset: int) -> int:
if not self._latest_boost.is_timeout():
Expand Down
11 changes: 10 additions & 1 deletion custom_components/peaqhvac/service/hvac/interfaces/ihvac.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from abc import abstractmethod
from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Tuple

from custom_components.peaqhvac.service.hvac.house_ventilation import HouseVentilation
Expand Down Expand Up @@ -104,7 +105,7 @@ def update_offset(self) -> bool: # todo: make async
self.get_offsets()
_hvac_offset = self.hvac_offset
new_offset, force_update = self.house_heater.get_current_offset(
self.model.current_offset_dict
self.model.current_offset_dict_combined
)
if new_offset != self.current_offset:
self.current_offset = new_offset
Expand All @@ -122,6 +123,14 @@ def get_offsets(self) -> None: # todo: make async
if ret is not None:
self.model.current_offset_dict = ret[0]
self.model.current_offset_dict_tomorrow = ret[1]
self.model.current_offset_dict_combined = self.set_combined_offsets(ret[0], ret[1])

def set_combined_offsets(self, today: dict, tomorrow: dict) -> dict:
ret:dict[datetime, int] = {}
for hour in range(0, 24):
ret[datetime.now().replace(hour=hour, minute=0, second=0, microsecond=0)] = today.get(hour, 0)
ret[datetime.now().replace(hour=hour, minute=0, second=0,microsecond=0) + timedelta(days=1)] = tomorrow.get(hour, 0)
return ret

@staticmethod
def _get_sensors_for_callback(types: dict) -> list:
Expand Down
1 change: 1 addition & 0 deletions custom_components/peaqhvac/service/models/ihvac_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class IHvacModel:
current_offset: int = 0
current_offset_dict: dict = field(default_factory=lambda: {})
current_offset_dict_tomorrow: dict = field(default_factory=lambda: {})
current_offset_dict_combined: dict = field(default_factory=lambda: {})

listenerentities: list = field(default_factory=lambda: [])

0 comments on commit fe43af2

Please sign in to comment.