Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion custom_components/marstek_local_api/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ def __init__(
# Staleness tracking - track last successful update per category
self.category_last_updated: dict[str, float] = {}
self.STALENESS_THRESHOLD = 3 # missed updates before invalidation
self.STALENESS_FACTOR = {
"battery": UPDATE_INTERVAL_FAST,
"es": UPDATE_INTERVAL_FAST,
"em": UPDATE_INTERVAL_MEDIUM,
"pv": UPDATE_INTERVAL_MEDIUM,
"mode": UPDATE_INTERVAL_MEDIUM,
"ble": UPDATE_INTERVAL_SLOW,
"wifi": UPDATE_INTERVAL_SLOW,
}
self.STATIC_CATEGORIES = {"device", "wifi", "ble", "_diagnostic", "aggregates"}

# Initialize compatibility matrix for version-specific scaling
Expand Down Expand Up @@ -393,8 +402,10 @@ def is_category_fresh(self, category: str) -> bool:
last_update = self.category_last_updated[category]
elapsed = time.time() - last_update

category_stale_factor = self.STALENESS_FACTOR.get(category, 1)

# Calculate max age (update interval * threshold)
max_age = self.update_interval.total_seconds() * self.STALENESS_THRESHOLD
max_age = self.update_interval.total_seconds() * self.STALENESS_THRESHOLD * category_stale_factor

return elapsed < max_age

Expand Down