Skip to content

OmniSensor.fetch_state() missing error handling #356

@StevenEmelander

Description

@StevenEmelander

Bug

OmniSensor.fetch_state() overrides Interface.fetch_state() to use its own get_level() method with custom formula-based conversion (as noted in the existing comment: "We are explicitly not calling the parent methods in fetch_state and handle_object_status, as we don't want SensorInterface to handle the state").

However, the override does not include the error handling that Interface.fetch_state() provides. The base class catches CommandError and ConversionError per property getter (base.py lines 217-225):

for prop, getter in self._property_getters.items():
    try:
        fetched_properties[prop] = await getter(self)
    except (CommandError, ConversionError) as ex:
        logger.warning(...)
        continue

Since OmniSensor.fetch_state() bypasses this and calls get_level() directly without a try/except, any CommandError (e.g., NotInitializedError for sensors that aren't ready) or ConversionError propagates up unhandled. This can cause Controller.fetch_state() to fail entirely, preventing the integration from setting up.

Expected behavior

OmniSensor.fetch_state() should handle errors gracefully, consistent with Interface.fetch_state() — log a warning and continue rather than raising.

Proposed fix

Add the same try/except pattern to the OmniSensor.fetch_state() override, catching CommandError and ConversionError with a warning log. PR incoming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions