Skip to content

Commit

Permalink
More cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexwijn committed May 15, 2023
1 parent a681498 commit 669e4f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions custom_components/sat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ async def reset_integral(_call: ServiceCall):
self.hass.services.async_register(
DOMAIN,
SERVICE_START_OVERSHOOT_PROTECTION_CALCULATION,
partial(start_overshoot_protection_calculation, self)
partial(start_overshoot_protection_calculation, self._coordinator, self)
)

self.hass.services.async_register(
DOMAIN,
SERVICE_SET_OVERSHOOT_PROTECTION_VALUE,
partial(set_overshoot_protection_value, self)
partial(set_overshoot_protection_value, self._coordinator)
)

async def track_sensor_temperature(self, entity_id):
Expand Down
2 changes: 2 additions & 0 deletions custom_components/sat/overshoot_protection.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ async def _wait_for_stable_temperature(self, max_modulation: float) -> float:

if max_modulation != OVERSHOOT_PROTECTION_MAX_RELATIVE_MOD:
await self._coordinator.async_set_control_setpoint(actual_temp)
else:
await self._coordinator.async_set_control_setpoint(OVERSHOOT_PROTECTION_SETPOINT)

previous_average_temp = average_temp
await asyncio.sleep(3)
13 changes: 9 additions & 4 deletions custom_components/sat/services.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from __future__ import annotations

import typing

from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN, SERVICE_SET_TEMPERATURE, HVACMode
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE
from homeassistant.core import ServiceCall

from . import async_reload_entry
from .climate import SatClimate
from .const import *
from .coordinator import SatDataUpdateCoordinator

if typing.TYPE_CHECKING:
from .climate import SatClimate


async def set_overshoot_protection_value(coordinator: SatDataUpdateCoordinator, call: ServiceCall):
"""Service to set the overshoot protection value."""
coordinator.store.update(STORAGE_OVERSHOOT_PROTECTION_VALUE, call.data.get("value"))


async def start_overshoot_protection_calculation(climate: SatClimate, coordinator: SatDataUpdateCoordinator, call: ServiceCall):
async def start_overshoot_protection_calculation(coordinator: SatDataUpdateCoordinator, climate: SatClimate, call: ServiceCall):
"""Service to start the overshoot protection calculation process.
This process will activate overshoot protection by turning on the heater and setting the control setpoint to
Expand All @@ -27,9 +31,10 @@ async def start_overshoot_protection_calculation(climate: SatClimate, coordinato
coordinator.logger.warning("[Overshoot Protection] Calculation already in progress.")
return

climate.overshoot_protection_calculate = True

from .coordinator import DeviceState
climate._device_state = DeviceState.ON
climate._overshoot_protection_calculate = True
await coordinator.async_set_heater_state(DeviceState.ON)

saved_hvac_mode = climate.hvac_mode
saved_target_temperature = climate.target_temperature
Expand Down

0 comments on commit 669e4f7

Please sign in to comment.