Skip to content

[API] Sub devices #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

[API] Sub devices #1146

wants to merge 11 commits into from

Conversation

dala318
Copy link

@dala318 dala318 commented Apr 10, 2025

What does this implement/fix?

Adds the possibility to group entities on one physical device into virtual devices (in Home Assistant), handy when one ESP serves several purposes.

Read more in related ESP Home PR

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):

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

Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (86a9c02) to head (5f8374b).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1146   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        19           
  Lines         2779      2795   +16     
=========================================
+ Hits          2779      2795   +16     

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

@dala318 dala318 mentioned this pull request Apr 10, 2025
14 tasks
Copy link

codspeed-hq bot commented Apr 10, 2025

CodSpeed Performance Report

Merging #1146 will not alter performance

Comparing dala318:multi_device (5f8374b) with main (86a9c02)

Summary

✅ 9 untouched benchmarks

@dala318 dala318 marked this pull request as draft April 10, 2025 10:51
Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Walkthrough

This pull request modifies the CI workflow to provide clearer debugging output when generated protobuf files differ, by adding informative echo statements. It also extends the API and data model by introducing a new sub-device information structure. A new message type and corresponding model class for sub-device info have been added, and existing messages and classes have been updated to include sub-device lists and device identifiers. These changes support configurations with multiple devices in one setup.

Changes

File(s) Change Summary
.github/.../ci.yml Updated error handling in the CI workflow by adding echo statements to display git diff output when differences in generated protobuf files are detected.
aioesphomeapi/api.proto, aioesphomeapi/model.py Added new sub-device support by introducing the SubDeviceInfo message and model class. Updated DeviceInfoResponse and DeviceInfo to include sub-device lists, and enhanced several entity messages/classes with an additional device_id field (with some commented out) along with minor formatting adjustments.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as GitHub Actions Runner
    participant Git as Git CLI
    Runner->>Git: Execute "git diff --quiet"
    alt Differences Exist
      Runner->>Runner: echo "The diff is:"
      Runner->>Git: Execute "git diff"
      Runner->>Runner: Exit with status 1
    end
Loading
sequenceDiagram
    participant Converter as SubDeviceInfo.convert_list
    participant Item as List Item
    participant Instance as SubDeviceInfo Instance
    Converter->>Item: Iterate over input list
    alt Item is dict
      Item->>Converter: Process using from_dict
    else Item is not dict
      Item->>Converter: Process using from_pb
    end
    Converter->>Instance: Create SubDeviceInfo instance
Loading

Assessment against linked issues

