Skip to content

Commit 8cb464d

Browse files
committed
Drop the need for OvershootProtection calibration
1 parent 7afe971 commit 8cb464d

File tree

3 files changed

+0
-434
lines changed

3 files changed

+0
-434
lines changed

custom_components/sat/config_flow.py

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from homeassistant import config_entries
88
from homeassistant.components import sensor, switch, valve, weather, binary_sensor, climate, input_boolean
99
from homeassistant.config_entries import ConfigEntry
10-
from homeassistant.const import ATTR_ENTITY_ID
1110
from homeassistant.core import callback
1211
from homeassistant.helpers import selector, entity_registry
1312
from homeassistant.helpers.selector import SelectSelectorMode, SelectOptionDict
@@ -22,7 +21,6 @@
2221
from .entry_data import SatConfig, SatMode
2322
from .helpers import calculate_default_maximum_setpoint, snake_case
2423
from .manufacturer import ManufacturerFactory, MANUFACTURERS
25-
from .overshoot_protection import OvershootProtection
2624
from .types import HeatingSystem, HeatingMode
2725
from .validators import valid_serial_device
2826

@@ -36,10 +34,6 @@ class SatFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
3634
VERSION = 10
3735
MINOR_VERSION = 0
3836

39-
calibration = None
40-
previous_hvac_mode = None
41-
overshoot_protection_value = None
42-
4337
def __init__(self):
4438
"""Initialize."""
4539
self.data = {}
@@ -51,11 +45,6 @@ def __init__(self):
5145
def async_get_options_flow(config_entry: ConfigEntry):
5246
return SatOptionsFlowHandler(config_entry)
5347

