update: clean up code formatting

This commit is contained in:
Aaron 2025-11-10 18:59:18 -05:00
parent 95e159ee5d
commit b3c56864ac

View File

@ -2,7 +2,7 @@ import time # type: ignore
class ScheduleMonitor: class ScheduleMonitor:
"""Monitor that checks and applies temperature schedules.""" """Monitor that checks and applies temperature schedules."""
def __init__(self, ac_monitor, heater_monitor, config, interval=60): def __init__(self, ac_monitor, heater_monitor, config, interval=60):
""" """
Initialize schedule monitor. Initialize schedule monitor.
@ -21,7 +21,7 @@ class ScheduleMonitor:
self.current_schedule = None self.current_schedule = None
self.last_applied_schedule = None self.last_applied_schedule = None
self.temp_hold_duration = config.get('temp_hold_duration', 3600) # Use config value, default 1 hour self.temp_hold_duration = config.get('temp_hold_duration', 3600) # Use config value, default 1 hour
def should_run(self): def should_run(self):
"""Check if it's time to run this monitor.""" """Check if it's time to run this monitor."""
current_time = time.time() current_time = time.time()
@ -29,7 +29,7 @@ class ScheduleMonitor:
self.last_check = current_time self.last_check = current_time
return True return True
return False return False
def _parse_time(self, time_str): def _parse_time(self, time_str):
"""Convert time string 'HH:MM' to minutes since midnight.""" """Convert time string 'HH:MM' to minutes since midnight."""
try: try:
@ -39,12 +39,12 @@ class ScheduleMonitor:
return hours * 60 + minutes return hours * 60 + minutes
except: except:
return None return None
def _get_current_minutes(self): def _get_current_minutes(self):
"""Get current time in minutes since midnight.""" """Get current time in minutes since midnight."""
t = time.localtime() t = time.localtime()
return t[3] * 60 + t[4] # hours * 60 + minutes return t[3] * 60 + t[4] # hours * 60 + minutes
def _find_active_schedule(self): def _find_active_schedule(self):
"""Find which schedule should be active right now.""" """Find which schedule should be active right now."""
if not self.config.get('schedule_enabled', False): if not self.config.get('schedule_enabled', False):
@ -79,7 +79,7 @@ class ScheduleMonitor:
active_schedule = sorted_schedules[-1][1] active_schedule = sorted_schedules[-1][1]
return active_schedule return active_schedule
def _apply_schedule(self, schedule): def _apply_schedule(self, schedule):
"""Apply a schedule's settings to the monitors.""" """Apply a schedule's settings to the monitors."""
if not schedule: if not schedule:
@ -93,20 +93,20 @@ class ScheduleMonitor:
# Update AC settings if provided # Update AC settings if provided
if 'ac_target' in schedule: if 'ac_target' in schedule:
self.ac_monitor.target_temp = float(schedule['ac_target']) self.ac_monitor.target_temp = float(schedule['ac_target'])
self.config['ac_target'] = float(schedule['ac_target']) # <-- ADD THIS self.config['ac_target'] = float(schedule['ac_target'])
if 'ac_swing' in schedule: if 'ac_swing' in schedule:
self.ac_monitor.temp_swing = float(schedule['ac_swing']) self.ac_monitor.temp_swing = float(schedule['ac_swing'])
self.config['ac_swing'] = float(schedule['ac_swing']) # <-- ADD THIS self.config['ac_swing'] = float(schedule['ac_swing'])
# Update heater settings if provided # Update heater settings if provided
if 'heater_target' in schedule: if 'heater_target' in schedule:
self.heater_monitor.target_temp = float(schedule['heater_target']) self.heater_monitor.target_temp = float(schedule['heater_target'])
self.config['heater_target'] = float(schedule['heater_target']) # <-- ADD THIS self.config['heater_target'] = float(schedule['heater_target'])
if 'heater_swing' in schedule: if 'heater_swing' in schedule:
self.heater_monitor.temp_swing = float(schedule['heater_swing']) self.heater_monitor.temp_swing = float(schedule['heater_swing'])
self.config['heater_swing'] = float(schedule['heater_swing']) # <-- ADD THIS self.config['heater_swing'] = float(schedule['heater_swing'])
# Save updated config to file so targets persist # Save updated config to file so targets persist
try: try:
@ -142,7 +142,7 @@ class ScheduleMonitor:
except Exception as e: except Exception as e:
print("Error applying schedule: {}".format(e)) print("Error applying schedule: {}".format(e))
def run(self): def run(self):
"""Check if schedule needs to be updated.""" """Check if schedule needs to be updated."""
@ -181,7 +181,7 @@ class ScheduleMonitor:
active_schedule = self._find_active_schedule() active_schedule = self._find_active_schedule()
if active_schedule: if active_schedule:
self._apply_schedule(active_schedule) self._apply_schedule(active_schedule)
def reload_config(self, new_config): def reload_config(self, new_config):
"""Reload configuration (called when settings are updated via web).""" """Reload configuration (called when settings are updated via web)."""
self.config = new_config self.config = new_config