feat: Enhance schedule application by saving updated config to file and ensuring target persistence

This commit is contained in:
Aaron 2025-11-09 12:43:32 -05:00
parent b346be9431
commit 5da44e1397

View File

@ -85,7 +85,6 @@ class ScheduleMonitor:
if not schedule: if not schedule:
return return
# Check if this is a different schedule than last applied
schedule_id = schedule.get('time', '') + schedule.get('name', '') schedule_id = schedule.get('time', '') + schedule.get('name', '')
if schedule_id == self.last_applied_schedule: if schedule_id == self.last_applied_schedule:
return # Already applied return # Already applied
@ -94,16 +93,29 @@ 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
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
# 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
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
# Save updated config to file so targets persist
try:
import json
with open('config.json', 'w') as f:
json.dump(self.config, f)
print("✅ Config updated with active schedule targets")
except Exception as e:
print("⚠️ Could not save config: {}".format(e))
# Log the change # Log the change
schedule_name = schedule.get('name', 'Unnamed') schedule_name = schedule.get('name', 'Unnamed')