Skip to content

Migrate all platforms to abstract base classes#662

Merged
puddly merged 10 commits intozigpy:devfrom
puddly:puddly/abstract-base-classes
Feb 24, 2026
Merged

Migrate all platforms to abstract base classes#662
puddly merged 10 commits intozigpy:devfrom
puddly:puddly/abstract-base-classes

Conversation

@puddly
Copy link
Copy Markdown
Contributor

@puddly puddly commented Feb 19, 2026

We've already migrated the larger platforms, this migrates the rest. I've also removed **kwargs from the async_ method calls for stronger typing.

This is just a code quality improvement and should have no external effects.

Copy link
Copy Markdown
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 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 **kwargs from 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
Copy link
Copy Markdown

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (a0d4782) to head (e436b19).
⚠️ Report is 5 commits behind head on dev.

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.
📢 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.

TheJulianJES added a commit to TheJulianJES/zha that referenced this pull request Feb 21, 2026
Co-authored-by: puddly <32534428+puddly@users.noreply.github.com>
@TheJulianJES TheJulianJES mentioned this pull request Feb 21, 2026
@TheJulianJES
Copy link
Copy Markdown
Contributor

Had a quick look at this and everything seems fine

@puddly puddly marked this pull request as ready for review February 24, 2026 18:43
@puddly puddly merged commit 0c82733 into zigpy:dev Feb 24, 2026
14 checks passed
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.

3 participants