Migrate all platforms to abstract base classes#662
Conversation
There was a problem hiding this comment.
Pull request overview
This PR completes the migration of all platform entities to use abstract base classes (ABC), improving code structure and type safety across the ZHA application. The changes remove **kwargs from async method signatures in favor of explicitly typed parameters, making the API more self-documenting and enabling stronger type checking.
Changes:
- Introduced abstract base classes for all remaining platform entity types (update, switch, siren, sensor, select, number, lock, light, fan, device_tracker, cover, climate, button, binary_sensor, alarm_control_panel)
- Removed
**kwargsfrom async methods and replaced with explicitly typed parameters - Moved common properties and methods to base classes while making entity-specific implementations abstract
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| zha/application/platforms/update.py | Added ABC import, made BaseFirmwareUpdateEntity inherit from ABC, added return type annotation for state property |
| zha/application/platforms/switch.py | Converted BaseSwitch to ABC with abstract methods, moved concrete implementations to subclasses, removed **kwargs from async_turn_on/off methods |
| zha/application/platforms/siren.py | Created BaseSiren abstract class, moved common properties and methods to base class, changed async_turn_on signature to explicit parameters |
| zha/application/platforms/sensor/init.py | Created BaseSensor abstract class with abstract native_value property, simplified info_object implementation, added unit setting for SmartEnergyMetering |
| zha/application/platforms/select.py | Created BaseSelectEntity abstract class with abstract current_option and async_select_option methods |
| zha/application/platforms/number/init.py | Made BaseNumber inherit from ABC, converted native_value and async_set_native_value to abstract methods |
| zha/application/platforms/lock/init.py | Created BaseLock abstract base class with abstract is_locked, async_lock, and async_unlock methods |
| zha/application/platforms/light/init.py | Made async_turn_on, async_turn_off, and _gateway abstract in BaseClusterHandlerLight |
| zha/application/platforms/fan/init.py | Made BaseFan inherit from ABC, removed **kwargs from async_turn_on/off methods |
| zha/application/platforms/device_tracker.py | Created BaseDeviceTracker abstract class with abstract is_connected, battery_level, and source_type properties |
| zha/application/platforms/cover/init.py | Created BaseCover abstract class, changed method signatures to explicit parameters, removed unused ATTR imports |
| zha/application/platforms/climate/init.py | Created BaseThermostat abstract class with comprehensive abstract properties and methods, changed async_set_temperature to explicit parameters, removed unused ATTR imports |
| zha/application/platforms/button/init.py | Created BaseButton abstract class with abstract async_press method, added ButtonEntityInfo base class |
| zha/application/platforms/binary_sensor/init.py | Created BaseBinarySensor abstract class with abstract is_on property |
| zha/application/platforms/alarm_control_panel/init.py | Created BaseAlarmControlPanel abstract class with abstract properties and async alarm control methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #662 +/- ##
==========================================
+ Coverage 97.44% 97.48% +0.03%
==========================================
Files 62 62
Lines 10733 10876 +143
==========================================
+ Hits 10459 10602 +143
Misses 274 274 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: puddly <32534428+puddly@users.noreply.github.com>
|
Had a quick look at this and everything seems fine |
We've already migrated the larger platforms, this migrates the rest. I've also removed
**kwargsfrom theasync_method calls for stronger typing.This is just a code quality improvement and should have no external effects.