Skip to content

Fall back to usage-only reads when cost endpoint returns an error#187

Merged
tronikos merged 2 commits into
tronikos:mainfrom
loganrosen:cost-api-error-fallback
May 1, 2026
Merged

Fall back to usage-only reads when cost endpoint returns an error#187
tronikos merged 2 commits into
tronikos:mainfrom
loganrosen:cost-api-error-fallback

Conversation

@loganrosen
Copy link
Copy Markdown
Contributor

There's existing logic to fall back to the usage-only endpoint when the cost endpoint returns empty data (line 428). However, some utilities like ConEd return HTTP 500 from the cost endpoint for daily/hourly aggregation instead of empty data, so the existing fallback never triggers.

This catches ApiException from the cost endpoint for non-bill aggregations and retries with usage_only=True, matching the existing empty-data fallback behavior. Bill-level errors still raise since there is no alternative endpoint.

The exact error from ConEd:

HTTP Error: 500
URL: https://cned.opower.com/.../cws/cost/utilityAccount/<UUID>?aggregateType=day
Response: {"error":{"httpStatus":500,"serviceErrorCode":"UPSTREAM_ERROR",
  "details":"Could not get rated costs and usages for utility account UUID: <UUID>"}}

The usage-only endpoint works fine at all granularities for this account.

Related: home-assistant/core#169223

loganrosen and others added 2 commits April 30, 2026 22:33
Some utilities (e.g. ConEd) return HTTP 500 from the cost endpoint for
daily/hourly aggregation while the usage-only endpoint works fine.
Previously, this raised ApiException and crashed the caller. The
existing empty-data fallback only triggered when the cost endpoint
returned no data, not when it threw an error.

Now, ApiException from the cost endpoint for non-bill aggregations
triggers the same usage-only fallback. Bill-level errors still raise
since there is no alternative endpoint for bill data.
@tronikos tronikos merged commit a3a6747 into tronikos:main May 1, 2026
3 checks passed
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