Skip to content

Fox uses storage to cache values#4062

Merged
springfall2008 merged 5 commits into
mainfrom
feat/fox_cache
Jun 14, 2026
Merged

Fox uses storage to cache values#4062
springfall2008 merged 5 commits into
mainfrom
feat/fox_cache

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings June 14, 2026 18:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apps/predbat/fox.py
Comment thread apps/predbat/fox.py Outdated
springfall2008 and others added 2 commits June 14, 2026 20:24
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

Comment thread apps/predbat/fox.py
Comment thread apps/predbat/fox.py Outdated
Comment thread apps/predbat/fox.py
Comment thread apps/predbat/fox.py
Comment thread apps/predbat/fox.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread apps/predbat/fox.py
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 thread apps/predbat/fox.py
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
@springfall2008 springfall2008 merged commit 70734eb into main Jun 14, 2026
2 checks passed
@springfall2008 springfall2008 deleted the feat/fox_cache branch June 14, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants