Skip to content

fix: wait for device confirmation on switch/select/number commands#25

Open
jlopez wants to merge 1 commit into
mainfrom
fix/issue-24
Open

fix: wait for device confirmation on switch/select/number commands#25
jlopez wants to merge 1 commit into
mainfrom
fix/issue-24

Conversation

@jlopez

@jlopez jlopez commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaces fire-and-forget MQTT commands plus optimistic local state writes with wait=True plus a merge of the device's echoed property dict.
  • When the device does not confirm within the socketry timeout, log a warning and leave coordinator data untouched.
  • Applied to switch.py, select.py, and number.py — all three platforms shared the same defect.

Why

Previously, if the device firmware refused a command (e.g. AC output turn-off while a load is attached), HA would record a phantom state change that was later silently corrected by an unrelated periodic DevicePropertyChange push — breaking automations that rely on the command actually taking effect (the original report involved a low-battery cutoff that drained the battery anyway because the inverter never disengaged).

The fix:

  • wait=True blocks until the device echoes the change (or a 10s timeout).
  • The echoed dict is merged into coordinator data, so HA reflects what the device actually did (which may differ from what was commanded — clamping, refusal, etc.).
  • A None response (timeout) leaves state alone and emits a warning so users can build watchdog automations.

Fixes #24

Test plan

  • uv run ruff check . && uv run ruff format --check .
  • uv run mypy custom_components/jackery
  • uv run pytest tests/test_switch.py tests/test_select.py tests/test_number.py — all 96 tests pass, 100% coverage on the three modules
  • Existing call-site assertions updated to include wait=True
  • New tests for: device echo merged into state, divergent echo (firmware refusal / clamping) reflected in HA, timeout (None response) leaves state untouched

🤖 Generated with Claude Code

…ng state

Replaces fire-and-forget MQTT commands plus an optimistic local state
write with `wait=True` plus a merge of the device's echoed property dict.
When the device does not confirm within the socketry timeout, log a
warning and leave coordinator data untouched.

Previously, if the device firmware refused a command (e.g. AC output
turn-off while a load is attached), HA would record a phantom state
change that was later silently corrected by an unrelated periodic
DevicePropertyChange push, breaking automations that depend on the
command actually taking effect.

Fixes #24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant