Conversation
…ic temperature values
…ved data validation
…d data validation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1359 +/- ##
==========================================
- Coverage 99.89% 99.88% -0.01%
==========================================
Files 6 6
Lines 910 898 -12
Branches 126 126
==========================================
- Hits 909 897 -12
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR migrates the data modeling layer from mashumaro with orjson to pydantic v2, modernizing the codebase and improving type safety. The migration introduces a new value conversion utility that handles BSB-LAN's string-based JSON responses and refactors all model classes to use pydantic's validation framework.
Changes:
- Replaced
mashumaroandorjsondependencies withpydantic>=2.0and updated all model classes to inherit fromBaseModelinstead of using@dataclasswithDataClassJSONMixin - Introduced
_convert_bsblan_value()utility function and amodel_validatorinEntityInfoto convert raw BSB-LAN string values to appropriate Python types (float, int, time) before pydantic validation - Updated all model instantiation calls from
.from_dict()to.model_validate()and removed now-unnecessarytype: ignorecomments
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Updated dependencies to replace mashumaro/orjson with pydantic>=2.0; updated ruff config for pydantic BaseModel |
| uv.lock | Removed mashumaro and orjson packages, added pydantic package |
| src/bsblan/models.py | Converted all JSON response models to pydantic BaseModel; added _convert_bsblan_value utility and model_validator for type conversion; updated type annotations to be more specific (e.g., EntityInfo[float], EntityInfo[int]) |
| src/bsblan/bsblan.py | Replaced all .from_dict() calls with .model_validate(); removed type: ignore comments that are no longer needed |
| tests/test_entity_info_ha.py | Updated from_dict() to model_validate() in tests |
| tests/test_temperature_unit.py | Updated EntityInfo test values from strings to correct Python types (e.g., "10" → 10.0) |
…y and improve type conversion handling
…ve error handling in EntityInfo
|



This pull request migrates the codebase from
mashumaroandorjsontopydantic v2for data modeling and validation, and refactors all models and related logic to usepydantic's features. It introduces a new type conversion utility for BSB-LAN values and updates all model classes and instantiations accordingly. The changes also update dependencies and remove now-unnecessary type ignores. The most significant changes are grouped below.Migration from mashumaro/orjson to pydantic:
mashumaroandorjsondependencies withpydantic>=2.0inpyproject.toml, and updated linting config to reflect the new base class and compatibility notes. [1] [2] [3]src/bsblan/models.pyto usepydantic.BaseModelinstead of@dataclassandDataClassJSONMixin, updating field definitions, default values, and type annotations to leveragepydantic's validation and configuration. [1] [2] [3] [4] [5] [6] [7]Type conversion and validation improvements:
_convert_bsblan_valueutility and amodel_validatorinEntityInfoto handle conversion of raw BSB-LAN values to appropriate Python types (e.g., float, int, time) before model validation, ensuring consistent and reliable data handling. [1] [2].from_dict()to.model_validate()to construct models usingpydantic's validation mechanism insrc/bsblan/bsblan.py. [1] [2] [3] [4] [5]Type annotation and documentation updates:
EntityInfo[float],EntityInfo[int],EntityInfo[time], and adjusted docstrings and comments for clarity and accuracy. [1] [2] [3] [4] [5]Minor code and style cleanups:
type: ignore[assignment]comments as type conversions are now handled by the new validation logic. [1] [2]These changes modernize the codebase, improve type safety, and set the foundation for better maintainability and extensibility.