Skip to content
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

refactor!: Split HassWSApi into resource-specific classes #18

Merged
merged 4 commits into from
Nov 15, 2024

Conversation

vicfergar
Copy link
Owner

Overview

This PR refactors the existing monolithic HassWSApi class by extracting resource-specific methods into dedicated API classes. This improves code organization, maintainability, and makes the codebase more modular while maintaining the same functionality.

⚠️ Breaking changes

The methods previously available directly on HassWSApi have been moved to their respective API classes. All calls need to be updated to use the new structure:

// Old way (NO LONGER WORKS)
await hassWSApi.ListAreasAsync();
await hassWSApi.CreateLabelAsync(label);
await hassWSApi.UpdateDeviceAsync(device);

// New way
await hassWSApi.Areas.ListAsync();
await hassWSApi.Labels.CreateAsync(label);
await hassWSApi.Devices.UpdateAsync(device);

New API Classes

Moved existing functionality into these dedicated classes:

  • AreasApi - Area management methods
  • CategoriesApi - Category registry operations
  • DevicesApi - Device registry operations
  • EntitiesEntriesApi - Entity registry management
  • FloorsApi - Floor registry operations
  • LabelsApi - Label management
  • ServicesApi - Service operations
  • StorageEntitiesApi - Storage entity operations
  • UsersApi - User management

Implementation Details

  • All API classes inherit from ResourceApi base class
  • Each API class takes HassClientWebSocket in constructor
  • Original methods removed from HassWSApi class
  • No changes to underlying WebSocket communication

Testing

  • Reorganized tests to match new API structure
  • Added new tests for base ResourceApi class
  • Updated all tests to use new API structure
  • Added tests to ensure Readme code blocks are up-to-date

Documentation

  • Updated XML documentation to reflect new class structure
  • Updated examples to show new API usage

Version Update

Due to breaking changes, this requires a major version bump:

  • Version updated from 1.0.15 to 2.0.0

Migration Guide

  • Update all direct method calls to use appropriate API property
  • Review and update any extension methods or utilities that wrap HassWSApi
  • Update tests to use new API structure

Copy link

Unit Test Results

684 tests  +1   684 ✔️ +1   8s ⏱️ +3s
  39 suites +1       0 💤 ±0 
    3 files   +1       0 ±0 

Results for commit 8ee26d8. ± Comparison against base commit 9f76e15.

@vicfergar vicfergar merged commit ae86e8a into main Nov 15, 2024
2 checks passed
@vicfergar vicfergar deleted the feature/resources-apis branch November 15, 2024 19:20
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.

1 participant