-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Avoid protobuf message construction when tx buffer is full #8787
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
Conversation
…e tx_buffer is full Also do not try to dequeue if the buffer is full
Hey there @OttoWinter, mind taking a look at this pull request as it has been labeled with an integration ( |
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice logical changes and cleanups.
Testing now on some devices
Working on a handful of devices and one with a bunch of sensors that all send at the same time |
Thanks. Some more dummy entities I used for testing button:
- platform: factory_reset
id: factory_reset_btn
name: Factory reset
sensor:
# Uptime sensor.
- platform: uptime
name: Ethernet Uptime
- platform: template
name: Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
unit_of_measurement: 'B'
state_class: measurement
- platform: template
id: test_climate_sensor
lambda: return 20.0;
binary_sensor:
- platform: template
name: "Test Binary Sensor"
lambda: return false;
cover:
- platform: time_based
name: "Test Cover"
open_duration: 5s
close_duration: 5s
open_action:
- logger.log: "Cover opening"
close_action:
- logger.log: "Cover closing"
stop_action:
- logger.log: "Cover stopping"
fan:
- platform: binary
output: test_light_output
name: "Test Fan"
switch:
- platform: template
id: test_switch
name: "Test Switch"
lambda: return false;
turn_on_action:
- logger.log: "Switch turned on"
turn_off_action:
- logger.log: "Switch turned off"
text_sensor:
- platform: version
name: "ESPHome Version"
light:
- platform: binary
name: "Test Light"
output: test_light_output
climate:
- platform: bang_bang
name: "Test Climate"
sensor: test_climate_sensor
default_target_temperature_low: 20°C
default_target_temperature_high: 22°C
heat_action:
- switch.turn_on: test_switch
idle_action:
- switch.turn_off: test_switch
number:
- platform: template
name: "Test Number"
min_value: 0
max_value: 100
step: 1
lambda: return 50.0;
set_action:
- logger.log: "Number set"
select:
- platform: template
name: "Test Select"
options:
- "Option 1"
- "Option 2"
initial_option: "Option 1"
optimistic: true
set_action:
- logger.log: "Select changed"
text:
- platform: template
name: "Test Text"
mode: text
initial_value: "Hello"
set_action:
- logger.log: "Text changed"
lock:
- platform: output
name: "Test Lock"
output: test_light_output
output:
- platform: gpio
pin: GPIO0
id: test_light_output
- platform: gpio
pin: GPIO2
id: test_climate_heat
- platform: gpio
pin: GPIO3
id: test_climate_cool
# Date, Time, and DateTime entities
datetime:
- platform: template
type: date
name: "Test Date"
initial_value: "2023-05-13"
optimistic: true
on_value:
- logger.log: "Date changed"
- platform: template
type: time
name: "Test Time"
initial_value: "12:30:00"
optimistic: true
on_value:
- logger.log: "Time changed"
- platform: template
type: datetime
name: "Test DateTime"
optimistic: true
on_value:
- logger.log: "DateTime changed"
# Valve
valve:
- platform: template
name: "Test Valve"
open_action:
- logger.log: "Valve opening"
close_action:
- logger.log: "Valve closing"
stop_action:
- logger.log: "Valve stopping"
# For now, commenting out media_player since it requires hardware support
# media_player:
# - platform: speaker
# name: "Test Media Player"
# Alarm Control Panel
alarm_control_panel:
- platform: template
name: "Test Alarm"
codes:
- "1234"
arming_away_time: 0s
arming_home_time: 0s
pending_time: 0s
trigger_time: 300s
restore_mode: ALWAYS_DISARMED
on_disarmed:
- logger.log: "Alarm disarmed"
on_arming:
- logger.log: "Alarm arming"
on_armed_away:
- logger.log: "Alarm armed away"
on_armed_home:
- logger.log: "Alarm armed home"
on_pending:
- logger.log: "Alarm pending"
on_triggered:
- logger.log: "Alarm triggered"
# Event
event:
- platform: template
name: "Test Event"
event_types:
- first_event
- second_event |
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
What does this implement/fix?
This PR refactors the
api_connection
to avoid protobuf message construction when the transmit buffer is full.The code in api_connection.cpp has been restructured to change how messages are sent, avoiding the need to add buffer-full checks in every single send function. This approach is cleaner and solves the problem at its source.
Avoids constructing protobuf messages that would fail to send due to a full tx_buffer
Eliminates the wasteful cycle of:
Functional changes are
try_to_clear_buffer
calls in the new helpers which try again to send the buffer ifcan_write_without_blocking
if false before proceeding to queue the message.process_queue
with acan_write_without_blocking
checktry_
functions are now marked as protected because it didn't seem like the intent was to make them part of the public APITesting
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml
:# Example config.yaml
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: