Skip to content
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

[packet_transport] Extract packet encoding functionality #8187

Open
wants to merge 34 commits into
base: dev
Choose a base branch
from

Conversation

clydebarrow
Copy link
Contributor

@clydebarrow clydebarrow commented Feb 3, 2025

What does this implement/fix?

The packet encoding routines in the udp component have been hoisted out into a dedicated, transport-independent, platform component that can be used by multiple communication mechanisms.

The packet_transport component provides all sensor encode/decode, encryption etc. The UDP component just provides the send/receive functionality.

the udp.sensor and udp.binary_sensor components are now packet_transport.sensor and packet_transport.binary_sensor.

UDP component also now has a receive trigger and write action.

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

  • fixes

Pull request in esphome-docs with documentation (if applicable):

Test Environment

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

Example entry for config.yaml:

# Example config.yaml

udp:
  listen_address: 239.0.60.53
  addresses: ["239.0.60.53"]

packet_transport:
  platform: udp
  update_interval: 5s
  encryption: "our key goes here"
  rolling_code_enable: true
  ping_pong_enable: true
  binary_sensors:
    - binary_sensor_id1
    - id: binary_sensor_id1
      broadcast_id: other_id
  sensors:
    - sensor_id1
    - id: sensor_id1
      broadcast_id: other_id
  providers:
    - name: some-device-name
      encryption: "their key goes here"

sensor:
  - platform: template
    id: sensor_id1
  - platform: packet_transport
    provider: some-device-name
    id: our_id
    remote_id: some_sensor_id

binary_sensor:
  - platform: packet_transport
    provider: unencrypted-device
    id: other_binary_sensor_id
  - platform: template
    id: binary_sensor_id1

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:

@codecov-commenter
Copy link

codecov-commenter commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.81%. Comparing base (4d8b5ed) to head (58ab24e).
Report is 2000 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8187      +/-   ##
==========================================
+ Coverage   53.70%   53.81%   +0.10%     
==========================================
  Files          50       50              
  Lines        9408     9856     +448     
  Branches     1654     1360     -294     
==========================================
+ Hits         5053     5304     +251     
- Misses       4056     4230     +174     
- Partials      299      322      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@clydebarrow clydebarrow marked this pull request as draft February 4, 2025 09:09
@clydebarrow clydebarrow changed the title [packet_encoding] Extract packet encoding functionality [packet_transport] Extract packet encoding functionality Feb 5, 2025
@clydebarrow clydebarrow marked this pull request as ready for review February 5, 2025 05:21
@nagyrobi
Copy link
Member

nagyrobi commented Feb 5, 2025

Testing...

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.

3 participants