Skip to content

Conversation

@premultiply
Copy link
Member

@andig andig added the infrastructure Basic functionality label Aug 17, 2025
@github-actions github-actions bot added the stale Outdated and ready to close label Aug 24, 2025
@premultiply premultiply removed the stale Outdated and ready to close label Aug 24, 2025
@premultiply premultiply requested a review from Copilot August 24, 2025 18:19
Copy link

Copilot AI left a comment

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 adds support for a configurable communication delay parameter to Modbus templates. The delay parameter allows users to specify a pause between Modbus requests, which is useful for devices that require time between communications to avoid errors or timeouts.

Key changes:

  • Added delay parameter support to Modbus template infrastructure
  • Updated template definitions to include delay configuration options
  • Refactored the WattSonic meter template to use the new centralized delay parameter instead of duplicating it in each Modbus call

Reviewed Changes

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

Show a summary per file
File Description
util/templates/types.go Added delay parameter constant and field definitions
util/templates/template_modbus.go Added logic to handle delay parameter in Modbus value processing
util/templates/modbus.tpl Added delay field to Modbus template output
util/templates/defaults.yaml Added delay parameter definition with descriptions and configuration
util/modbus/modbus.go Added delay field to Modbus settings structures
templates/definition/meter/wattsonic.yaml Refactored to use centralized delay parameter instead of per-call delays

@premultiply premultiply requested review from andig and removed request for Copilot August 24, 2025 18:21
@github-actions github-actions bot added the stale Outdated and ready to close label Aug 31, 2025
@github-actions github-actions bot closed this Sep 5, 2025
@premultiply premultiply added backlog Things to do later and removed stale Outdated and ready to close labels Sep 5, 2025
@premultiply premultiply reopened this Sep 5, 2025
@premultiply premultiply marked this pull request as ready for review September 5, 2025 19:09
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The new Delay field is added to the Modbus settings but I don't see it being applied in the request loop—make sure you inject a sleep (e.g. time.Sleep) between Modbus calls to enforce the delay.
  • Add parsing/validation of the Delay string (using time.ParseDuration) when loading the configuration so invalid duration formats are caught early.
  • The delay parameter is defined globally in defaults.yaml and will show up for all templates; consider scoping it only to Modbus‐related templates to avoid cluttering other definitions.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new Delay field is added to the Modbus settings but I don't see it being applied in the request loop—make sure you inject a sleep (e.g. time.Sleep) between Modbus calls to enforce the delay.
- Add parsing/validation of the Delay string (using time.ParseDuration) when loading the configuration so invalid duration formats are caught early.
- The delay parameter is defined globally in defaults.yaml and will show up for all templates; consider scoping it only to Modbus‐related templates to avoid cluttering other definitions.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Baudrate int `json:",omitempty" yaml:",omitempty"`
UDP bool `json:",omitempty" yaml:",omitempty"`
RTU *bool `json:",omitempty" yaml:",omitempty"`
Delay string `json:",omitempty" yaml:",omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Delay string `json:",omitempty" yaml:",omitempty"`
Delay time.Duration `json:",omitempty" yaml:",omitempty"`

Comset string `json:",omitempty"` // device specific default for modbus RS485 comset
Port int `json:",omitempty"` // device specific default for modbus TCPIP port
ID int `json:",omitempty"` // device specific default for modbus ID
Delay string `json:",omitempty"` // device specific default for modbus communication delay
Copy link
Member

Choose a reason for hiding this comment

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

time.Duration

?

@andig
Copy link
Member

andig commented Sep 8, 2025

Das Delay scheint nirgendwo benutzt zu werden? Es muss ja auch gesetzt werden. Dafür wäre es vmtl. sinnvoll, die modbus.NewConnection durch eine modbus.NewTcp/Rtu/EtcConnection zu ergänzen und dort den ganzen Parameterstack zu übergeben. NewModbusMbmdFromConfig muss ebenfalls angepasst werden.

@andig andig marked this pull request as draft September 8, 2025 17:30
@tolot27
Copy link

tolot27 commented Oct 5, 2025

Vielleicht könnte man auch timeout genauso generell verfügbar machen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backlog Things to do later infrastructure Basic functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QCells unregelmäßig Fehler durch zu schnelle Anfragen und niedrige Latenz

3 participants