fix: replace critical error handling with warnings for missing entities values in Home Assistant monitors#70
Open
fix: replace critical error handling with warnings for missing entities values in Home Assistant monitors#70
Conversation
… values in Home Assistant monitors
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.
Problem
When fetching energy state or forecast data from Home Assistant, a single entity returning
unavailableorunknown(e.g.sensor.battery_soc) caused the entire data retrieval to fail and returnNone. This meant:The root cause was a
has_critical_errorflag that was set toTruefor any configured-but-unavailable entity, triggeringreturn Noneand discarding all successfully retrieved data — despite the domain model already supporting partial data (EnergyStateSnapshot.batteryand.gridareOptional).This PR closes #69
Solution
Removed the
has_critical_errormechanism entirely. Each entity failure is now handled independently with graceful degradation:consumptionreturn None0W, snapshot still createdproductionreturn None0Wgridreturn NoneGridStateset toNonebattery_soc/battery_powerreturn NoneBatteryStateset toNoneenergy_today/energy_tomorrow(forecast)return NoneThe snapshot is now always constructed with whatever data is available. Missing optional components result in
Nonesub-objects, which downstream consumers (policy rules, decisional context, frontend) already handle.Changes
adapters/domain/energy/monitors/home_assistant_api.pyhas_critical_errorflag and the earlyreturn Noneblock.has_critical_error = Trueto a warning log.GridStatewill beNone.has_critical_error = Trueto a warning log.BatteryStatewill beNone.0W.adapters/domain/energy/monitors/home_assistant_mqtt.pyhas_critical_errorflag and the earlyreturn Noneblock.adapters/domain/forecast/providers/home_assistant_api.pyhas_critical_errorflag and the earlyreturn Noneblock.energy_todayandenergy_tomorrow: changed from critical errors to warning logs.Testing
unavailable, the snapshot is still created withbattery=Noneand all other fields populated.