54-
@callback
55-
def async_remove(self) -> None:
56-
if self.calibration is not None:
57-
self.calibration.cancel()
58-
5948
async def async_step_user(self, _user_input: Optional[dict[str, Any]] = None):
6049
"""Handle user flow."""
6150
menu_options = [
@@ -435,9 +424,6 @@ async def async_step_areas(self, _user_input: Optional[dict[str, Any]] = None):
435424
if _user_input.get(CONF_THERMOSTAT) is None:
436425
self.data[CONF_THERMOSTAT] = None
437426

438-
if (await self.async_create_coordinator()).supports_setpoint_management:
439-
return await self.async_step_calibrate_system()
440-
441427
return await self.async_step_automatic_gains()
442428

443429
return self.async_show_form(
@@ -474,106 +460,6 @@ async def async_step_automatic_gains(self, _user_input: Optional[dict[str, Any]]
474460
data_schema=vol.Schema({vol.Required(CONF_AUTOMATIC_GAINS, default=True): bool})
475461
)
476462

477-
async def async_step_calibrate_system(self, _user_input: Optional[dict[str, Any]] = None):
478-
return self.async_show_menu(
479-
step_id="calibrate_system",
480-
menu_options=["calibrate", "overshoot_protection", "pid_controller"]
481-
)
482-
483-
async def async_step_calibrate(self, _user_input: Optional[dict[str, Any]] = None):
484-
# Let's see if we have already been configured before
485-
entities = entity_registry.async_get(self.hass)
486-
climate_id = entities.async_get_entity_id(climate.DOMAIN, DOMAIN, self.config_entry.entry_id)
487-
488-
async def start_calibration():
489-
try:
490-
coordinator = await self.async_create_coordinator()
491-
await coordinator.async_setup()
492-
493-
overshoot_protection = OvershootProtection(coordinator, self.data.get(CONF_HEATING_SYSTEM))
494-
self.overshoot_protection_value = await overshoot_protection.calculate()
495-
496-
await coordinator.async_will_remove_from_hass()
497-
except asyncio.TimeoutError:
498-
_LOGGER.warning("Timed out during overshoot protection calculation.")
499-
except asyncio.CancelledError:
500-
_LOGGER.warning("Cancelled overshoot protection calculation.")
501-
502-
if not self.calibration:
503-
self.calibration = self.hass.async_create_task(
504-
start_calibration()
505-
)
506-
507-
# Make sure to turn off the existing climate if we found one
508-
if climate_id is not None:
509-
self.previous_hvac_mode = self.hass.states.get(climate_id).state
510-
data = {ATTR_ENTITY_ID: climate_id, climate.ATTR_HVAC_MODE: climate.HVACMode.OFF}
511-
await self.hass.services.async_call(climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True)
512-
513-
# Make sure all climate valves are open
514-
for entity_id in self.data.get(CONF_RADIATORS, []) + self.data.get(CONF_ROOMS, []):
515-
data = {ATTR_ENTITY_ID: entity_id, climate.ATTR_HVAC_MODE: climate.HVACMode.HEAT}
516-
await self.hass.services.async_call(climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True)
517-
518-
return self.async_show_progress(
519-
step_id="calibrate",
520-
progress_task=self.calibration,
521-
progress_action="calibration",
522-
)
523-
524-
if self.overshoot_protection_value is None:
525-
return self.async_abort(reason="unable_to_calibrate")
526-
527-
self._enable_overshoot_protection(
528-
self.overshoot_protection_value
529-
)
530-
531-
self.calibration = None
532-
self.overshoot_protection_value = None
533-
534-
# Make sure to restore the mode after we are done
535-
if climate_id is not None:
536-
data = {ATTR_ENTITY_ID: climate_id, climate.ATTR_HVAC_MODE: self.previous_hvac_mode}
537-
await self.hass.services.async_call(climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True)
538-
539-
return self.async_show_progress_done(next_step_id="calibrated")
540-
541-
async def async_step_calibrated(self, _user_input: Optional[dict[str, Any]] = None):
542-
return self.async_show_menu(
543-
step_id="calibrated",
544-
description_placeholders=self.data,
545-
menu_options=["calibrate", "finish"],
546-
)
547-
548-
async def async_step_overshoot_protection(self, _user_input: Optional[dict[str, Any]] = None):
549-
if _user_input is not None:
550-
self._enable_overshoot_protection(
551-
_user_input[CONF_MINIMUM_SETPOINT]
552-
)
553-
554-
if self.data[CONF_MODE] == SatMode.SIMULATOR:
555-
return await self.async_step_finish()
556-
557-
return await self.async_step_manufacturer()
558-
559-
return self.async_show_form(
560-
last_step=False,
561-
step_id="overshoot_protection",
562-
data_schema=vol.Schema({
563-
vol.Required(
564-
CONF_MINIMUM_SETPOINT,
565-
default=self.data.get(CONF_MINIMUM_SETPOINT, OPTIONS_DEFAULTS[CONF_MINIMUM_SETPOINT]),
566-
): selector.NumberSelector(
567-
selector.NumberSelectorConfig(
568-
min=MINIMUM_SETPOINT,
569-
max=MAXIMUM_SETPOINT,
570-
step=1,
571-
unit_of_measurement="°C",
572-
)
573-
),
574-
})
575-
)
576-
577463
async def async_step_pid_controller(self, _user_input: Optional[dict[str, Any]] = None):
578464
self.data[CONF_AUTOMATIC_GAINS] = False
579465

@@ -671,11 +557,6 @@ def _create_mqtt_form(self, step_id: str, default_topic: Optional[str] = None, d
671557
data_schema=vol.Schema(schema),
672558
)
673559

674-
def _enable_overshoot_protection(self, overshoot_protection_value: float):
675-
"""Store the value and enable overshoot protection."""
676-
self.data[CONF_OVERSHOOT_PROTECTION] = True
677-
self.data[CONF_MINIMUM_SETPOINT] = overshoot_protection_value
678-
679560

680561
class SatOptionsFlowHandler(config_entries.OptionsFlow):
681562
"""Config flow options handler."""

custom_components/sat/overshoot_protection.py

Lines changed: 0 additions & 196 deletions
This file was deleted.

0 commit comments

Comments
 (0)