Skip to content

Consumer: Shelly relais - #4255

Merged
LKuemmel merged 10 commits into
openWB:masterfrom
ndrsnhs:shelly-relais
Nov 11, 2026
Merged

LKuemmel merged 10 commits into
openWB:masterfrom
ndrsnhs:shelly-relais

Conversation

@ndrsnhs

@ndrsnhs ndrsnhs commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

openWB/openwb-ui-settings#1157

Summary by Sourcery

Add configurable Shelly relay consumers and improve handling of authentication and missing consumer power data.

New Features:

  • Add support for Shelly relay consumers with on/off control and state monitoring across Shelly generations.

Bug Fixes:

  • Handle consumers with unavailable power readings without attempting invalid peak filtering or simulated counter updates.

Enhancements:

  • Centralize Shelly authentication handling for status requests and relay switching, including generation-specific authentication.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Changes are still needed because Gen1 responses and configured channels are handled incorrectly, and authentication is omitted from discovery and status requests.

2 open issues
What changed in this PR

Adds a Shelly relay consumer for on/off control, with configurable channel, credentials, generation-aware switching, and support for consumers without power measurements.

Changes:

  • Adds Shelly relay configuration and consumer implementation.
  • Adds authenticated relay commands and status polling.
  • Updates common consumer handling to default unavailable power values to zero.

Unresolved findings remain in consumer.py: a critical Gen1/channel status-parsing issue (4 votes) and a moderate authentication issue affecting discovery and polling (2 votes). This pull request requires changes.

File Summary
packages/​modules/​consumers/​shelly/​shelly_relais/​consumer.py Implements Shelly relay initialization, switching, and state updates. Contains the unresolved status-parsing and authentication findings.
packages/​modules/​consumers/​shelly/​shelly_relais/​config.py Defines Shelly relay configuration, credentials, channel, and consumer metadata.
packages/​modules/​common/​configurable_consumer.py Handles consumers that do not provide power measurements by defaulting missing values to zero.

Review effort: Lite

def initializer():
nonlocal sim_counter, generation, model
sim_counter = SimCounterConsumer(config.id, ComponentType.CONSUMER)
generation, model = get_generation(config.configuration.ip_address)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Beim Endpunkt /shelly braucht man bei beiden Generationen kein Auth.

@LKuemmel LKuemmel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bitte die Copilot-Anmerkungen prüfen.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The Shelly consumer leaves generation detection and status reads unauthenticated, so configured credentials fail on authentication-enabled devices and prevent initialization or state reporting.

1 open issue
1 resolved since last review

Review effort: Lite

@LKuemmel LKuemmel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bitte die Copilot-Anmerkungen prüfen.

@sourcery-ai

sourcery-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Add a shared authentication helper and an optional auth parameter to Shelly status requests so callers can authenticate across device generations.

  • packages/modules/devices/shelly/shelly/status_handler.py L4, L27-35, L40

Uses of the API

Initialize generation-appropriate authentication in the existing Shelly consumers and pass it to status requests and relay-switch requests.

  • packages/modules/consumers/shelly/shelly_em/consumer.py L14-19 (+3 small edits)
  • packages/modules/consumers/shelly/shelly_pm/consumer.py L16-21 (+5 small edits)

Implementation

Add a Shelly relay consumer that switches and reports relay state for generations 1 and 2, with authentication and channel support.

  • packages/modules/consumers/shelly/shelly_relais/consumer.py L1-70

Avoid filtering or simulating energy values when power is unavailable, and default missing power and energy values to zero.

  • packages/modules/common/configurable_consumer.py L78-96

Configuration

Define the Shelly relay consumer's configurable address, channel, credentials, and consumer usage defaults.

  • packages/modules/consumers/shelly/shelly_relais/config.py L1-32

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The change adds authenticated status requests, but existing Shelly PM and EM consumers do not pass their configured credentials, so authenticated devices will still fail status and power polling.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Forward credentials in existing Shelly status requests

packages/​modules/​devices/​shelly/​shelly/​status_handler.py:32

This adds authenticated status requests, but the existing Shelly PM and Shelly EM consumers still call request_status(address, generation) without forwarding their configured credentials (consumers/shelly/shelly_pm/consumer.py:59 and shelly_em/consumer.py:20). Consequently authenticated devices still fail their status/power polling; please wire the same generation-specific auth into those call sites as well, or otherwise scope this API change so all authenticated Shelly consumers use it.

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical authentication-handling issue remains: the shared response hook raises the initial 401 before HTTP digest authentication can retry, causing authenticated Gen2 status and relay requests to fail.

2 open issues

Review effort: Lite

else:
status_url = "http://" + address + "/rpc/Shelly.GetStatus"
return req.get_http_session().get(status_url, timeout=3).json()
return req.get_http_session().get(status_url, auth=auth, timeout=3).json()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Obwohl die Session-Hooks zuerst angelegt werden, registriert Requests beim Vorbereiten der Anfrage die Auth-Hooks vor den Session-Hooks.

@LKuemmel
LKuemmel merged commit ba2f490 into openWB:master Nov 11, 2026
2 checks passed
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.

3 participants