Fix missing error handling in OmniSensor.fetch_state()#357
Open
StevenEmelander wants to merge 1 commit intoloopj:mainfrom
Open
Fix missing error handling in OmniSensor.fetch_state()#357StevenEmelander wants to merge 1 commit intoloopj:mainfrom
StevenEmelander wants to merge 1 commit intoloopj:mainfrom
Conversation
OmniSensor overrides Interface.fetch_state() to use its own get_level() method with custom formula-based conversion. However, the override does not include the error handling that Interface.fetch_state() provides, which catches CommandError and ConversionError per property. This causes OmniSensor.fetch_state() to raise unhandled exceptions when sensors report errors like "Not Initialized" or "Not Supported", which can prevent the entire integration from loading. Add the same try/except pattern used by Interface.fetch_state(), with a warning log for visibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Fixes #356
Summary
OmniSensor.fetch_state()overridesInterface.fetch_state()to use its ownget_level()method with custom formula-based conversion. This is intentional — the existing comment explains that OmniSensors should not useSensorInterfaceto handle state because they do additional conversion behind the scenes.However, the override bypasses the error handling that
Interface.fetch_state()provides. The base class wraps each property getter in a try/except forCommandErrorandConversionError, logging a warning and continuing. TheOmniSensoroverride callsget_level()directly without this protection, so any error (e.g.,NotInitializedErrorfrom a sensor that isn't ready) propagates up unhandled and can prevent the integration from loading.Changes
get_level()catchingCommandErrorandConversionError, matching the base class patternInterface.fetch_state()[](no properties changed) on error instead of raisingTest plan