Fall back to usage-only reads when cost endpoint returns an error#187
Merged
Conversation
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
approved these changes
May 1, 2026
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.
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
ApiExceptionfrom the cost endpoint for non-bill aggregations and retries withusage_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:
The usage-only endpoint works fine at all granularities for this account.
Related: home-assistant/core#169223