fix: populate projected budget bill and deferred amount sensors - #93
Merged
Conversation
- Fetch energy usage before computing Budget Billing data so projected bill figures are available - Safely access projectedBill dictionary keys to avoid KeyError - Separate premise details and budget billing graph calls into isolated try/except blocks - Add defensive fallback in BillToDateSensor - Add comprehensive unit tests for budget billing client and sensors Closes #92
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.
Summary
Fixes #92 by addressing the
KeyErrorand data fetching ordering when collecting Budget Billing details for enrolled accounts.Root Cause
FplMainRegionApiClient.update(),__getBBL_async()was executed beforeget_energy_usage().__getBBL_async(),projectedBillData["projected_bill"]threw aKeyErrorbecause projected bill data had not been fetched yet (and the key is stored as camelCaseprojectedBill).try...exceptcaught theKeyErrorand returned an empty dictionary, skipping both the calculation ofbudget_billing_projected_bill/budget_billing_daily_avgand the subsequent call toURL_BUDGET_BILLING_GRAPH(which populatesdefered_amount).Changes
get_energy_usage()andget_appliance_usage()prior to evaluating BBL program and running__getBBL_async()..get()forprojectedBillandas_of_daysin__getBBL_async().URL_BUDGET_BILLING_PREMISE_DETAILSandURL_BUDGET_BILLING_GRAPHinto dedicatedtry...exceptblocks with clear error logging.Nonechecks inBillToDateSensor.tests/test_budget_billing.pycovering BBL API client calculations, ordering inupdate(), partial failure resilience, and sensor state resolutions.Verification
Ran test suite:
All 10 tests passed.