-
Notifications
You must be signed in to change notification settings - Fork 2
Feature: Lazy loading #1307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Lazy loading #1307
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request introduces lazy loading for improved initialization performance and adds mDNS device discovery via Zeroconf. The main objective is to defer section validation until data is actually needed, significantly reducing startup time for the python-bsblan library (important for Home Assistant integration).
Changes:
- Implemented lazy loading architecture: minimal initialization (firmware only) with on-demand section validation
- Added granular hot water parameter validation (validates only essential/config/schedule groups as needed, not all 29 params)
- Added mDNS/Zeroconf device discovery utility and updated examples to use environment-based configuration
- Enhanced developer documentation with skill guides, prompt templates, and lazy loading architecture details
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/bsblan/bsblan.py |
Core lazy loading implementation: _setup_api_validator(), _ensure_section_validated(), and _ensure_hot_water_group_validated() methods for on-demand validation; _validate_target_temperature() now async with lazy temperature range initialization |
tests/test_temperature_validation.py |
Updated temperature validation tests to async with lazy loading support |
tests/test_state.py |
Changed validated section from "state" to "heating" (correct for lazy loading) |
tests/test_initialization.py |
Updated to test new _setup_api_validator() instead of multiple initialization methods |
tests/test_hotwater_state.py |
Added test setup to mark hot water groups as validated |
tests/test_hot_water_additional.py |
Added granular validation tests and updated existing tests to mark groups as validated |
examples/discovery.py |
New mDNS discovery utility using Zeroconf for finding BSB-LAN devices |
examples/control.py |
Updated to use discovery utility and environment variables instead of hardcoded values |
examples/profile_init.py |
New profiling utility to measure lazy loading performance improvements |
pyproject.toml |
Added zeroconf>=0.148.0 as development dependency |
uv.lock |
Lock file updated with zeroconf and ifaddr dependencies |
.github/copilot-instructions.md |
Added hot water parameter groups table and lazy loading architecture documentation |
.github/skills/bsblan-parameters/SKILL.md |
New skill guide for adding parameters with hot water group mappings |
.github/skills/bsblan-testing/SKILL.md |
New skill guide for testing patterns and lazy loading test setup |
.github/prompts/add-parameter.prompt.md |
New prompt template for adding parameters |
.github/prompts/code-review.prompt.md |
New prompt template for code reviews |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1307 +/- ##
==========================================
+ Coverage 99.60% 99.87% +0.27%
==========================================
Files 6 6
Lines 767 827 +60
Branches 83 102 +19
==========================================
+ Hits 764 826 +62
+ Partials 3 1 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…losure on success
…ntion in lazy loading
|



🚀 Performance Comparison: Lazy Loading
Before (Eager Loading)
After (Lazy Loading)
Granular Hot Water Loading
Hot water parameters split into 3 groups for more efficient loading:
hot_water_state()hot_water_config()hot_water_schedule()Race Condition Prevention
Added asyncio locks (double-checked locking pattern) to prevent duplicate network requests when concurrent calls access the same section before validation completes.
Home Assistant Impact
Summary
This pull request introduces significant improvements to developer documentation, parameter management, and device discovery for the python-bsblan library. The main highlights include new developer skills and prompt templates, enhanced documentation on parameter grouping and lazy loading, and the addition of mDNS-based device discovery (via Zeroconf) for easier setup and testing. The example control script is updated to use these new discovery features, and dependency management is updated accordingly.
Documentation and Developer Guidance:
.github/skills/bsblan-parameters/SKILL.md) and testing (.github/skills/bsblan-testing/SKILL.md), covering naming conventions, step-by-step instructions, test patterns, coverage requirements, and validation commands. [1] [2].github/prompts/add-parameter.prompt.md,.github/prompts/code-review.prompt.md). [1] [2]Parameter Grouping and Lazy Loading:
.github/copilot-instructions.md). [1] [2]_validated_hot_water_groups) to theBSBLANclass for managing which hot water parameter groups have been validated, supporting the new lazy loading architecture (src/bsblan/bsblan.py).Device Discovery and Example Improvements:
examples/discovery.pyutility that uses mDNS/Zeroconf to discover BSB-LAN devices on the local network, and provides helpers for retrieving device host/port from the environment or discovery.examples/control.py). [1] [2] [3]Dependency Management:
zeroconfas a development dependency to support mDNS-based device discovery (pyproject.toml).