Fox uses storage to cache values#4062
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Fox ESS Cloud API integration to persist selected device data in storage and refresh it using age-based thresholds, reducing unnecessary cloud polling after reboots and during normal operation.
Changes:
- Added storage-backed caching for Fox device list/detail, settings/scheduler state, production totals, and real-time values.
- Replaced time-boundary refresh logic with age-based refresh decisions per cached data category.
- Expanded/updated Fox API tests to validate cache aging behavior and first-run refresh rules.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/predbat/fox.py | Adds cache keys, refresh thresholds, load/save helpers, and age-based refresh logic in run() for Fox API data. |
| apps/predbat/tests/test_fox_api.py | Updates tests to cover age-based refresh behavior, including realtime/settings expiry and first-run refresh expectations. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+335
to
+352
| # Device detail and battery charging times rarely change - refresh based on age | ||
| if first or self._needs_refresh("device_detail", FOX_REFRESH_STATIC): | ||
| detail_updated = False | ||
| battery_updated = False | ||
| for device in self.device_list: | ||
| sn = device.get("deviceSN", None) | ||
| if sn: | ||
| # get_device_detail returns None on failure, the data (always non-empty) on success | ||
| if await self.get_device_detail(sn) is not None: | ||
| detail_updated = True | ||
| # get_battery_charging_time returns {} on failure or for a non-battery device | ||
| if await self.get_battery_charging_time(sn) is not None: | ||
| battery_updated = True | ||
| # Persist each cache once after polling all devices, only when a poll succeeded | ||
| if detail_updated: | ||
| await self._save_cache("device_detail", self.device_detail) | ||
| if battery_updated: | ||
| await self._save_cache("battery_charging_time", self.device_battery_charging_time) |
Comment on lines
+361
to
+365
| # Device settings and scheduler - refresh based on age | ||
| settings_refresh = self._needs_refresh("device_settings", FOX_REFRESH_SETTINGS) | ||
| if settings_refresh: | ||
| settings_updated = False | ||
| scheduler_updated = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.