Repository navigation
Add typed event data - #1967
Add typed event data#1967Bascht74 wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1967 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 30 30
Lines 5354 5373 +19
=========================================
+ Hits 5354 5373 +19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. ℹ️ Recent review info
WalkthroughThe event protobuf messages and Python models add fields for an event value and its name. Tests cover conversion of populated and absent fields. ChangesEvent value fields
Priority: Estimated code review effort: 2 (Simple) | ~8 minutes Change: Feature Suggested reviewers: Merge Risk:
|
# Conflicts: # aioesphomeapi/api_pb2.py
There was a problem hiding this comment.
🔵 Needs a closer look
The wire-format and event-data contract awaits cross-repository maintainer design review and confirmation that the dependent ESPHome change has landed before merging.
No open issues 🎉
What changed in this PR
Adds typed event data to aioesphomeapi’s ESPHome Native API models, enabling consumers such as Home Assistant to receive boolean, integer, float, and string event attributes.
Changes:
- Extends the event protocol and regenerated bindings with variable definitions, indexed values, and a dropped-values flag.
- Adds public event data models with empty-list defaults for older firmware and handling for unknown variable types.
- Adds tests for typed values, float conversion, dropped values, and JSON round trips.
| File | Description |
|---|---|
tests/test_model.py |
Tests event data conversion, compatibility defaults, and serialization. |
aioesphomeapi/model.py |
Adds and exports typed event models; extends event metadata and payloads. |
aioesphomeapi/api.proto |
Defines event variables, typed values, and dropped-value reporting. |
aioesphomeapi/api_pb2.py |
Regenerates Python bindings for the extended event protocol. |
Review effort: Balanced
What does this implement/fix?
An event entity can declare typed variables, and each event sends the values it sets.
EventInfo.variables: list ofEventVariablewithnameandtype(EventVariableType:BOOL,INT,FLOAT,STRING). A type this version does not know becomesNone, like the other enums.Event.values: list ofEventVariableValuewithindexintoEventInfo.variablesandbool_,int_,float_,string_. The field that matches the type of the variable holds the value, as inExecuteServiceArgument.Event.valuesis also empty for older queued events that the device sent without their values under backpressure;Event.values_droppedisTruefor those events. The device does not keep whether such an event had values, so the flag is alsoTruefor one that set none.api.protohas the event section of esphome/esphome#21528;api_pb2.pyis regenerated with the proto builder image.Home Assistant passes each value as an event attribute with its native type (home-assistant/core#188624) and maps each
EventVariableTypeto its value field inevent.py.Hint: this map can also move into aioesphomeapi as a helper if preferred.
As discussed on esphome/esphome#21527, bdraco reviews the design and the Home Assistant side first, so this PR stays a draft until then.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome (if applicable):
Checklist:
tests/folder).