[api] Add conditional compilation for Home Assistant service subscriptions - #9900
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#9900
components: [api, homeassistant]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #9900 +/- ##
=======================================
Coverage 60.09% 60.09%
=======================================
Files 51 51
Lines 10303 10303
Branches 1372 1372
=======================================
Hits 6192 6192
Misses 3755 3755
Partials 356 356 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
👋 Hi there! This PR modifies 15 file(s) with codeowners. @OttoWinter, @landonr, @Links2004 - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds conditional compilation for Home Assistant service subscriptions in the API component to reduce binary size and memory usage for devices that don't use Hom
8000
e Assistant service calls. It introduces the USE_API_HOMEASSISTANT_SERVICES compilation flag that is automatically enabled when using relevant actions or platforms, or can be manually enabled via configuration.
- Adds conditional compilation guards around Home Assistant service-related code
- Automatically enables the feature when using
homeassistant.service,homeassistant.event, or homeassistant number/switch platforms - Provides manual configuration option
api: homeassistant_services: true
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 |
|---|---|
| esphome/core/defines.h | Adds the new USE_API_HOMEASSISTANT_SERVICES define |
| esphome/components/homeassistant/switch/init.py | Auto-enables the define for homeassistant switch platform |
| esphome/components/homeassistant/number/init.py | Auto-enables the define for homeassistant number platform |
| esphome/components/api/homeassistant_service.h | Wraps service-related classes with conditional compilation |
| esphome/components/api/custom_api_device.h | Guards service call methods with conditional compilation |
| esphome/components/api/api_server.h | Guards service call method declaration |
| esphome/components/api/api_server.cpp | Guards service call method implementation |
| esphome/components/api/api_pb2_service.h | Guards service subscription methods and handlers |
| esphome/components/api/api_pb2_service.cpp | Guards service subscription message handling |
| esphome/components/api/api_pb2_dump.cpp | Guards service message dump methods |
| esphome/components/api/api_pb2.h | Guards service-related protobuf message classes |
| esphome/components/api/api_pb2.cpp | Guards service message encoding/calculation methods |
| esphome/components/api/api_connection.h | Guards service call methods and subscription handling |
| esphome/components/api/api.proto | Adds ifdef option to service-related protobuf messages |
| esphome/components/api/init.py | Adds configuration option and auto-enables for service/event actions |
|
Thanks |
What does this implement/fix?
This PR adds conditional compilation for Home Assistant service subscriptions in the API component, similar to #9898 which did the same for Home Assistant state subscriptions.
This optimization reduces binary size and memory usage for devices that don't use Home Assistant service calls (e.g.,
homeassistant.service,homeassistant.event, or the homeassistant number/switch components).Key changes:
USE_API_HOMEASSISTANT_SERVICEScompilation flaghomeassistant.serviceorhomeassistant.eventactionshomeassistantplatform for number or switch componentsapi: homeassistant_services: trueBreaking change for external components:
External components using
CustomAPIDevice::call_homeassistant_service()orCustomAPIDevice::fire_homeassistant_event()will need to either:cg.add_define("USE_API_HOMEASSISTANT_SERVICES")in their Python codeTypes of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: