Skip to content

fix ioBroker SoC - #4267

Merged
LKuemmel merged 1 commit into
openWB:masterfrom
seaspotter:fix/iobroker-soc-timestamp
Nov 6, 2026
Merged

LKuemmel merged 1 commit into
openWB:masterfrom
seaspotter:fix/iobroker-soc-timestamp

Conversation

@seaspotter

@seaspotter seaspotter commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Use 'lc' (last changed) instead of 'ts' (last update)

Summary by Sourcery

Bug Fixes:

  • Use the ioBroker state's last-changed timestamp when recording SoC update times.

@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates ioBroker SoC timestamp handling to use lc (last changed) instead of ts (last update), ensuring the reported timestamp reflects when the SoC value actually changed.

File-Level Changes

Change Details Files
Use the ioBroker state’s last-changed timestamp for SoC freshness metadata.
  • Replace the ts field with lc when deriving the SoC timestamp.
  • Continue converting the millisecond timestamp to Unix seconds and preserving None when unavailable.
packages/modules/vehicles/iobroker/soc.py

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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/modules/vehicles/iobroker/soc.py" line_range="35" />
<code_context>
             f"Ungültiger SoC-Wert {soc}% von State '{cfg.state_soc}' erhalten "
             "(erwartet: 0-100). Bitte State-ID und Skalierung in ioBroker prüfen.")
-    soc_timestamp = int(soc_state['ts'] / 1000) if soc_state.get('ts') else None
+    soc_timestamp = int(soc_state['lc'] / 1000) if soc_state.get('lc') else None

     if cfg.state_range is None or cfg.state_range == "":
</code_context>
<issue_to_address>
**Old SoC readings appear fresh**

When the state's last-changed time is absent, zero, or differs from the request time, `fetch_soc` uses `lc` for `soc_timestamp`, so ioBroker timestamps no longer mean the documented last-request time. When `lc` is absent or zero, `fetch_soc` passes `None` to `CarState`, which substitutes the current time and lets `ConfigurableVehicle` accept stale SoC as fresh.

Use the state's request timestamp (`ts`) for `soc_timestamp` to preserve the documented meaning and avoid treating an absent `lc` as a current timestamp.
</issue_to_address>

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

f"Ungültiger SoC-Wert {soc}% von State '{cfg.state_soc}' erhalten "
"(erwartet: 0-100). Bitte State-ID und Skalierung in ioBroker prüfen.")
soc_timestamp = int(soc_state['ts'] / 1000) if soc_state.get('ts') else None
soc_timestamp = int(soc_state['lc'] / 1000) if soc_state.get('lc') else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Old SoC readings appear fresh

When the state's last-changed time is absent, zero, or differs from the request time, fetch_soc uses lc for soc_timestamp, so ioBroker timestamps no longer mean the documented last-request time. When lc is absent or zero, fetch_soc passes None to CarState, which substitutes the current time and lets ConfigurableVehicle accept stale SoC as fresh.

Use the state's request timestamp (ts) for soc_timestamp to preserve the documented meaning and avoid treating an absent lc as a current timestamp.

Prompt for AI agents
In `packages/modules/vehicles/iobroker/soc.py` at line 35:

**Old SoC readings appear fresh**

When the state's last-changed time is absent, zero, or differs from the request time, `fetch_soc` uses `lc` for `soc_timestamp`, so ioBroker timestamps no longer mean the documented last-request time. When `lc` is absent or zero, `fetch_soc` passes `None` to `CarState`, which substitutes the current time and lets `ConfigurableVehicle` accept stale SoC as fresh.

Use the state's request timestamp (`ts`) for `soc_timestamp` to preserve the documented meaning and avoid treating an absent `lc` as a current timestamp.

@seaspotter
seaspotter requested a review from LKuemmel November 5, 2026 22:45
@LKuemmel
LKuemmel merged commit c12545e into openWB:master Nov 6, 2026
2 checks passed
@seaspotter
seaspotter deleted the fix/iobroker-soc-timestamp branch November 11, 2026 10:23
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.

2 participants