@@ -106,20 +106,14 @@ def init_weather_client():
106106 logger .warning ("Weather API key not configured - weather feature disabled" )
107107 return
108108
109- latitude = weather_config .get ("latitude" )
110- longitude = weather_config .get ("longitude" )
111-
112- if latitude is None or longitude is None :
113- logger .warning ("Weather location not configured - weather feature disabled" )
114- return
115-
116109 city_name = weather_config .get ("city_name" , "" )
110+ if not city_name :
111+ logger .warning ("Weather city not configured - weather feature disabled" )
112+ return
117113
118114 weather_client = WeatherClient (
119115 api_key = api_key ,
120- latitude = latitude ,
121- longitude = longitude ,
122- city_name = city_name if city_name else None
116+ city_name = city_name
123117 )
124118
125119 bad_conditions = weather_config .get ("bad_weather_conditions" , ["Rain" , "Thunderstorm" , "Drizzle" , "Snow" ])
@@ -130,7 +124,7 @@ def init_weather_client():
130124 min_cloud_cover = min_cloud_cover
131125 )
132126
133- location_str = city_name if city_name else f"( { latitude } , { longitude } )"
127+ location_str = city_name
134128 logger .info (f"Weather client initialised for { location_str } " )
135129
136130
@@ -182,8 +176,8 @@ def should_skip_discharge_for_weather() -> tuple:
182176 if not forecast :
183177 return False , "Weather data unavailable"
184178
185- threshold_days = weather_config .get ("bad_weather_threshold_days " , 2 )
186- return weather_analyser .should_skip_discharge (forecast , threshold_days )
179+ min_solar_kwh = weather_config .get ("min_solar_threshold_kwh " , 0 )
180+ return weather_analyser .should_skip_discharge (forecast , min_solar_kwh )
187181
188182
189183def is_within_discharge_window () -> bool :
@@ -538,7 +532,7 @@ def complete_setup():
538532 if "weather" not in config :
539533 config ["weather" ] = {}
540534
541- for key in ["enabled" , "api_key" , "city_name" , "latitude" , "longitude" ,
535+ for key in ["enabled" , "api_key" , "city_name" ,
542536 "inverter_capacity_kw" , "panel_capacity_kw" ]:
543537 if key in weather_data :
544538 config ["weather" ][key ] = weather_data [key ]
@@ -584,7 +578,7 @@ def get_status():
584578 "enabled" : weather_config .get ("enabled" , False ),
585579 "skip_active" : current_state .get ("weather_skip_active" , False ),
586580 "skip_reason" : current_state .get ("weather_skip_reason" ),
587- "threshold_days " : weather_config .get ("bad_weather_threshold_days " , 2 )
581+ "min_solar_threshold_kwh " : weather_config .get ("min_solar_threshold_kwh " , 0 )
588582 }
589583
590584 # Include free energy status
@@ -778,7 +772,7 @@ def get_weather():
778772 "forecast" : forecast ,
779773 "skip_discharge" : skip_active ,
780774 "skip_reason" : skip_reason ,
781- "threshold_days " : weather_config .get ("bad_weather_threshold_days " , 2 ),
775+ "min_solar_threshold_kwh " : weather_config .get ("min_solar_threshold_kwh " , 0 ),
782776 "last_update" : weather_forecast_cache .get ("last_update" ).isoformat () if weather_forecast_cache .get ("last_update" ) else None
783777 })
784778
@@ -790,9 +784,7 @@ def get_weather_config():
790784 return jsonify ({
791785 "enabled" : weather_config .get ("enabled" , False ),
792786 "city_name" : weather_config .get ("city_name" , "" ),
793- "latitude" : weather_config .get ("latitude" ),
794- "longitude" : weather_config .get ("longitude" ),
795- "bad_weather_threshold_days" : weather_config .get ("bad_weather_threshold_days" , 2 ),
787+ "min_solar_threshold_kwh" : weather_config .get ("min_solar_threshold_kwh" , 0 ),
796788 "bad_weather_conditions" : weather_config .get ("bad_weather_conditions" , []),
797789 "min_cloud_cover_percent" : weather_config .get ("min_cloud_cover_percent" , 70 ),
798790 "inverter_capacity_kw" : weather_config .get ("inverter_capacity_kw" , 0 ),
@@ -836,12 +828,8 @@ def update_weather_config():
836828 config ["weather" ]["enabled" ] = body ["enabled" ]
837829 if "city_name" in body :
838830 config ["weather" ]["city_name" ] = body ["city_name" ]
839- if "latitude" in body :
840- config ["weather" ]["latitude" ] = body ["latitude" ]
841- if "longitude" in body :
842- config ["weather" ]["longitude" ] = body ["longitude" ]
843- if "bad_weather_threshold_days" in body :
844- config ["weather" ]["bad_weather_threshold_days" ] = body ["bad_weather_threshold_days" ]
831+ if "min_solar_threshold_kwh" in body :
832+ config ["weather" ]["min_solar_threshold_kwh" ] = body ["min_solar_threshold_kwh" ]
845833 if "bad_weather_conditions" in body :
846834 config ["weather" ]["bad_weather_conditions" ] = body ["bad_weather_conditions" ]
847835 if "min_cloud_cover_percent" in body :
0 commit comments