Skip to content

Move writable_component to entities so the tooling drops pydantic (2.2.2) - #26

Merged
basmeerman merged 1 commit into
mainfrom
fix/writable-component-without-pydantic
Sep 16, 2026
Merged

basmeerman merged 1 commit into
mainfrom
fix/writable-component-without-pydantic

Conversation

@basmeerman

Copy link
Copy Markdown
Owner

Why

scripts/rename_entities.py only reads the entity table, yet importing it pulled in the bridge's runtime dependencies:

scripts/rename_entities.py -> jkbms2mqtt.mqtt -> jkbms2mqtt.config -> pydantic, yaml

An operator migrating an install (MIGRATION.md#entity-ids) had to build a virtualenv with the whole add-on package just to print a rename plan.

What changes

writable_component() moves from mqtt.py to entities.py, beside the Component enum it returns. entities.py imports only the standard library plus jk_settings; jk_modbus.py and jk_settings.py are standard-library only.

Callers updated: mqtt.py (6 uses, now imports it from entities), dashboard.py, dashboards/check_entities.py, scripts/rename_entities.py.

Two consequences:

  • the rename script runs from a checkout with PYTHONPATH=jkbms2mqtt/src and websockets alone — no package install. Its docstring now says so.
  • dashboard.py imported mqtt only for this function, so the dashboard generator no longer needs pydantic either.

The bridge itself is unchanged, and the generated dashboard artifacts are byte-identical — this is an import-only change.

Proof, not assertion

tests/unit/test_import_independence.py runs each check in a subprocess with the modules blocked at import time:

Check Blocked Result
rename script builds its target ids pydantic, yaml, aiomqtt, pymodbus passes
generator builds a dashboard pydantic, aiomqtt, pymodbus (yaml allowed) passes
control: import jkbms2mqtt.mqtt pydantic fails, as it must

The control matters: without it the first two would pass just as happily if the blocker stopped working.

Test plan

  • ruff, mypy, pytest — 563 passed, 100 % branch coverage
  • check_entities.py passes all four write-tier combinations
  • Regenerated dashboard artifacts byte-identical
  • Rename script imports and computes all 105 target ids with pydantic/yaml/aiomqtt/pymodbus blocked

Closes #24

🤖 Generated with Claude Code

scripts/rename_entities.py only reads the entity table, but importing it
pulled in pydantic and PyYAML: it took writable_component from
jkbms2mqtt.mqtt, and mqtt.py imports config.py. Migrating an install
therefore meant building a virtualenv with the whole add-on package.

writable_component is four lines and returns a Component, which lives in
entities.py — a module that imports only the standard library and
jk_settings. Moving it there breaks the chain for every caller that does
not otherwise need the MQTT layer.

Effects:

- the rename script imports only entities / jk_modbus / jk_settings, so
  it runs from a checkout with PYTHONPATH and websockets, no install;
- dashboard.py imported mqtt solely for this function, so the dashboard
  generator no longer needs pydantic either — PyYAML alone;
- the bridge is unchanged: mqtt.py imports the function from entities.

Guarded by tests/unit/test_import_independence.py, which blocks the
modules at import time in a subprocess and includes a control asserting
mqtt.py still fails without pydantic, so the checks cannot pass vacuously.
The generated dashboard artifacts are byte-identical.

Add-on version 2.2.2.

Closes #24

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@basmeerman
basmeerman merged commit 70446c4 into main Sep 16, 2026
4 checks passed
@basmeerman
basmeerman deleted the fix/writable-component-without-pydantic branch September 16, 2026 22:15
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.

rename_entities.py pulls in pydantic/PyYAML through jkbms2mqtt.mqtt

1 participant