Skip to content

fix(iobroker): reconcile rejected vehicle/energy writes instead of leaving state looking applied - #124

Merged
Bre77 merged 1 commit into
mainfrom
fm/iob-write-reconcile
Aug 13, 2026
Merged

fix(iobroker): reconcile rejected vehicle/energy writes instead of leaving state looking applied#124
Bre77 merged 1 commit into
mainfrom
fm/iob-write-reconcile

Conversation

@Bre77

@Bre77 Bre77 commented Aug 13, 2026

Copy link
Copy Markdown
Member

Intent

  • VehicleHandler/EnergyHandler's handleStateChange() caught and logged their own write failures, so main.ts's onStateChange() caller never saw the rejection - after a rejected lock/temperature/charge-limit/energy write, the ioBroker object state kept showing the requested value as if it had applied.
    • Write failures now propagate out of handleStateChange() to onStateChange(), the single place that logs and reconciles - no more double logging.
    • Each write now goes through a writeAndReconcile(id, value, write) helper (colocated in each handler): it acks the requested value on success, and on failure re-acks the last confirmed value so the state never lies about what applied.
  • No new modules or retry/queue machinery - same dispatch points, just honest state on failure.

Test plan

  • pnpm --filter iobroker.teslemetry test - new coverage for a rejected lock command and a rejected temperature write (vehicle) and a rejected backup-reserve write (energy), each restoring the prior value and propagating exactly once with no handler-level log; plus matching successful-write ack cases
  • pnpm --filter iobroker.teslemetry check (tsc)
  • pnpm --filter iobroker.teslemetry build
  • pnpm lint

…aving state looking applied

handleStateChange() in VehicleHandler/EnergyHandler used to catch and log
its own write failures, so the onStateChange() caller in main.ts never saw
the rejection and the object state kept showing the requested value as if
it had applied. Writes now go through a writeAndReconcile() helper that
acks the requested value on success and restores the last confirmed value
on failure, letting the failure propagate to onStateChange() as the single
place that logs it.
@Bre77 Bre77 added the fm Opened by a Firstmate crewmate label Aug 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c5ccba2eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

* shows a requested value that was never actually applied.
*/
private async writeAndReconcile(id: string, value: any, write: () => Promise<any>): Promise<void> {
const prior = await this.adapter.getStateAsync(id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Cache the confirmed state before the user overwrites it

When a user changes any directly writable state, ioBroker has already stored the incoming ack: false value before onStateChange() invokes this helper, so getStateAsync(id) returns the requested value rather than the previously acknowledged one. If setTemps, setChargeLimit, setSentryMode, or an energy operation write rejects, the catch therefore re-writes that rejected value with ack: true, still making it look applied; the identical helper in EnergyHandler has the same problem. Preserve confirmed values separately instead of reading the current state here—the new tests miss this because they invoke the handler while the fake store still contains the old value.

AGENTS.md reference: AGENTS.md:L171-L171

Useful? React with 👍 / 👎.

@Bre77
Bre77 merged commit 26e1584 into main Aug 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fm Opened by a Firstmate crewmate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant