Skip to content

Commit

Permalink
async conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Sep 10, 2024
1 parent 103a14b commit e48ffe3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 29 deletions.
4 changes: 2 additions & 2 deletions custom_components/peaqhvac/sensors/offsetsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def icon(self) -> str:
return "mdi:stairs"

async def async_update(self) -> None:
self._state = self._hub.hvac.house_heater.get_adjusted_offset(
self._state = await self._hub.hvac.house_heater.async_adjusted_offset(
self._hub.hvac.model.current_offset
)[0]

offsetsmodel: OffsetsExportModel = await self._hub.async_offset_export_model()
data: CalculatedOffsetModel = self._hub.hvac.house_heater.get_calculated_offsetdata(
data: CalculatedOffsetModel = await self._hub.hvac.house_heater.async_calculated_offsetdata(
self._hub.hvac.model.current_offset
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _update_aux_offset_adjustments(self, max_lower: bool) -> None:
self._helpers.aux_offset_adjustments[OffsetAdjustments.PeakHour] = OFFSET_MIN_VALUE if max_lower else 0
self.current_adjusted_offset = OFFSET_MIN_VALUE

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

outdoor_temp = self.hub.sensors.average_temp_outdoors.value
Expand All @@ -66,7 +66,7 @@ def get_adjusted_offset(self, current_offset: int) -> Tuple[int, bool]:

self._helpers.aux_offset_adjustments[OffsetAdjustments.PeakHour] = 0

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

if self.current_adjusted_offset != round(offsetdata.sum_values(), 0):
Expand All @@ -93,7 +93,7 @@ def _current_tolerances(self, determinator: bool, current_offset: int, adjust_to
tolerances = _min, _max
return tolerances[0] if (determinator > 0 or determinator is True) else tolerances[1]

def get_calculated_offsetdata(self, current_offset: int) -> CalculatedOffsetModel:
async def async_calculated_offsetdata(self, current_offset: int) -> CalculatedOffsetModel:
tempdiff = get_tempdiff_inverted(
current_offset,
self.hub.sensors.get_tempdiff(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def get_tempdiff_inverted(current_offset: int, temp_diff: float, determine_toler
"""get the inverted tolerance in this case"""
_tolerance = determine_tolerance(diff * -1, current_offset)
ret = floor(abs(diff) / _tolerance) * -1
if abs(diff) > 10: #debug bad offsets
_LOGGER.debug(f"Tempdiff is {diff}, tolerance is {_tolerance}, ret is {ret}. Current offset is {current_offset}")
if diff > 0:
return ret
return ret * -1
Expand Down
16 changes: 8 additions & 8 deletions custom_components/peaqhvac/service/hvac/house_ventilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ def _check_hvac_fan_speed(self) -> None:
async def async_check_vent_boost(self, caller=None) -> None:
if self._hvac.hub.sensors.temp_trend_indoors.samples > 0 and time.time() - self._wait_timer_boost.value > WAITTIMER_VENT:
if self._vent_boost_warmth():
self._vent_boost_start("Vent boosting because of warmth.")
await self.async_vent_boost_start("Vent boosting because of warmth.")
return
elif self._vent_boost_night_cooling():
self._vent_boost_start("Vent boost night cooling")
if self._vent_boost_night_cooling():
await self.async_vent_boost_start("Vent boost night cooling")
return
elif self._vent_boost_low_dm():
self._vent_boost_start("Vent boosting because of low degree minutes.")
if self._vent_boost_low_dm():
await self.async_vent_boost_start("Vent boosting because of low degree minutes.")
return
if any([
(self._hvac.hvac_dm > self._hvac.hub.options.heating_options.low_degree_minutes + 100 and self._hvac.hub.sensors.average_temp_outdoors.value < self._hvac.hub.options.heating_options.outdoor_temp_stop_heating),
self._hvac.hub.sensors.average_temp_outdoors.value < self._hvac.hub.options.heating_options.very_cold_temp
]) and self.vent_boost:
_LOGGER.debug(f"recovered dm or very cold. stopping went boost. dm: {self._hvac.hvac_dm} > {self._hvac.hub.options.heating_options.low_degree_minutes + 100}, temp: {self._hvac.hub.sensors.average_temp_outdoors.value}")
self.vent_boost = False
self.observer.broadcast(ObserverTypes.UpdateOperation)
await self.observer.async_broadcast(ObserverTypes.UpdateOperation)

def _vent_boost_warmth(self) -> bool:
return all(
Expand Down Expand Up @@ -107,9 +107,9 @@ def _vent_boost_low_dm(self) -> bool:
]
)

def _vent_boost_start(self, msg) -> None:
async def async_vent_boost_start(self, msg) -> None:
if not self.vent_boost and self.control_module:
_LOGGER.debug(msg)
self._wait_timer_boost.update()
self.vent_boost = True
self.observer.broadcast(ObserverTypes.UpdateOperation)
await self.observer.async_broadcast(ObserverTypes.UpdateOperation)
14 changes: 1 addition & 13 deletions custom_components/peaqhvac/service/hvac/interfaces/ihvac.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ async def async_update_offset(self) -> bool:
if len(self.hub.sensors.peaqev_facade.offsets.get("today", {})) < 20:
return ret
try:
#self.get_offsets()
_hvac_offset = self.hvac_offset
new_offset, force_update = self.house_heater.get_adjusted_offset(self.model.current_offset)
new_offset, force_update = await self.house_heater.async_adjusted_offset(self.model.current_offset)
if new_offset != self.model.current_offset:
self.model.current_offset = new_offset
self._force_update = force_update
Expand All @@ -149,17 +148,6 @@ async def async_update_offset(self) -> bool:
finally:
return ret

# def get_offsets(self) -> None: # todo: make async
# ret = self.hub.offset.get_offset()
# if ret is not None:
# self.model.current_offset_dict = {k: v for k, v in ret.calculated_offsets.items() if
# k.date() == datetime.now().date()}
# self.model.current_offset_dict_tomorrow = {k: v for k, v in ret.calculated_offsets.items() if
# k.date() == datetime.now().date() + timedelta(days=1)}
# self.model.current_offset_dict_combined = ret.calculated_offsets
# else:
# _LOGGER.debug("get_offsets returned None where it should not")

@staticmethod
def _get_sensors_for_callback(types: dict) -> list:
ret = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ async def async_cycle_waterboost(target_temp: float, async_update_system: callab
await async_update_system(operation=HvacOperations.WaterBoost, set_val=0)
await asyncio.sleep(180)
await async_update_system(operation=HvacOperations.WaterBoost, set_val=0)
hub.observer.broadcast("water boost done")
await hub.observer.async_broadcast("water boost done")
hub.state_machine.bus.fire("peaqhvac.water_heater_warning", {"new": False})
return True

0 comments on commit e48ffe3

Please sign in to comment.