10000 [packet_transport] Make some arguments const by clydebarrow · Pull Request #8700 · esphome/esphome · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[packet_transport] Make some arguments const #8700

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

Merged
merged 1 commit into from
May 7, 2025

Conversation

clydebarrow
Copy link
Contributor

What does this implement/fix?

Change some function signatures to have const arguments since they aren't modified.

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-docs with documentation (if applicable):

  • esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link
probot-esphome bot commented May 6, 2025

Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (uart) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@clydebarrow
Copy link
Contributor Author

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#8700
    components: [packet_transport, uart, udp]
    refresh: 1h

(Added by the PR bot)

Copy link
Contributor
@Copilot 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 improves code quality by updating function signatures across UDP and UART packet transport components to use const reference parameters for data buffers, ensuring immutability where applicable.

  • Update of send_packet functions to use const std::vector<uint8_t> & instead of non-const references.
  • Consistent propagation of const correctness in both header and source files across UDP, UART, and packet transport modules.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
esphome/components/udp/udp_component.h Updated send_packet to use a const vector argument.
esphome/components/udp/packet_transport/udp_transport.h Modified send_packet signature to const reference.
esphome/components/udp/packet_transport/udp_transport.cpp Updated send_packet call to match new const signature.
esphome/components/uart/packet_transport/uart_transport.h Updated send_packet signature to use const vector argument.
esphome/components/uart/packet_transport/uart_transport.cpp Updated send_packet call to match new const signature.
esphome/components/packet_transport/packet_transport.h Updated virtual send_packet and process_ methods to use const vector parameters.
esphome/components/packet_transport/packet_transport.cpp Updated process_ implementation to accept a const vector parameter.
Comments suppressed due to low confidence (7)

esphome/components/udp/udp_component.h:33

  • Updating send_packet to take a const reference improves clarity regarding immutability. Ensure that any callers relying on mutable data are updated accordingly.
void send_packet(const std::vector<uint8_t> &buf) { this->send_packet(buf.data(), buf.size()); }

esphome/components/udp/packet_transport/udp_transport.h:19

  • Changing the parameter to a const reference enforces immutability and clarifies the interface contract. Confirm that this modification aligns with the expectations in the parent class.
void send_packet(const std::vector<uint8_t> &buf) const override;

esphome/components/udp/packet_transport/udp_transport.cpp:34

  • The const correctness update here is appropriate; verify that the parent's send_packet accepts a const argument to avoid compatibility issues.
void UDPTransport::send_packet(const std::vector<uint8_t> &buf) const { this->parent_->send_packet(buf); }

esphome/components/uart/packet_transport/uart_transport.h:32

  • Converting to a const reference in send_packet enhances code safety by ensuring the buffer remains unchanged. Confirm that all associated components reflect this change.
void send_packet(const std::vector<uint8_t> &buf) const override;

esphome/components/uart/packet_transport/uart_transport.cpp:77

  • The const update here is consistent with the header declaration; ensure that the parent's method usage is compatible with this change.
void UARTTransport::send_packet(const std::vector<uint8_t> &buf) const {

esphome/components/packet_transport/packet_transport.h:109

  • Changing process_ to accept a const vector reinforces immutability during data processing. Ensure that all calls to process_ are adjusted to reflect the const parameter requirement.
void process_(const std::vector<uint8_t> &data);

esphome/components/packet_transport/packet_transport.cpp:356

  • Aligning the implementation with the header by using a const vector is a good consistency improvement. Verify that no in-place modifications of the data are expected within this function.
void PacketTransport::process_(const std::vector<uint8_t> &data) {

@codecov-commenter
Copy link
codecov-commenter commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.64%. Comparing base (4d8b5ed) to head (5bb8696).
Report is 2479 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8700      +/-   ##
==========================================
+ Coverage   53.70%   56.64%   +2.93%     
==========================================
  Files          50       50              
  Lines        9408     9922     +514     
  Branches     1654     1340     -314     
==========================================
+ Hits         5053     5620     +567     
+ Misses       4056     3954     -102     
- Partials      299      348      +49     

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

@jesserockz jesserockz merged commit d60e1f0 into esphome:dev May 7, 2025
103 checks passed
@jesserockz jesserockz mentioned this pull request May 13, 2025
@jesserockz jesserockz mentioned this pull request May 21, 2025
sa-crespo pushed a commit to sa-crespo/esphome that referenced this pull request May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0