Repository navigation
fix(1P): treat Meter (326) and Charging Signal (242) registers as bitfields - #155
SupermotoJerry wants to merge 2 commits into
Conversation
Register 326 (Ex_MeterCT) packs meter enable, phase, direction and meter type into one word, so real values such as 0x0383 (SDM230 on phase A) matched no option and logged 'No option found for mapping 899'. Map only bit0 to Disable/Enable and preserve the other bits on write. Drop the bogus 'Generator: 13' option. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Only bits0-1 hold the grid/generator signal; the upper byte carries other data on some inverters (e.g. 0x5F01), which matched no option and logged 'No option found for mapping 24321'. Map bits0-1 and preserve the rest on write. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Reviewer's GuideUpdates the 1P Meter (326) and Charging Signal (242) selects to decode only their protocol-defined bitfields, eliminating unmapped values from composite registers. Each select caches the raw value from polling and merges changes into it on write, preserving other fields; writes are safely skipped with a warning if no initial register value is available. Sequence diagram for bitfield select read and writesequenceDiagram
participant Modbus
participant MeterSelect
participant ChargingSignalSelect
participant RawCache
Modbus->>MeterSelect: poll register 326
MeterSelect->>RawCache: meter_ct_raw = x
MeterSelect->>MeterSelect: decode x & 0x0001
MeterSelect-->>MeterSelect: show Disable or Enable
Modbus->>ChargingSignalSelect: poll register 242
ChargingSignalSelect->>RawCache: gen_grid_signal_raw = x
ChargingSignalSelect->>ChargingSignalSelect: decode x & 0x0003
ChargingSignalSelect-->>ChargingSignalSelect: show Normal, Grid, Generator, or Both
MeterSelect->>RawCache: read meter_ct_raw
alt raw value available
MeterSelect->>Modbus: write preserved bits | value & 0x0001
else register not read
MeterSelect-->>MeterSelect: write skipped with warning
end
ChargingSignalSelect->>RawCache: read gen_grid_signal_raw
alt raw value available
ChargingSignalSelect->>Modbus: write preserved bits | value & 0x0003
else register not read
ChargingSignalSelect-->>ChargingSignalSelect: write skipped with warning
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the bit assignments or write masks are wrong, selecting an option could change the inverter's meter or grid/generator configuration and leave that setting active after a revert. The affected register values are bounded and can be corrected by writing the intended settings again, but reverting the code alone would not undo a device-side change.
Description
Fixes #154.
The 1P Meter (register 326) and Charging Signal (register 242) selects treat the whole register as one enum, but on the 1P both registers hold more than one field. Real values such as
0x0383and0x5F01matched no option, so the selects never showed a value and loggedNo option found for mapping ...on every poll. Writing them also overwrote the whole register.Changes:
Ex_MeterCT): map only bit0 (meter enable) toDisable/Enable. RemovedGenerator: 13, which isn't a value from the protocol.Gen_Grid_Signal): map only bits0-1 toNormal/Grid/Generator/Both.write_lambdadoes a read-modify-write, so the other bits (meter type, phase, direction, upper byte of 242) are preserved. If the register hasn't been read since boot, the write is skipped with a warning instead of writing a partial value.Tested on a SUN-10K-SG02LP1-AU (ESPHome 2026.9.1): both errors are gone and the selects show
EnableandGrid.Changes relate to
🤖 Generated with Claude Code
Summary by Sourcery
Fix 1P Meter and Charging Signal selects to read and update only their respective bitfields without overwriting other register data.
Bug Fixes:
Enhancements: