Skip to content

Stop treating a queued write as a failed one - #164

Open
mathieuletyrant wants to merge 1 commit into
gduteil:mainfrom
mathieuletyrant:queued-write-state
Open

Stop treating a queued write as a failed one#164
mathieuletyrant wants to merge 1 commit into
gduteil:mainfrom
mathieuletyrant:queued-write-state

Conversation

@mathieuletyrant

Copy link
Copy Markdown

One-character fix: an if that should be an elif.

In set_capability_value, the execution poller tests state 1 in an if of its own, then opens a fresh if/elif chain on state 2:

if execution_state == 1:
    _LOGGER.info("Execution_state waiting execution")

if execution_state == 2:        # new chain
    ...
elif execution_state == 3:
    completed = True
    break
else:                            # state 1 lands here
    _LOGGER.info("Execution_state error")
    break

So state 1 — waiting execution, the normal first answer to a write — logs waiting execution, falls into the else of the second chain, logs Execution_state error and breaks out.

completed stays False, so the optimistic capability["value"] = value after the loop never runs, and the entity keeps its old value until the next scheduled poll, up to a minute later. Nothing had failed: the write went through.

Closing the chain makes a queued execution fall through to the retry sleep, like an in-progress one:

queued then ok    waiting -> waiting -> in progress -> completed
immediate ok      completed
real error        waiting -> ERROR

The giveaway in the logs is an Execution_state waiting execution followed immediately by Execution_state error on a write that visibly succeeded.

Running on my installation: entities now reflect a change as soon as the write completes, instead of waiting for the next poll.

Independent of #160, #161, #162 and #163.

🤖 Generated with Claude Code

The execution poller tested state 1 in an if of its own, then opened a fresh
if/elif chain on state 2. So state 1 -- "waiting execution", the normal first
answer to a write -- logged "waiting execution" and immediately fell into the
else of the second chain, logged "Execution_state error" and broke out.

completed stayed False, so the optimistic local write that follows the loop
never ran and the entity kept its old value until the next scheduled poll,
up to a minute later. Nothing had actually failed; the write went through.

Turning that second if into an elif closes the chain. A queued execution now
falls through to the retry sleep like an in-progress one:

  queued then ok   waiting -> waiting -> in progress -> completed
  immediate ok     completed
  real error       waiting -> ERROR

The giveaway in the logs was an "Execution_state waiting execution" followed
straight away by "Execution_state error" on a write that had succeeded.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
mmnlfrrr pushed a commit to mmnlfrrr/cozytouch that referenced this pull request Sep 10, 2026
A write whose execution comes back in state 1, queued, fell through the state
handling: the first branch logged it, the next one tested for state 2 with a
fresh if instead of an elif, so state 1 reached the else, was logged as an
error and broke out of the polling loop. The write was then never confirmed and
the new value never applied locally, even though the appliance went on to carry
it out.

State 1 is uncommon but real: it shows up once across the 47 executions of a
field capture, which makes this an intermittent failure of every write path,
including the mode select, the boost switch and the setpoints added here.

Upstream PR gduteil#164 proposes the same one-line change, so either can be dropped
when the other lands.

Also refreshes the coordinator after writing a programmed setpoint, otherwise
the entity keeps showing the old value until the next poll, matching what
upstream PR gduteil#170 does for the other number entities.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ACWv1DVSmVzzfdVBRBarZF
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.

1 participant