-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add delay to Modbus template #23054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add delay to Modbus template #23054
Conversation
There was a problem hiding this 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
delayparameter 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 |
There was a problem hiding this 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.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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time.Duration
?
|
Das Delay scheint nirgendwo benutzt zu werden? Es muss ja auch gesetzt werden. Dafür wäre es vmtl. sinnvoll, die |
|
Vielleicht könnte man auch |
Fixes #22723 (comment)