Repository navigation
Move writable_component to entities so the tooling drops pydantic (2.2.2) - #26
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
scripts/rename_entities.pyonly reads the entity table, yet importing it pulled in the bridge's runtime dependencies: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 frommqtt.pytoentities.py, beside theComponentenum it returns.entities.pyimports only the standard library plusjk_settings;jk_modbus.pyandjk_settings.pyare standard-library only.Callers updated:
mqtt.py(6 uses, now imports it fromentities),dashboard.py,dashboards/check_entities.py,scripts/rename_entities.py.Two consequences:
PYTHONPATH=jkbms2mqtt/srcandwebsocketsalone — no package install. Its docstring now says so.dashboard.pyimportedmqttonly 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.pyruns each check in a subprocess with the modules blocked at import time:import jkbms2mqtt.mqttThe 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 coveragecheck_entities.pypasses all four write-tier combinationsCloses #24
🤖 Generated with Claude Code