Skip to content

Add typed event data - #1967

Draft
Bascht74 wants to merge 4 commits into
esphome:mainfrom
Bascht74:event-value
Draft

Bascht74 wants to merge 4 commits into
esphome:mainfrom
Bascht74:event-value

Conversation

@Bascht74

@Bascht74 Bascht74 commented Oct 23, 2026 •

Copy link
Copy Markdown

What does this implement/fix?

An event entity can declare typed variables, and each event sends the values it sets.

  • EventInfo.variables: list of EventVariable with name and type (EventVariableType: BOOL, INT, FLOAT, STRING). A type this version does not know becomes None, like the other enums.
  • Event.values: list of EventVariableValue with index into EventInfo.variables and bool_, int_, float_, string_. The field that matches the type of the variable holds the value, as in ExecuteServiceArgument.
  • Both lists are empty for entities without variables and for older firmware. Event.values is also empty for older queued events that the device sent without their values under backpressure; Event.values_dropped is True for those events. The device does not keep whether such an event had values, so the flag is also True for one that set none.

api.proto has the event section of esphome/esphome#21528; api_pb2.py is 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 EventVariableType to its value field in event.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

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

  • not applicable

Pull request in esphome (if applicable):

Checklist:

  • The code change is tested and works locally.
  • If api.proto was modified, a linked pull request has been made to esphome with the same changes.
  • Tests have been added to verify that the new code works (under tests/ folder).

@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 61 untouched benchmarks


Comparing Bascht74:event-value (e1ea967) with main (ecc823d)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (4213b47) during the generation of this report, so ecc823d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ecc823d) to head (e1ea967).
⚠️ Report is 1 commits behind head on main.

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

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2ff4465e-0b2e-4042-8768-45bdb5f430f1
📥 Commits

Reviewing files that changed from the base of the PR and between 6cddfb3 and 65b19cf.

📒 Files selected for processing: 4
  • aioesphomeapi/api.proto
  • aioesphomeapi/api_pb2.py
  • aioesphomeapi/model.py
  • tests/test_model.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The event protobuf messages and Python models add fields for an event value and its name. Tests cover conversion of populated and absent fields.

Changes

Event value fields

Layer / File(s) Summary
Add protobuf event fields
aioesphomeapi/api.proto
ListEntitiesEventResponse adds conditional value_name. EventResponse adds conditional value.
Expose and test event values
aioesphomeapi/model.py, tests/test_model.py
EventInfo and Event add value fields. Tests check conversion, defaults, and dictionary output.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Feature

Suggested reviewers: bdraco

Merge Risk: Minimal · up to 65b19

No actionable defect was found in the event-value fields. Confirm the matching firmware change before merging, as required by repository guidance.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title "Add typed event data" is partially related to the changeset. The PR adds typed event variables, but the raw summary describes only a value_name string on EventInfo and a value integer o…
Description check Passed The pull request description is related to the changeset. It describes adding event value metadata and event values, including corresponding api.proto changes and tests.
Full details: Title check

Explanation

The title "Add typed event data" is partially related to the changeset. The PR adds typed event variables, but the raw summary describes only a value_name string on EventInfo and a value integer on Event. The title does not match that scope exactly. The PR description describes a larger feature (EventVariable, EventVariableType, EventVariableValue, and typed value lists), so the title is accurate to the description but not to the summarized diff. The commit message "Add the event value and its name" and the PR objectives point to a different scope. The title is clear and specific enough to be acceptable.

Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Bascht74
Bascht74 marked this pull request as draft October 24, 2026 00:25
@Bascht74 Bascht74 changed the title Add the event value and its name Add typed event data Oct 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

This branch has not been deployed

No deployments
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