Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Sep 15, 2024
1 parent 775ec9a commit 332270e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 79 deletions.
5 changes: 1 addition & 4 deletions custom_components/peaqhvac/sensors/offsetsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ def icon(self) -> str:
return "mdi:stairs"

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

offsetsmodel: OffsetsExportModel = await self._hub.async_offset_export_model()
data: CalculatedOffsetModel = await self._hub.hvac.house_heater.async_calculated_offsetdata(
Expand Down
75 changes: 0 additions & 75 deletions custom_components/peaqhvac/service/hvac/interfaces/ihvac.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(self, hass: HomeAssistant, hub: Hub, observer: IObserver):
self.house_ventilation = HouseVentilation(hvac=self, observer=observer)

self.observer.add(ObserverTypes.OffsetRecalculation, self.async_update_offset)
self.observer.add("water boost start", self.async_boost_water)

@property
@abstractmethod
Expand Down Expand Up @@ -125,7 +124,6 @@ async def async_update_hvac(self) -> None:
await self.house_heater.async_update_demand()
await self.water_heater.async_update_demand()
await self.house_ventilation.async_check_vent_boost()
await self.request_periodic_updates()

async def async_update_offset(self, raw_offset:int|None = None) -> bool:
if raw_offset:
Expand Down Expand Up @@ -192,83 +190,10 @@ def _handle_sensor(self, sensor: str):
return None
return state.state

async def request_periodic_updates(self) -> None:
await self.async_update_ventilation()
if self.hub.hvac.house_heater.control_module:
await self.async_update_heat()
await self.async_perform_periodic_updates()

async def async_update_ventilation(self) -> None:
if self.house_ventilation.booster_update:
if await self.async_ready_to_update(HvacOperations.VentBoost):
_vent_state = int(self.house_ventilation.vent_boost)
if _vent_state != self.update_list.get(HvacOperations.VentBoost, None):
_LOGGER.debug(f"Vent boost state changed to {_vent_state}. Adding to update list.")
self.update_list[HvacOperations.VentBoost] = _vent_state

async def async_update_heat(self) -> None:
if await self.async_update_offset():
if await self.async_ready_to_update(HvacOperations.Offset):
self.update_list[HvacOperations.Offset] = self.model.current_offset

async def async_boost_water(self, target_temp: float) -> None:
if self.hub.hvac.water_heater.control_module:
_LOGGER.debug(f"init water boost process")
self.hub.state_machine.async_create_task(
async_cycle_waterboost(target_temp, self.async_update_system, self.hub))
_LOGGER.debug(f"return from water boost process")

async def async_perform_periodic_updates(self) -> None:
removelist = []
for operation, v in self.update_list.items():
if self.timer_timeout(operation):
if await self.async_update_system(operation=operation, set_val=v):
self.periodic_update_timers[operation] = time.time()
removelist.append(operation)
for r in removelist:
self.update_list.pop(r)

async def async_update_system(self, operation: HvacOperations, set_val: any = None) -> bool:
if self.hub.sensors.peaqhvac_enabled.value:
_value = set_val
if self.hub.sensors.average_temp_outdoors.initialized_percentage > 0.5:
(
call_operation,
params,
domain,
) = self.set_operation_call_parameters(operation, _value)

await self._hass.services.async_call(domain, call_operation, params)
_LOGGER.debug(
f"Requested to update hvac-{operation.name} with value {set_val}. Actual value: {params} for {call_operation}"
)
return True
return False

def timer_timeout(self, operation) -> bool:
return time.time() - self.periodic_update_timers[operation] > UPDATE_INTERVALS[operation]

async def async_ready_to_update(self, operation) -> bool:
match operation:
case HvacOperations.WaterBoost | HvacOperations.VentBoost:
return any(
[
self.timer_timeout(operation),
self.hub.sensors.peaqev_facade.exact_threshold >= 100,
]
)
case HvacOperations.Offset:
if not self.hub.hvac.house_heater.control_module:
return False
if self._force_update:
self._force_update = False
return True
return any(
[
self.timer_timeout(operation),
datetime.now().minute == 0,
self.hub.sensors.peaqev_facade.exact_threshold >= 100,
]
)
case _:
return False

0 comments on commit 332270e

Please sign in to comment.