Skip to content

fix: refresh on input changes without an executor job per state change (#158 + test fix) - #160

Merged
bvweerd merged 4 commits into
devfrom
claude/pr158-test-fix
Oct 6, 2026
Merged

bvweerd merged 4 commits into
devfrom
claude/pr158-test-fix

Conversation

@bvweerd

@bvweerd bvweerd commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Carries bvweerd/simple_pid_controller#158 by @alaraun unchanged (commit 357c020), plus one test fix. Merging this with a merge commit also marks #158 as merged.

What #158 does

The 11 input listeners in sensor.py were plain functions. Home Assistant ran each one as an executor job for every state_changed event in the system. They also never matched, because entity_ids follow the device name and not <entry_id>_<key>. #158 replaces them with one @callback listener and a @callback event filter that matches the entry's inputs by registry unique_id. The PR description of #158 has the details.

Test fix (005127b)

test_unrelated_state_change_does_not_refresh never reached the unique_id check. Both entities went from no state or unknown to a value, and the filter rejects that before it looks at the unique_id. Replacing the whole unique_id check with return True left all tests green. The test now gives both entities a real value first. With that change, the same mutation makes the test fail, and it passes without it.

Behaviour change to be aware of

Before #158 the listeners never fired, so the controller only computed on its interval. Now a change to Kp, Ki, Kd, the setpoint, the output limits, the sample time, a switch or the start mode triggers a PID update straight away. The coordinator's debouncer allows at most one such update per 10 s. Each one adds an entry to the histories, shows a short "Actual Sample Time", and restarts the interval timer.

Also contains

bvweerd/simple_pid_controller#159 is merged in, so that lint is green here too. Once #159 is on dev that part drops out of this diff.

Validation

  • pytest: all pass on Python 3.14 / Home Assistant 2026.10.0b0 and on Python 3.13 / Home Assistant 2026.2.3
  • mypy and pre-commit run --all-files: clean

🤖 Generated with Claude Code

https://claude.ai/code/session_012VjGcBURcFQJMzcFaFvciV


Generated by Claude Code

alaraun and others added 4 commits October 5, 2026 22:42
The input listeners were plain functions, so Home Assistant ran each of
the 11 as an executor job for every state_changed event in the system,
and called hass.async_create_task from a worker thread. At shutdown the
executor is gone and every state change logs 11 "Executor shutdown has
been called" errors.

They also never matched: they compared against number.<entry_id>_<key>,
but entity_ids follow the device name, so a parameter change reached the
controller only on the next interval tick.

Use one callback listener with a callback event filter that matches the
entry's input entities by unique_id, as PIDDeviceHandle already does. An
entity being added, removed or passing through unavailable/unknown is
not treated as a change.
Home Assistant 2026.10 replaced voluptuous with probatio and now types
async_show_form's data_schema as probatio.Schema, so the lint job's mypy
step fails on dev (scheduled run of 2026-10-05) and on every pull request.
voluptuous is also no longer a Home Assistant dependency.

Import probatio as vol from 2026.10 on and voluptuous before that. The
choice goes by version, not by whether probatio imports: 2026.9 already
installs probatio but still expects voluptuous schemas.

The pre-commit mypy hook types against the latest stable release (2026.9)
and the lint job against the one pytest-homeassistant-custom-component
pins (2026.10), so the two config flow schemas are annotated Any.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012VjGcBURcFQJMzcFaFvciV
Both entities went from no state or unknown to a value, which the event
filter rejects before it looks at the unique_id. The test therefore kept
passing with the unique_id check replaced by 'return True'. Give them a
value first, so the change under test is a real one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012VjGcBURcFQJMzcFaFvciV
…ude/pr158-test-fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012VjGcBURcFQJMzcFaFvciV
@github-actions github-actions Bot added enhancement New feature or improvement bug Something isn't working as expected labels Oct 6, 2026
@bvweerd
bvweerd merged commit b9b8096 into dev Oct 6, 2026
@bvweerd
bvweerd deleted the claude/pr158-test-fix branch October 6, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected enhancement New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants