1- ###############################################################################
2- # PumpSteer - ML Adaptive Engine (Learning Version)
3- # Author: Johan Älvedal / GPT-5 Assistant
4- # Description:
51# This version extends the original ML collector with richer data logging,
62# session summaries, and a simple self-learning regression model that
73# derives optimal inertia and aggressiveness based on comfort drift and
84# duration performance.
9- ###############################################################################
5+
106
117from datetime import datetime
128from pathlib import Path
3733
3834
3935class PumpSteerMLCollector :
40- """Collects, analyzes, and learns from PumpSteer operation sessions. """
36+ """Collects, analyzes, and learns from PumpSteer operation sessions"""
4137
4238 def __init__ (self , hass : HomeAssistant , data_file_path : str = ML_DATA_FILE_PATH ):
4339 self .hass = hass
@@ -57,7 +53,7 @@ def __init__(self, hass: HomeAssistant, data_file_path: str = ML_DATA_FILE_PATH)
5753 )
5854
5955 async def async_load_data (self ) -> None :
60- """Load previously saved learning data from disk. """
56+ """Load previously saved learning data from disk"""
6157 await self .hass .async_add_executor_job (self ._load_data_sync )
6258 _LOGGER .info (
6359 "ML: Loaded %d sessions from %s" ,
@@ -104,7 +100,7 @@ def _save_data_sync(self) -> None:
104100 json .dump (data , f , indent = 2 )
105101
106102 def start_session (self , initial_data : Dict [str , Any ]) -> None :
107- """Start a new learning session. """
103+ """Start a new learning session"""
108104 if self .current_session is not None :
109105 self .end_session ("interrupted" )
110106
@@ -119,7 +115,7 @@ def start_session(self, initial_data: Dict[str, Any]) -> None:
119115 )
120116
121117 def update_session (self , update_data : Dict [str , Any ]) -> None :
122- """Add detailed data points to the ongoing session. """
118+ """Add detailed data points to the ongoing session"""
123119 if self .current_session is None :
124120 return
125121
@@ -150,7 +146,7 @@ def update_session(self, update_data: Dict[str, Any]) -> None:
150146 def end_session (
151147 self , reason : str = "normal" , final_data : Optional [Dict [str , Any ]] = None
152148 ) -> None :
153- """Close the session, summarize it, and learn from results. """
149+ """Close the session, summarize it, and learn from results"""
154150 if self .current_session is None :
155151 return
156152
@@ -233,7 +229,7 @@ def end_session(
233229 self .hass .async_create_task (self .async_save_data ())
234230
235231 def _update_learning_model (self ) -> None :
236- """Perform a simple regression analysis on collected sessions. """
232+ """Perform a simple regression analysis on collected sessions"""
237233 heating_sessions = [
238234 s
239235 for s in self .learning_sessions
@@ -315,7 +311,7 @@ def _update_learning_model(self) -> None:
315311 )
316312
317313 def get_recommendations (self ) -> List [str ]:
318- """Generate adaptive recommendations based on learned model. """
314+ """Generate adaptive recommendations based on learned model"""
319315 if not self .model_coefficients :
320316 return ["System is still learning — need more sessions." ]
321317
@@ -346,7 +342,7 @@ def get_recommendations(self) -> List[str]:
346342 return msg
347343
348344 def get_learning_summary (self ) -> Dict [str , Any ]:
349- """Return current learning summary and model state. """
345+ """Return current learning summary and model state"""
350346 return {
351347 "summary" : self .learning_summary ,
352348 "coefficients" : self .model_coefficients ,
@@ -355,7 +351,7 @@ def get_learning_summary(self) -> Dict[str, Any]:
355351 }
356352
357353 async def async_shutdown (self ) -> None :
358- """Graceful shutdown and data save. """
354+ """Graceful shutdown and data save"""
359355 if self .current_session is not None :
360356 self .end_session ("shutdown" )
361357 await self .async_save_data ()
0 commit comments