Track history of recent API calls (last 5-10 calls) for debugging and monitoring.
Problem
Currently, only the latest response is stored. Users can't easily see patterns in API behavior or review recent calls for troubleshooting.
Proposed Solution
Add a configurable history buffer (default: 5 calls):
Store last N calls with timestamps
Include request details (rendered templates)
Include response details (status, body)
Expose as sensor attribute or separate diagnostic entity
Benefits
Better debugging for intermittent issues
See patterns in API responses over time
Useful for development/testing
Can track when APIs started failing
Implementation Notes
# In HaapiApiCallerself._history= [] # List of dictsHISTORY_SIZE=5# After each callself._history.append({
"timestamp": datetime.now().isoformat(),
"status_code": status,
"response_body": body,
"request_url": rendered_url,
"error": error_msgiferrorelseNone,
})
self._history=self._history[-HISTORY_SIZE:] # Keep last N# In Response sensorattrs["call_history"] =self._api_caller.history
Considerations
Could increase database size
May need size limits per history entry
Could be opt-in feature
Consider diagnostic sensor vs main sensor attribute
Activity