Skip to content

Shelly: don't log an error for consumers without external temp sensors - #4291

Merged
LKuemmel merged 2 commits into
openWB:masterfrom
seaspotter:fix-shelly-temperature-missing-sensor-logspam
Nov 10, 2026
Merged

LKuemmel merged 2 commits into
openWB:masterfrom
seaspotter:fix-shelly-temperature-missing-sensor-logspam

Conversation

@seaspotter

@seaspotter seaspotter commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

#3466 (reply in thread)

Summary by Sourcery

Handle absent Shelly external temperature sensors without spurious errors while continuing to report genuinely malformed readings.

Bug Fixes:

  • Stop logging errors when Shelly devices have no external temperature sensors attached while retaining error logging for malformed sensor data.

Tests:

  • Add coverage for Shelly generation 1 and 2 devices without external sensors, valid sensor readings, and malformed temperature data.

@sourcery-ai

sourcery-ai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Skip missing external-temperature sensor entries without logging, while continuing to log malformed entries.

  • packages/modules/devices/shelly/shelly/status_handler.py L39-45

Tests

Add coverage for absent and sparse sensors, malformed entries, and both Shelly generations.

  • packages/modules/devices/shelly/shelly/status_handler_test.py L1-65

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/modules/devices/shelly/shelly/status_handler.py" line_range="42" />
<code_context>
                 value = status['ext_temperature'][str(index)]['tC']
             else:
                 value = status[f'temperature:{100 + index}']['tC']
+        except KeyError:
+            continue
+        try:
</code_context>
<issue_to_address>
**Malformed status faults consumer**

When the Shelly status has a non-mapping `ext_temperature` section or temperature entry, `parse_temperatures` lets the `TypeError` from indexing escape because the lookup is outside the conversion handler, aborting the consumer update and leaving readings stale as the component enters its fault path.

Handle and log `TypeError` from the nested lookup as malformed data without aborting processing of valid readings.

Also at `packages/modules/devices/shelly/shelly/status_handler.py:44-46`.
</issue_to_address>

### Comment 2
<location path="packages/modules/devices/shelly/shelly/status_handler.py" line_range="42" />
<code_context>
                 value = status['ext_temperature'][str(index)]['tC']
             else:
                 value = status[f'temperature:{100 + index}']['tC']
+        except KeyError:
+            continue
+        try:
</code_context>
<issue_to_address>
**Malformed sensors disappear silently**

When an indexed sensor entry is present but lacks its `tC` field, `parse_temperatures` catches the lookup's `KeyError` and continues, treating the malformed sensor as absent; its reading is omitted, potentially leaving a previously published value stale, without a diagnostic.

Distinguish an absent sensor from a present entry missing `tC`, and log the malformed entry instead of silently skipping it.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@LKuemmel
LKuemmel merged commit e59891c into openWB:master Nov 10, 2026
2 checks passed
@seaspotter
seaspotter deleted the fix-shelly-temperature-missing-sensor-logspam branch November 10, 2026 12:54
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.

2 participants