Skip to content

Fix missing error handling in OmniSensor.fetch_state()#357

Open
StevenEmelander wants to merge 1 commit intoloopj:mainfrom
StevenEmelander:fix/omni-sensor-fetch-state
Open

Fix missing error handling in OmniSensor.fetch_state()#357
StevenEmelander wants to merge 1 commit intoloopj:mainfrom
StevenEmelander:fix/omni-sensor-fetch-state

Conversation

@StevenEmelander
Copy link

Fixes #356

Summary

OmniSensor.fetch_state() overrides Interface.fetch_state() to use its own get_level() method with custom formula-based conversion. This is intentional — the existing comment explains that OmniSensors should not use SensorInterface to 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 for CommandError and ConversionError, logging a warning and continuing. The OmniSensor override calls get_level() directly without this protection, so any error (e.g., NotInitializedError from a sensor that isn't ready) propagates up unhandled and can prevent the integration from loading.

Changes

  • Add try/except around get_level() catching CommandError and ConversionError, matching the base class pattern
  • Log a warning for visibility, consistent with Interface.fetch_state()
  • Return [] (no properties changed) on error instead of raising

Test plan

  • Verified integration loads cleanly with OmniSensors that report "Not Initialized"
  • Verified working sensors still report level correctly

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>
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.

OmniSensor.fetch_state() missing error handling

1 participant