Modbus: unify delay and timeout settings (BC) - #31996
Conversation
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="util/templates/template_modbus.go" line_range="93-95" />
<code_context>
for _, p := range typeParams {
// don't overwrite custom values
- if values[p.Name] != nil {
+ if v, ok := values[p.Name]; ok && v != nil && v != "" {
continue
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Comparing interface values to empty string can panic for non-comparable underlying types.
`v != ""` on an `any` can panic when `v` holds a non-comparable type (e.g. map, slice), since interface equality requires a comparable underlying type. Please avoid direct comparison and instead type-assert to `string` before comparing, or use a helper that inspects the concrete type to decide whether it is "empty."
</issue_to_address>
### Comment 2
<location path="meter/cfos.go" line_range="40" />
<code_context>
}
- return NewCfosPowerBrain(ctx, cc.URI, cc.ID)
+ return NewCfosPowerBrain(ctx, cc)
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Same type mismatch when passing config to NewCfosPowerBrain.
`cc` is an anonymous struct that embeds `modbus.TcpSettings`, but `NewCfosPowerBrain` now expects a `modbus.TcpSettings`. You should pass `cc.TcpSettings` instead of `cc`; otherwise this will not compile.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@premultiply had wanted to do this for a very long time... |
|
Why are we getting spammed here? |
|
@copilot resolve the merge conflicts in this pull request |
# Conflicts: # templates/definition/meter/wattsonic.yaml
Merged |
|
How about |
wdym? |
|
Inside the Huawei template, the Search for |
|
It's the odd one out. With only a single device ever needing this I'd much rather remove it entirely... |
|
Didn't know it was only für Huawei. Will try to reach out to them. |
|
Claude says that swallowed requests after a connect is a common problem with many Modbus devices and that it is advisable to have a connect delay of 0,5–2s. |
|
Claude says many things during a long day... |
|
mbproxy and modbus-proxy both have a connect delay parameter. |
exactly the reason i need to use external modbus proxy - with the huawei inverter i need a timeout of 15s and connection_time of 2s to work properly with tiagocouthinos modbus-proxy. when i configure it with evcc, it does not work at all. maybe worth implementing it here as well? |
|
Would it help if we honored delay after connect to get rid of the connect delay? It‘s really only Huawei that needs this, very annoying… |
|
Huawei requires a 1-2s delay after connect, also depending on how old the FW is. Applying a multi-second delay to requests as well is not a good idea IMHO. @mptr8956 The 1s delay works for most setups. Maybe you want to open a discussion where we can discuss your setup. |
Adds
delayandtimeoutas first-class modbus settings, available consistently everywhere modbus is configured — template, yaml and Go device level. Fixes #31972.util/modbus
SettingsandTcpSettingsgainDelayandTimeoutfields(Tcp)Settings.Connection(ctx)method creates the connection and applies both (optional protocol override for forced-proto devices, e.g. ABL/ASCII)Templates
delay/timeoutadded to the modbus include: advanced params on all modbus connection types, rendered bymodbus.tplwhen set — available in all 188 modbus templatesmodbusparam (likeid/port/baudrate/comset); carried over:luxtronik:timeout: 10shuawei-sun2000-inverter/-hybrid:timeout: 15swattsonic:delay: 100mstimeout/delayparams inabl,pracht-alpha,luxtronik,wattsonic,huawei-sun2000-*,solaredge-invertermarked deprecated (kept, not removed) and their per-source render lines dropped — the config keys stay valid and values continue to apply via the modbus includeDevices
settings.Connection(ctx)-based constructors takingmodbus.(Tcp)Settings— delay/timeout now work uniformlydelay: 100ms, EVSE-DINdelay: 200ms, Em2Godelay: 60ms, Alphatecdelay: 20msplugin/modbus,plugin/sunspec,meter/mbmdand the modbus proxy use the same mechanism (connectdelayunchanged)cachehandling (Bender, Hoymiles DTU, Ambibox) is unchanged🤖 Generated with Claude Code