Skip to content

Comments

Switch to pydantic#1359

Merged
liudger merged 6 commits intomainfrom
switch-to-pydantic
Feb 23, 2026
Merged

Switch to pydantic#1359
liudger merged 6 commits intomainfrom
switch-to-pydantic

Conversation

@liudger
Copy link
Owner

@liudger liudger commented Feb 23, 2026

This pull request migrates the codebase from mashumaro and orjson to pydantic v2 for data modeling and validation, and refactors all models and related logic to use pydantic'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:

  • Replaced mashumaro and orjson dependencies with pydantic>=2.0 in pyproject.toml, and updated linting config to reflect the new base class and compatibility notes. [1] [2] [3]
  • Refactored all data models in src/bsblan/models.py to use pydantic.BaseModel instead of @dataclass and DataClassJSONMixin, updating field definitions, default values, and type annotations to leverage pydantic's validation and configuration. [1] [2] [3] [4] [5] [6] [7]

Type conversion and validation improvements:

  • Introduced _convert_bsblan_value utility and a model_validator in EntityInfo to 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]
  • Updated all usages of .from_dict() to .model_validate() to construct models using pydantic's validation mechanism in src/bsblan/bsblan.py. [1] [2] [3] [4] [5]

Type annotation and documentation updates:

  • Updated all model field type annotations to be more specific, e.g., 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:

  • Removed unnecessary 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.

Copilot AI review requested due to automatic review settings February 23, 2026 09:12
@liudger liudger added major This PR causes a major version bump in the version number. refactor Improvement of existing code, not introducing new features. labels Feb 23, 2026
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.88%. Comparing base (dca81e7) to head (9ae2c87).
⚠️ Report is 6 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a 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 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 mashumaro and orjson dependencies with pydantic>=2.0 and updated all model classes to inherit from BaseModel instead of using @dataclass with DataClassJSONMixin
  • Introduced _convert_bsblan_value() utility function and a model_validator in EntityInfo to 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-unnecessary type: ignore comments

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)

@sonarqubecloud
Copy link

@liudger liudger merged commit b985ed9 into main Feb 23, 2026
19 checks passed
@liudger liudger deleted the switch-to-pydantic branch February 23, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major This PR causes a major version bump in the version number. refactor Improvement of existing code, not introducing new features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant