-
-
Notifications
You must be signed in to change notification settings - Fork 95
Ensure solar data updates at midnight #3331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
666ba1c
a395b0e
e14cc12
e3fd176
9699cb7
3a5b0ec
20fa9ed
2974a9f
755275c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,14 +55,23 @@ def initialize(self, solcast_host, solcast_api_key, solcast_sites, solcast_poll_ | |
| self.forecast_solar_failures_total = 0 | ||
| self.solcast_last_success_timestamp = None | ||
| self.forecast_solar_last_success_timestamp = None | ||
| self.last_fetched_timestamp = None | ||
| self.forecast_days = 4 | ||
|
|
||
| async def run(self, seconds, first): | ||
| """ | ||
| Run the Solar API | ||
| """ | ||
| fetch_age = 9999 | ||
| same_day = False | ||
| if self.last_fetched_timestamp: | ||
| fetch_age = (self.now_utc_exact - self.last_fetched_timestamp).total_seconds() / 60 | ||
| same_day = self.last_fetched_timestamp.date() == self.now_utc_exact.date() | ||
|
|
||
| if seconds % (self.plan_interval_minutes * 60) == 0: # Every plan_interval_minutes | ||
| await self.fetch_pv_forecast() | ||
| elif not same_day or (fetch_age > 60): # If data is older than 60 minutes or it's a new day, fetch new data | ||
| await self.fetch_pv_forecast() | ||
| return True | ||
|
Comment on lines
61
to
75
|
||
|
|
||
| async def cache_get_url(self, url, params, max_age=8 * 60): | ||
|
|
@@ -879,5 +888,7 @@ async def fetch_pv_forecast(self): | |
| self.publish_pv_stats(pv_forecast_data, divide_by / 30.0, 30) | ||
| self.pack_and_store_forecast(pv_forecast_minute, pv_forecast_minute10) | ||
| self.update_success_timestamp() | ||
| self.last_fetched_timestamp = self.now_utc_exact | ||
| else: | ||
| self.log("Warn: No solar data has been configured.") | ||
| self.last_fetched_timestamp = self.now_utc_exact | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.last_fetched_timestampis set usingself.now_utc_exact(timezone-aware), butrun()compares it todatetime.now()(naive). Subtracting/comparing these will raise aTypeErrorat runtime. Use a consistent, tz-aware clock for both values (e.g.,now = self.now_utc_exactordatetime.now(self.local_tz)), and avoid mixing naive/aware datetimes.