Objective Addressed Explanation
Improve HA device registry and support multiple devices (#1335)

Suggested reviewers

  • jesserockz
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
aioesphomeapi/model.py (1)

220-221: Consider implementing device_id at the EntityInfo base class level.

The commented-out code suggests a plan to add device_id to the base EntityInfo class. This would be a more maintainable approach than adding it to each entity type individually.

-  # # Is it ok to ad for the generic device info before all are added?
-  # device_id: str = ""
+  device_id: str = ""

Since this is marked as a comment/question, please clarify if there's a specific reason to delay adding this field to the base class. Adding it now would simplify future implementations across all entity types.

aioesphomeapi/api.proto (1)

387-387: Consider implementing device_id for all entity types consistently.

Many entity types have commented-out device_id fields. Consider whether these should be implemented now for consistency, or if there's a specific reason to add them incrementally.

A phased approach is reasonable, but ensure there's a clear plan for adding support to all entity types in subsequent PRs. Document this plan if there are specific prerequisites or dependencies that would benefit from a staged implementation.

Also applies to: 456-457, 546-547, 577-578, 613-614, 777-778, 879-880, 961-962, 1000-1001, 1100-1101, 1136-1137, 1192-1193, 1690-1691, 1734-1735, 1773-1774, 1815-1816, 1860-1861, 1890-1891, 1935-1936, 1974-1975

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ad8751 and d18cce9.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml (1 hunks)
  • aioesphomeapi/api.proto (24 hunks)
  • aioesphomeapi/model.py (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**`: - Do not generate or add any sequence diagrams

**: - Do not generate or add any sequence diagrams

  • aioesphomeapi/model.py
  • aioesphomeapi/api.proto
🪛 GitHub Check: codecov/patch
aioesphomeapi/model.py

[warning] 145-146: aioesphomeapi/model.py#L145-L146
Added lines #L145 - L146 were not covered by tests


[warning] 148-148: aioesphomeapi/model.py#L148
Added line #L148 was not covered by tests

🔇 Additional comments (9)
.github/workflows/ci.yml (1)

125-131: Improved error handling output for protobuf file differences.

The added echo statements enhance developer experience by providing clearer debugging information when generated protobuf files differ from expected versions.

aioesphomeapi/model.py (4)

172-174: Added sub_devices list to DeviceInfo class.

This addition enables the representation of multiple virtual devices within a single physical device, which aligns well with the PR objectives.


234-234: Added device_id to BinarySensorInfo.

This enables linking binary sensors to specific sub-devices.


251-251: Added device_id to CoverInfo.

This enables linking covers to specific sub-devices.


136-150:

❓ Verification inconclusive

New SubDeviceInfo class added to support virtual device grouping.

This class implements the data model for sub-devices with identification, name, and location information. Good implementation of the convert_list method for handling different input formats.


🏁 Script executed:

#!/bin/bash
# Check if there are any unit tests for the new SubDeviceInfo class

echo "Checking for unit tests covering SubDeviceInfo class..."
rg "SubDeviceInfo" tests/

Length of output: 146


Attention: Confirm Unit Test Coverage for SubDeviceInfo Class

The implementation of the new SubDeviceInfo class—with its clear data model and the robust convert_list method handling both dictionary and protobuf inputs—is well done. However, our search in the tests directory did not locate any unit tests for this class. Please manually verify whether tests exist in another location or consider adding unit tests to cover its functionality (especially for both from_dict and from_pb conversion paths).

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 145-146: aioesphomeapi/model.py#L145-L146
Added lines #L145 - L146 were not covered by tests


[warning] 148-148: aioesphomeapi/model.py#L148
Added line #L148 was not covered by tests

aioesphomeapi/api.proto (4)

185-189: New SubDeviceInfo message type added.

This protocol buffer message provides the structure for transmitting sub-device information with fields for id, name, and suggested_area.


237-237: Added sub_devices field to DeviceInfoResponse message.

This allows the API to report multiple sub-devices associated with a single physical device.


281-281: Implemented device_id field for binary sensors and covers.

These are the first entity types to fully implement the sub-device association. This implementation correctly links these entity types to the new sub-device structure.

Also applies to: 315-315


1-2007:

❓ Verification inconclusive

Verify compatibility with the linked esphome repository PR.

The PR objectives mention a linked PR to the main esphome repository (esphome/esphome#8544). Ensure these API changes are compatible with the changes in that PR.


🌐 Web query:

What's the current status of esphome/esphome PR #8544?

💡 Result:

The current search results do not provide specific information about the status of esphome/esphome PR #8544. The latest mentions in the provided data refer to releases up to 2025.3.3 and changes in 2024.8.x, but no details about PR #8544 are included.

For the most accurate and up-to-date status, you would need to check the esphome/esphome GitHub repository directly. The provided results do not indicate whether this PR has been merged, closed, or is still under review[3][6].

Citations:


Action: Manually verify compatibility with esphome/esphome#8544

The API changes in this file (aioesphomeapi/api.proto, lines 1–2007) should be checked against the upstream modifications introduced in esphome/esphome PR #8544. Currently, web searches did not return specific status details for that PR. Please ensure that:

  • The updated service definitions and RPC options are fully aligned with the upstream changes.
  • Any removed or replaced code in this API file is compatible with the handling in [API] Sub devices esphome#8544.
  • You cross-check the most recent state of the upstream PR directly on GitHub to confirm compatibility.
🧰 Tools
🪛 Buf (1.47.2)

3-3: import "api_options.proto": file does not exist

(COMPILE)

@bdraco bdraco added the waiting-for-esphome Indicates the PR is waiting for the esphome main repo code approval label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-esphome Indicates the PR is waiting for the esphome main repo code approval
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve HA device registry and support multiple devices in one config
2 participants