Skip to content

fix(1P): treat Meter (326) and Charging Signal (242) registers as bitfields - #155

Open
SupermotoJerry wants to merge 2 commits into
Lewa-Reka:mainfrom
SupermotoJerry:fix/1p-meter-bitfield
Open

SupermotoJerry wants to merge 2 commits into
Lewa-Reka:mainfrom
SupermotoJerry:fix/1p-meter-bitfield

Conversation

@SupermotoJerry

@SupermotoJerry SupermotoJerry commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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 0x0383 and 0x5F01 matched no option, so the selects never showed a value and logged No option found for mapping ... on every poll. Writing them also overwrote the whole register.

Changes:

  • Meter (326, Ex_MeterCT): map only bit0 (meter enable) to Disable / Enable. Removed Generator: 13, which isn't a value from the protocol.
  • Charging Signal (242, Gen_Grid_Signal): map only bits0-1 to Normal / Grid / Generator / Both.
  • Both selects keep the last raw register value in a global, and their write_lambda does 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 Enable and Grid.

Changes relate to

  • Docs
  • Deye 3P LP
  • Deye 3P HV
  • Deye 1P LP
  • Other

🤖 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:

  • Treat the 1P Meter and Charging Signal registers as bitfields so their selects correctly display values from registers containing multiple fields.
  • Preserve unrelated register bits during select writes and skip writes until the raw register value has been read.

Enhancements:

  • Remove the unsupported Generator option from the Meter select.

SupermotoJerry and others added 2 commits October 11, 2026 12:36
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>
@sourcery-ai

sourcery-ai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Updates 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 write

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Treat the Meter and Charging Signal registers as bitfields while preserving unrelated register bits during writes.
  • Map Meter enable to bit 0 and remove the invalid Generator option.
  • Map Charging Signal states to bits 0–1 while ignoring upper fields.
  • Cache the latest raw register values and perform read-modify-write operations.
  • Skip writes with a warning until the corresponding register has been read.
pv_inverter/packages/deye_hybrid_1p/device.yaml
pv_inverter/packages/deye_hybrid_1p/grid.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#154 Make the Meter select for register 326 interpret only bit 0 as the meter enable state, remove the invalid Generator option, and correctly display values from bitfield registers. ✅
#154 Make the Charging Signal select for register 242 interpret only bits 0-1 while ignoring unrelated upper bits, so valid values such as 0x5F01 display the correct signal option. ✅
#154 Preserve unrelated register bits when either select is written by performing a read-modify-write, and avoid writing a partial value before the register has been read. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
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.

1P: Meter (326) and Charging Signal (242) selects log "No option found for mapping" - registers are bitfields

1 participant