Skip to content

Fix consumer modules - #3865

Merged
LKuemmel merged 3 commits into
openWB:feature_consumer_modulesfrom
benderl:fix-consumer-modules
Aug 28, 2026
Merged

Fix consumer modules#3865
LKuemmel merged 3 commits into
openWB:feature_consumer_modulesfrom
benderl:fix-consumer-modules

Conversation

@benderl

@benderl benderl commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

No description provided.

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.

Pull request overview

This PR standardizes and tightens typing across many consumer/device modules (notably around Optional[...] usage and config defaults) to improve static analysis and reduce ambiguous None handling, with a few small behavioral tweaks.

Changes:

  • Add/adjust Optional[...] annotations for lazily-initialized client/session variables across many consumers.
  • Refine multiple consumer config.py constructors to use non-optional primitive defaults (e.g., port: int = 502) and mark configuration parameters as Optional[...].
  • Minor functional updates: Shelly generation typing cleanup, AVM consumer now raises when the configured device name is not found, my-PV consumers switched from write_registers to write_register.

Reviewed changes

Copilot reviewed 39 out of 39 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/modules/devices/shelly/shelly/status_handler.py Tightens get_generation() return typing (always returns an int generation).
packages/modules/consumers/viessmann/viessmann_heat_pump/consumer.py Adds Optional typing for the lazily initialized Modbus client.
packages/modules/consumers/viessmann/viessmann_heat_pump/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/stiebel/stiebel/consumer.py Adds Optional typing for Modbus client and sim counter.
packages/modules/consumers/stiebel/stiebel/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/solvis/solvis/consumer.py Adds Optional typing for Modbus client and sim counter.
packages/modules/consumers/solvis/solvis/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/solarfocus/vampair/consumer.py Adds Optional typing for Modbus client and sim counter.
packages/modules/consumers/solarfocus/vampair/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/shelly/shelly_pm/consumer.py Adds Optional typing for sim counter/model and explicit int for generation.
packages/modules/consumers/shelly/shelly_pm/config.py Makes factor/phase non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/shelly/shelly_em/consumer.py Adds Optional typing for sim counter and explicit int for generation.
packages/modules/consumers/shelly/shelly_em/config.py Makes factor/phase non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/ratiotherm/ratiotherm/consumer.py Adds Optional typing for Modbus client and sim counter; minor formatting tweak.
packages/modules/consumers/ratiotherm/ratiotherm/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/ovum/ovum/consumer.py Adds Optional typing for Modbus client and sim counter.
packages/modules/consumers/ovum/ovum/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/nibe/nibe_s_series/consumer.py Adds Optional typing for Modbus client and sim counter.
packages/modules/consumers/nibe/nibe_s_series/config.py Makes modbus_id non-optional default; configuration becomes Optional[...].
packages/modules/consumers/mystrom/mystrom/consumer.py Adds Optional typing for HTTP session and sim counter.
packages/modules/consumers/mystrom/mystrom/config.py Marks configuration as Optional[...].
packages/modules/consumers/my_pv/elwa_e/consumer.py Renames “STATUS” to “STATE” mapping and switches to write_register for setpoint writes.
packages/modules/consumers/my_pv/elwa_e/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/my_pv/acthor/consumer.py Adds Optional typing and switches to write_register for setpoint writes.
packages/modules/consumers/my_pv/acthor/config.py Makes several fields non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/lambda_/lambda_/consumer.py Adds Optional typing for Modbus client and sim counter.
packages/modules/consumers/lambda_/lambda_/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/idm/idm/consumer.py Adds Optional typing for Modbus client and sim counter.
packages/modules/consumers/idm/idm/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/generic/json/consumer.py Adds Optional typing for session/sim counter and corrects update() return type annotation.
packages/modules/consumers/generic/json/config.py Makes many config fields explicitly Optional[str]; configuration becomes Optional[...].
packages/modules/consumers/generic/http/consumer.py Adds Optional typing for session/sim counter and request/post callables; minor call-site adjustment.
packages/modules/consumers/generic/http/config.py Makes many config fields explicitly Optional[str]; configuration becomes Optional[...].
packages/modules/consumers/generic/dac/consumer.py Makes Modbus client Optional[...]; comment capitalization + minor formatting.
packages/modules/consumers/generic/dac/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].
packages/modules/consumers/avm/avm/consumer.py Types ain as Optional[str] and raises if the configured device name is not found.
packages/modules/consumers/avm/avm/config.py Changes session_mtime type to Optional[float]; configuration becomes Optional[...].
packages/modules/consumers/askoma/askoheat/consumer.py Adds Optional typing for Modbus client and sim counter.
packages/modules/consumers/askoma/askoheat/config.py Makes port/modbus_id non-optional defaults; configuration becomes Optional[...].

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/modules/consumers/my_pv/acthor/consumer.py Outdated
Comment thread packages/modules/consumers/my_pv/elwa_e/consumer.py Outdated

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.

Pull request overview

Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.

Comment thread packages/modules/consumers/avm/avm/consumer.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@benderl
benderl requested a review from ndrsnhs August 27, 2026 10:13
Comment on lines +16 to +17
client: Optional[ModbusTcpClient_] = None
sim_counter: Optional[SimCounterConsumer] = None

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.

Suggested change
client: Optional[ModbusTcpClient_] = None
sim_counter: Optional[SimCounterConsumer] = None
client: ModbusTcpClient_
sim_counter: SimCounterConsumer

So sind die pyright-Meldungen komplett verschwunden. Und ob client gar nicht oder mit None initialisiert ist, kommt beim Aufruf von read_input_registers in beiden Fällen eine Exception und intializer sollte sowieso vorher aufgerufen werden.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Das Ziel der Anpassung war ja nicht, die Meldungen "verschwinden" zu lassen, sondern den Code robuster zu machen. Wenn klar ist, dass client und sim_counter zuerst None sind, wird das auch in der IDE entsprechend mit Hinweisen versehen und es kann darauf reagiert werden.

In diesem Modul kommt es z.B. in Zeile 28 zu einer Warnung, dass client ggf. Noneist. Ohne weitere Anpassung wird eine Exception geworfen, die irgendetwas von None hat keine Eigenschaft XYZ (sinngemäß) erzählt. Damit kann außer einem Entwickler niemand etwas anfangen.

Es wäre nach meiner Meinung sinnvoller, wenn vorab auf client is None geprüft wird und dann eine Klartextmeldung kommt, die z.B. auch der Support versteht. Das mag nicht unbedingt "Python Style" sein, hätte aber durchaus Vorteile. Ich vermute mal, dass nicht ohne Grund angemeckert wird, dass client iin Zeile 28 None sein könnte.

@LKuemmel
LKuemmel merged commit f8780fb into openWB:feature_consumer_modules Aug 28, 2026
1 check passed
LKuemmel pushed a commit that referenced this pull request Aug 28, 2026
* fix configuration type hints

* fix consumer type hints and errors

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.

3 participants