Skip to content
This repository was archived by the owner on Aug 14, 2026. It is now read-only.

Commit 4129f25

Browse files
committed
fix again
1 parent 0b86b3d commit 4129f25

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎app.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,13 @@ def get_weather_forecast():
165165
if not weather_client or not weather_analyser:
166166
return None
167167

168-
# Check cache (update every 30 minutes)
168+
# Check cache (update every 5 minutes - matches frontend refresh)
169+
# 288 calls/day max, well under 1000/day API limit
169170
cache_age = None
170171
if weather_forecast_cache["last_update"]:
171172
cache_age = (datetime.now() - weather_forecast_cache["last_update"]).total_seconds()
172173

173-
if cache_age is None or cache_age > 1800: # 30 minutes
174+
if cache_age is None or cache_age > 300: # 5 minutes
174175
try:
175176
forecast = weather_client.get_forecast()
176177
# Get panel capacity for solar estimates
@@ -188,6 +189,7 @@ def get_weather_forecast():
188189
capacity_kw = api_inverter_kw * 1.25 # Use API inverter capacity with oversizing ratio
189190
else:
190191
capacity_kw = 0
192+
logger.info(f"Solar capacity for forecast: {capacity_kw} kW (panel={panel_kw}, inverter_config={inverter_kw}, inverter_api={api_inverter_kw})")
191193
# Pass weather_client for hourly solar calculations
192194
forecast = weather_analyser.analyse_forecast(
193195
forecast,
@@ -637,6 +639,10 @@ def complete_setup():
637639

638640
save_config()
639641

642+
# Clear weather cache to apply new capacity settings
643+
weather_forecast_cache["forecast"] = None
644+
weather_forecast_cache["last_update"] = None
645+
640646
# Reinitialize clients
641647
init_client()
642648
init_weather_client()

‎templates/index.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ <h2>Schedule Settings</h2>
835835
<div class="schedule-grid">
836836
<!-- Force Discharge Window -->
837837
<div class="schedule-section">
838-
<div class="schedule-section-title">⚡ Force Discharge</div>
838+
<div class="schedule-section-title"><span style="color: #4ecca3;">*</span> Force Discharge</div>
839839
<form id="scheduleForm" class="schedule-form">
840840
<div class="schedule-row">
841841
<div class="setting-item">
@@ -865,7 +865,7 @@ <h2>Schedule Settings</h2>
865865
<div class="schedule-section-title">
866866
<label style="display: flex; align-items: center; gap: 6px; cursor: pointer;">
867867
<input type="checkbox" id="freeEnergyEnabled">
868-
🔋 Free Energy Charge
868+
<span style="color: #3498db;">⚡</span> Free Energy Charge
869869
</label>
870870
</div>
871871
<form id="freeEnergySettingsForm" class="schedule-form">

‎weather_client.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, api_key: str, city_name: str):
3232
self.base_url = "https://api.openweathermap.org/data/2.5"
3333
self._cache = {}
3434
self._cache_time = None
35-
self._cache_duration = 1800 # 30 minutes cache
35+
self._cache_duration = 300 # 5 minutes cache
3636

3737
def _geocode_city(self) -> bool:
3838
"""Geocode city_name to get latitude and longitude. Returns True if successful."""
@@ -115,10 +115,12 @@ def estimate_solar_output_hourly(self, panel_capacity_kw: float, date_str: str)
115115
Estimated kWh for the day, or None if hourly data unavailable
116116
"""
117117
if "hourly_data" not in self._cache:
118+
logger.debug(f"No hourly_data in cache for solar estimate")
118119
return None
119120

120121
hourly_data = self._cache["hourly_data"].get(date_str, [])
121122
if not hourly_data:
123+
logger.debug(f"No hourly data for date {date_str}, available dates: {list(self._cache['hourly_data'].keys())}")
122124
return None
123125

124126
# Base daily production varies by latitude (peak sun hours equivalent)
@@ -715,6 +717,6 @@ def should_skip_discharge(
715717
else:
716718
return False, f"Good solar forecast ({estimated_solar:.1f} kWh on {tomorrow.get('day_name', 'Tomorrow')})"
717719
else:
718-
return False, "Solar prediction not available (configure panel capacity)"
720+
return False, "Solar prediction not available (no hourly forecast data)"
719721

720722
return False, "Solar threshold not configured"

0 commit comments

Comments
 (0)