From 6099ac7b533be3c9ecfd44c9463df86572e7f239 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Wed, 2 Sep 2026 21:17:22 +1200 Subject: [PATCH 1/4] [core] Document C++ conventions in AGENTS.md that reviews keep catching (#18941) --- AGENTS.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f006ee6087..e932c50f32 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -44,6 +44,16 @@ This document provides essential context for AI models interacting with this pro ## 4. Coding Conventions & Style Guide +**Read the developer documentation before writing a component.** https://developers.esphome.io covers the +component lifecycle, the main loop, and the reasoning behind the rules below in far more depth than this +file does, and it is the authority when they disagree. The most useful starting points: + +* https://developers.esphome.io/architecture/components/ - component lifecycle, `setup()`, `loop()`, + setup priorities, and how a component is registered. +* https://developers.esphome.io/architecture/components/advanced/ - choosing between `loop()`, + `set_interval`, `set_timeout` and `defer`; waking the loop from another thread; the RAM cost of each. +* https://developers.esphome.io/contributing/code/ - contribution rules, public API and breaking changes. + * **Formatting:** * **Python:** Uses `ruff` and `flake8` for linting and formatting. Configuration is in `pyproject.toml`. * **C++:** Uses `clang-format` for formatting. Configuration is in `.clang-format`. @@ -142,6 +152,47 @@ This document provides essential context for AI models interacting with this pro * **Indentation:** Use spaces (two per indentation level), not tabs * **Type aliases:** Prefer `using type_t = int;` over `typedef int type_t;` * **Line length:** Wrap lines at no more than 120 characters + * **Timing in `loop()`:** Never call `millis()` in a `loop()` body. The current tick's timestamp is + already cached - use `App.get_loop_component_start_time()` (from `esphome/core/application.h`). + Only reach for `millis()` when you genuinely need sub-tick resolution inside a long operation. + * **The main loop runs every 16 ms.** A rate-limit gate shorter than that does nothing: the check + passes on essentially every pass of the loop, so it costs a comparison and buys nothing. Pick an + interval comfortably coarser than 16 ms, or drop the gate entirely and accept running every loop. + ```cpp + // Bad - a 10ms gate against a 16ms loop never holds anything back + static constexpr uint32_t POLL_INTERVAL_MS = 10; + const uint32_t now = millis(); + if (now - this->last_poll_ < POLL_INTERVAL_MS) + return; + this->last_poll_ = now; + ``` + ```cpp + // Good - an interval that actually rate limits, off the cached timestamp + static constexpr uint32_t POLL_INTERVAL_MS = 100; + const uint32_t now = App.get_loop_component_start_time(); + if (now - this->last_poll_ < POLL_INTERVAL_MS) + return; + this->last_poll_ = now; + ``` + Pick the primitive by cadence: under 250 ms use a gated `loop()`; 500 ms and above use + `set_interval`. Full reasoning, including why `set_interval` costs more below 500 ms: + https://developers.esphome.io/architecture/components/advanced/#quick-rule-of-thumb + * **Don't override a default with the same value:** if a base class method already returns what you + want, do not override it. `Component::get_setup_priority()` returns `setup_priority::DATA`, so a + component that wants `DATA` should simply leave it alone. + ```cpp + // Bad - this is exactly what the base class already does + float get_setup_priority() const override { return setup_priority::DATA; } + ``` + * **Logging string literals:** wrap literals passed as `%s` arguments in `LOG_STR_LITERAL()` so they + can be stored in flash rather than RAM. + ```cpp + // Bad + ESP_LOGV(TAG, "Key %u %s", key, pressed ? "pressed" : "released"); + + // Good + ESP_LOGV(TAG, "Key %u %s", key, pressed ? LOG_STR_LITERAL("pressed") : LOG_STR_LITERAL("released")); + ``` * **Constructor parameters vs setters:** Component properties that are both **required** and **invariant** (never change after construction) should be constructor parameters rather than set via setter methods. This makes the dependency explicit and prevents use of the object in an incompletely-initialized state. @@ -562,6 +613,33 @@ This document provides essential context for AI models interacting with this pro Use `cg.add_define("MAX_SERVICES", count)` to set the size from Python configuration. Like `std::array` but with vector-like API (`push_back()`, `size()`) and no STL reallocation code. + **Listener and child-entity registration lists are the most common case, and the most commonly + missed.** A `register_*()` method called once per child at code generation time has a count that + is known at compile time, so it should never be a `std::vector`. Use `cg.slot_counter()`: it + returns a function that each consumer calls once per slot it will occupy, and after every + `to_code` has run it emits the define with the final count. When nothing registers, no define is + emitted and the storage plus its registration method compile out entirely. + ```python + # hub component's __init__.py + _request_listener_slot = cg.slot_counter("MY_COMPONENT_LISTENER_COUNT") + + + async def register_listener(hub: MockObj, var: MockObj) -> None: + _request_listener_slot() + cg.add(hub.register_listener(var)) + ``` + ```cpp + #ifdef MY_COMPONENT_LISTENER_COUNT + void register_listener(MyComponentListener *listener); + #endif + protected: + #ifdef MY_COMPONENT_LISTENER_COUNT + StaticVector listeners_; + #endif + ``` + Request slots from `to_code`, not from a job that runs after `CoroPriority.FINAL` - a late + request raises rather than silently undercounting. + 3. **Runtime-known sizes:** Use `FixedVector` from `esphome/core/helpers.h` when the size is only known at runtime initialization. ```cpp // Bad - generates STL realloc code (_M_realloc_insert) @@ -599,9 +677,25 @@ This document provides essential context for AI models interacting with this pro ``` Linear search on small datasets (1-16 elements) is often faster than hashing/tree overhead, but this depends on lookup frequency and access patterns. For frequent lookups in hot code paths, the O(1) vs O(n) complexity difference may still matter even for small datasets. `std::vector` with simple structs is usually fine—it's the heavy containers (`map`, `set`, `unordered_map`) that should be avoided for small datasets unless profiling shows otherwise. - 5. **Avoid `std::deque`:** It allocates in 512-byte blocks regardless of element size, guaranteeing at least 512 bytes of RAM usage immediately. This is a major source of crashes on memory-constrained devices. + 5. **Strings set once from configuration:** Use `StringRef` (`esphome/core/string_ref.h`) rather than + `std::string`. Code generation passes a string literal that lives in flash for the life of the + program, so storing a `std::string` copies it onto the heap for nothing. `StringRef` is a + non-owning pointer plus length; it does not copy, and it must only ever refer to storage that + outlives it (a string literal, or a buffer owned elsewhere). + ```cpp + // Bad - heap copy of a literal that is already in flash + void set_keys(std::string keys) { this->keys_ = std::move(keys); } + std::string keys_; + ``` + ```cpp + // Good - no allocation + void set_keys(const char *keys) { this->keys_ = StringRef(keys); } + StringRef keys_; + ``` - 6. **Detection:** Look for these patterns in compiler output: + 6. **Avoid `std::deque`:** It allocates in 512-byte blocks regardless of element size, guaranteeing at least 512 bytes of RAM usage immediately. This is a major source of crashes on memory-constrained devices. + + 7. **Detection:** Look for these patterns in compiler output: - Large code sections with STL symbols (vector, map, set) - `alloc`, `realloc`, `dealloc` in symbol names - `_M_realloc_insert`, `_M_default_append` (vector reallocation) From da16c01351e60d33c4ecc6527b8e78e0907a22ed Mon Sep 17 00:00:00 2001 From: "esphome[bot]" <115708604+esphome[bot]@users.noreply.github.com> Date: Wed, 2 Sep 2026 09:32:47 +0000 Subject: [PATCH 2/4] [ci] Refresh integration test durations (#18944) --- .../integration_test_durations.json | 281 +++++++++--------- 1 file changed, 141 insertions(+), 140 deletions(-) diff --git a/tests/integration/integration_test_durations.json b/tests/integration/integration_test_durations.json index 9bada5cd36..5a5aac3b22 100644 --- a/tests/integration/integration_test_durations.json +++ b/tests/integration/integration_test_durations.json @@ -1,142 +1,143 @@ { - "tests/integration/test_action_concurrent_reentry.py": 45.23, - "tests/integration/test_addressable_light_transition.py": 74.47, - "tests/integration/test_alarm_control_panel_state_transitions.py": 74.1, - "tests/integration/test_api_action_metadata.py": 62.1, - "tests/integration/test_api_action_responses.py": 71.08, - "tests/integration/test_api_action_timeout.py": 21.64, - "tests/integration/test_api_conditional_memory.py": 13.72, - "tests/integration/test_api_custom_services.py": 24.16, - "tests/integration/test_api_get_time_response_timezone.py": 23.48, - "tests/integration/test_api_homeassistant.py": 37.87, - "tests/integration/test_api_homeassistant_action_no_subscriber.py": 14.38, - "tests/integration/test_api_list_entities_backpressure.py": 26.85, - "tests/integration/test_api_message_size_batching.py": 33.36, - "tests/integration/test_api_reboot_timeout.py": 13.63, - "tests/integration/test_api_string_lambda.py": 25.04, - "tests/integration/test_api_vv_logging.py": 16.6, - "tests/integration/test_api_zero_psk_provisioning.py": 43.14, - "tests/integration/test_areas_and_devices.py": 25.98, - "tests/integration/test_automation_wait_actions.py": 21.91, - "tests/integration/test_automations.py": 42.43, - "tests/integration/test_batch_delay_zero_rapid_transitions.py": 16.65, - "tests/integration/test_binary_sensor_autorepeat_filter.py": 28.67, - "tests/integration/test_binary_sensor_invalidate_state.py": 23.69, - "tests/integration/test_blocking_warning_log_time_not_charged_to_next_operation.py": 22.99, - "tests/integration/test_build_info.py": 24.96, - "tests/integration/test_camera_mock.py": 14.47, - "tests/integration/test_climate_control_action.py": 31.07, - "tests/integration/test_climate_custom_modes.py": 28.59, - "tests/integration/test_continuation_actions.py": 14.96, - "tests/integration/test_cover_control_action.py": 26.14, - "tests/integration/test_crc8_helper.py": 10.92, - "tests/integration/test_device_id_in_state.py": 64.97, - "tests/integration/test_duplicate_entities.py": 30.81, - "tests/integration/test_entity_icon.py": 32.85, - "tests/integration/test_fan_turn_on_action.py": 24.91, - "tests/integration/test_fnv1_hash_object_id.py": 12.54, - "tests/integration/test_fnv1a_hash.py": 21.8, - "tests/integration/test_gpio_expander_cache.py": 5.2, - "tests/integration/test_host_logger_thread_safety.py": 21.7, - "tests/integration/test_host_mode_basic.py": 13.62, - "tests/integration/test_host_mode_batch_delay.py": 14.56, - "tests/integration/test_host_mode_climate_basic_state.py": 30.95, - "tests/integration/test_host_mode_climate_control.py": 29.06, - "tests/integration/test_host_mode_empty_string_options.py": 27.22, - "tests/integration/test_host_mode_entity_fields.py": 30.95, - "tests/integration/test_host_mode_fan_preset.py": 14.44, - "tests/integration/test_host_mode_many_entities.py": 54.13, - "tests/integration/test_host_mode_many_entities_multiple_connections.py": 32.17, - "tests/integration/test_host_mode_noise_encryption.py": 42.77, - "tests/integration/test_host_mode_reconnect.py": 4.06, - "tests/integration/test_host_mode_sensor.py": 13.47, - "tests/integration/test_host_ota.py": 21.4, - "tests/integration/test_host_preferences.py": 25.43, - "tests/integration/test_host_preferences_suspend_resume.py": 19.2, - "tests/integration/test_improv_serial_uart.py": 31.52, - "tests/integration/test_large_message_batching.py": 15.64, - "tests/integration/test_legacy_area.py": 22.63, - "tests/integration/test_legacy_climate_compat.py": 26.13, - "tests/integration/test_legacy_fan_compat.py": 24.05, - "tests/integration/test_light_automations.py": 30.86, - "tests/integration/test_light_binary_effect_off_phase.py": 23.19, - "tests/integration/test_light_calls.py": 32.35, - "tests/integration/test_light_constant_brightness.py": 29.89, - "tests/integration/test_light_control_action.py": 29.06, - "tests/integration/test_light_dim_relative_action.py": 29.61, - "tests/integration/test_light_effect_zero_brightness.py": 18.68, - "tests/integration/test_light_initial_state.py": 24.49, - "tests/integration/test_light_toggle_action.py": 26.46, - "tests/integration/test_lock_automations.py": 23.28, - "tests/integration/test_logger_buffered_recursion_guard.py": 24.29, - "tests/integration/test_loop_disable_enable.py": 45.28, - "tests/integration/test_loop_interval_decoupling.py": 28.35, - "tests/integration/test_loop_interval_default_not_pulled_forward.py": 21.97, - "tests/integration/test_micros_to_millis.py": 20.79, - "tests/integration/test_multi_click_trigger.py": 26.2, - "tests/integration/test_multi_device_preferences.py": 16.87, - "tests/integration/test_noise_encryption_key_protection.py": 77.05, - "tests/integration/test_object_id_api_verification.py": 73.51, - "tests/integration/test_object_id_friendly_name_no_mac_suffix.py": 62.33, - "tests/integration/test_object_id_no_friendly_name.py": 43.47, - "tests/integration/test_online_image_auto_detects_image_bmp_mime.py": 32.21, - "tests/integration/test_online_image_auto_detects_redirected_image_bmp_mime.py": 56.86, - "tests/integration/test_online_image_bmp.py": 50.9, - "tests/integration/test_oversized_payloads.py": 53.2, - "tests/integration/test_preference_key_stability.py": 26.09, - "tests/integration/test_runtime_stats.py": 18.34, - "tests/integration/test_safe_mode_loop_runs.py": 10.07, - "tests/integration/test_scheduler_blocking_warning.py": 40.91, - "tests/integration/test_scheduler_bulk_cleanup.py": 23.14, - "tests/integration/test_scheduler_defer_cancel.py": 24.54, - "tests/integration/test_scheduler_defer_cancel_regular.py": 13.48, - "tests/integration/test_scheduler_defer_fifo_simple.py": 26.86, - "tests/integration/test_scheduler_defer_stress.py": 27.23, - "tests/integration/test_scheduler_heap_stress.py": 24.02, - "tests/integration/test_scheduler_internal_id_no_collision.py": 24.57, - "tests/integration/test_scheduler_interval_reschedule.py": 13.12, - "tests/integration/test_scheduler_interval_zero_coerced.py": 22.91, - "tests/integration/test_scheduler_null_name.py": 23.46, - "tests/integration/test_scheduler_numeric_id_test.py": 24.54, - "tests/integration/test_scheduler_pool.py": 25.0, - "tests/integration/test_scheduler_rapid_cancellation.py": 14.68, - "tests/integration/test_scheduler_recursive_timeout.py": 25.35, - "tests/integration/test_scheduler_removed_item_race.py": 26.19, - "tests/integration/test_scheduler_self_keyed.py": 23.43, - "tests/integration/test_scheduler_simultaneous_callbacks.py": 22.16, - "tests/integration/test_scheduler_string_test.py": 15.22, - "tests/integration/test_script_array_params.py": 14.67, - "tests/integration/test_script_delay_params.py": 15.65, - "tests/integration/test_script_queued.py": 24.93, - "tests/integration/test_script_queued_idle_loop.py": 5.04, - "tests/integration/test_script_wait_on_boot.py": 13.08, - "tests/integration/test_select_stringref_trigger.py": 29.6, - "tests/integration/test_sensor_filters_delta.py": 28.01, - "tests/integration/test_sensor_filters_ring_buffer.py": 25.04, - "tests/integration/test_sensor_filters_sliding_window.py": 71.5, - "tests/integration/test_sensor_filters_value_list.py": 16.94, - "tests/integration/test_sensor_timeout_filter.py": 29.48, - "tests/integration/test_socket_wake_gate_tcp.py": 20.36, - "tests/integration/test_status_flags.py": 37.42, - "tests/integration/test_strftime_to.py": 22.61, - "tests/integration/test_syslog.py": 16.34, - "tests/integration/test_template_alarm_control_panel_many_sensors.py": 29.81, - "tests/integration/test_template_text_save.py": 25.43, - "tests/integration/test_text_command.py": 23.34, - "tests/integration/test_text_sensor_raw_state.py": 69.57, - "tests/integration/test_uart_mock_ld2410.py": 37.95, - "tests/integration/test_uart_mock_ld2412.py": 93.22, - "tests/integration/test_uart_mock_ld2420.py": 43.24, - "tests/integration/test_uart_mock_ld2450.py": 31.75, - "tests/integration/test_uart_mock_modbus.py": 667.4, - "tests/integration/test_udp.py": 9.38, - "tests/integration/test_use_address_runtime.py": 37.05, - "tests/integration/test_valve_control_action.py": 24.47, - "tests/integration/test_varint_five_byte_device_id.py": 25.03, - "tests/integration/test_wait_until_mid_loop_timing.py": 23.73, - "tests/integration/test_wait_until_on_boot.py": 9.16, - "tests/integration/test_wait_until_ordering.py": 13.3, - "tests/integration/test_wait_until_reentrant_restart.py": 25.23, - "tests/integration/test_wake_loop_forces_phase_b.py": 23.34, - "tests/integration/test_water_heater_template.py": 17.67 + "tests/integration/test_action_concurrent_reentry.py": 57.91, + "tests/integration/test_addressable_light_transition.py": 21.25, + "tests/integration/test_alarm_control_panel_state_transitions.py": 70.71, + "tests/integration/test_api_action_metadata.py": 66.6, + "tests/integration/test_api_action_responses.py": 36.1, + "tests/integration/test_api_action_timeout.py": 68.86, + "tests/integration/test_api_conditional_memory.py": 15.48, + "tests/integration/test_api_custom_services.py": 18.77, + "tests/integration/test_api_get_time_response_timezone.py": 21.08, + "tests/integration/test_api_homeassistant.py": 65.59, + "tests/integration/test_api_homeassistant_action_no_subscriber.py": 18.44, + "tests/integration/test_api_homeassistant_binary_sensor_initial_state.py": 15.05, + "tests/integration/test_api_list_entities_backpressure.py": 13.88, + "tests/integration/test_api_message_size_batching.py": 29.98, + "tests/integration/test_api_reboot_timeout.py": 16.05, + "tests/integration/test_api_string_lambda.py": 15.31, + "tests/integration/test_api_vv_logging.py": 19.28, + "tests/integration/test_api_zero_psk_provisioning.py": 31.5, + "tests/integration/test_areas_and_devices.py": 24.95, + "tests/integration/test_automation_wait_actions.py": 20.92, + "tests/integration/test_automations.py": 35.19, + "tests/integration/test_batch_delay_zero_rapid_transitions.py": 17.99, + "tests/integration/test_binary_sensor_autorepeat_filter.py": 20.39, + "tests/integration/test_binary_sensor_invalidate_state.py": 18.41, + "tests/integration/test_blocking_warning_log_time_not_charged_to_next_operation.py": 24.69, + "tests/integration/test_build_info.py": 18.7, + "tests/integration/test_camera_mock.py": 16.23, + "tests/integration/test_climate_control_action.py": 21.14, + "tests/integration/test_climate_custom_modes.py": 20.74, + "tests/integration/test_continuation_actions.py": 16.81, + "tests/integration/test_cover_control_action.py": 20.34, + "tests/integration/test_crc8_helper.py": 9.36, + "tests/integration/test_device_id_in_state.py": 44.67, + "tests/integration/test_duplicate_entities.py": 23.58, + "tests/integration/test_entity_icon.py": 34.35, + "tests/integration/test_fan_turn_on_action.py": 24.23, + "tests/integration/test_fnv1_hash_object_id.py": 16.21, + "tests/integration/test_fnv1a_hash.py": 13.38, + "tests/integration/test_gpio_expander_cache.py": 13.06, + "tests/integration/test_host_logger_thread_safety.py": 23.66, + "tests/integration/test_host_mode_basic.py": 8.01, + "tests/integration/test_host_mode_batch_delay.py": 21.0, + "tests/integration/test_host_mode_climate_basic_state.py": 22.14, + "tests/integration/test_host_mode_climate_control.py": 19.39, + "tests/integration/test_host_mode_empty_string_options.py": 21.76, + "tests/integration/test_host_mode_entity_fields.py": 29.61, + "tests/integration/test_host_mode_fan_preset.py": 20.01, + "tests/integration/test_host_mode_many_entities.py": 39.08, + "tests/integration/test_host_mode_many_entities_multiple_connections.py": 23.92, + "tests/integration/test_host_mode_noise_encryption.py": 42.42, + "tests/integration/test_host_mode_reconnect.py": 3.41, + "tests/integration/test_host_mode_sensor.py": 22.96, + "tests/integration/test_host_ota.py": 29.5, + "tests/integration/test_host_preferences.py": 16.06, + "tests/integration/test_host_preferences_suspend_resume.py": 18.71, + "tests/integration/test_improv_serial_uart.py": 20.22, + "tests/integration/test_large_message_batching.py": 26.56, + "tests/integration/test_legacy_area.py": 22.72, + "tests/integration/test_legacy_climate_compat.py": 14.13, + "tests/integration/test_legacy_fan_compat.py": 14.33, + "tests/integration/test_light_automations.py": 18.81, + "tests/integration/test_light_binary_effect_off_phase.py": 8.38, + "tests/integration/test_light_calls.py": 21.88, + "tests/integration/test_light_constant_brightness.py": 59.45, + "tests/integration/test_light_control_action.py": 31.91, + "tests/integration/test_light_dim_relative_action.py": 14.43, + "tests/integration/test_light_effect_zero_brightness.py": 25.05, + "tests/integration/test_light_initial_state.py": 18.97, + "tests/integration/test_light_toggle_action.py": 17.44, + "tests/integration/test_lock_automations.py": 18.9, + "tests/integration/test_logger_buffered_recursion_guard.py": 18.2, + "tests/integration/test_loop_disable_enable.py": 63.35, + "tests/integration/test_loop_interval_decoupling.py": 17.7, + "tests/integration/test_loop_interval_default_not_pulled_forward.py": 21.56, + "tests/integration/test_micros_to_millis.py": 15.89, + "tests/integration/test_multi_click_trigger.py": 17.23, + "tests/integration/test_multi_device_preferences.py": 19.4, + "tests/integration/test_noise_encryption_key_protection.py": 72.59, + "tests/integration/test_object_id_api_verification.py": 19.22, + "tests/integration/test_object_id_friendly_name_no_mac_suffix.py": 16.77, + "tests/integration/test_object_id_no_friendly_name.py": 45.8, + "tests/integration/test_online_image_auto_detects_image_bmp_mime.py": 86.73, + "tests/integration/test_online_image_auto_detects_redirected_image_bmp_mime.py": 40.4, + "tests/integration/test_online_image_bmp.py": 37.24, + "tests/integration/test_oversized_payloads.py": 55.75, + "tests/integration/test_preference_key_stability.py": 25.49, + "tests/integration/test_runtime_stats.py": 29.81, + "tests/integration/test_safe_mode_loop_runs.py": 6.26, + "tests/integration/test_scheduler_blocking_warning.py": 37.98, + "tests/integration/test_scheduler_bulk_cleanup.py": 18.67, + "tests/integration/test_scheduler_defer_cancel.py": 18.46, + "tests/integration/test_scheduler_defer_cancel_regular.py": 16.34, + "tests/integration/test_scheduler_defer_fifo_simple.py": 18.26, + "tests/integration/test_scheduler_defer_stress.py": 17.74, + "tests/integration/test_scheduler_heap_stress.py": 3.89, + "tests/integration/test_scheduler_internal_id_no_collision.py": 20.01, + "tests/integration/test_scheduler_interval_reschedule.py": 16.29, + "tests/integration/test_scheduler_interval_zero_coerced.py": 16.09, + "tests/integration/test_scheduler_null_name.py": 14.69, + "tests/integration/test_scheduler_numeric_id_test.py": 17.08, + "tests/integration/test_scheduler_pool.py": 19.88, + "tests/integration/test_scheduler_rapid_cancellation.py": 4.42, + "tests/integration/test_scheduler_recursive_timeout.py": 4.3, + "tests/integration/test_scheduler_removed_item_race.py": 15.49, + "tests/integration/test_scheduler_self_keyed.py": 25.77, + "tests/integration/test_scheduler_simultaneous_callbacks.py": 14.84, + "tests/integration/test_scheduler_string_test.py": 15.42, + "tests/integration/test_script_array_params.py": 12.73, + "tests/integration/test_script_delay_params.py": 12.69, + "tests/integration/test_script_queued.py": 20.38, + "tests/integration/test_script_queued_idle_loop.py": 25.06, + "tests/integration/test_script_wait_on_boot.py": 15.67, + "tests/integration/test_select_stringref_trigger.py": 19.48, + "tests/integration/test_sensor_filters_delta.py": 27.62, + "tests/integration/test_sensor_filters_ring_buffer.py": 20.27, + "tests/integration/test_sensor_filters_sliding_window.py": 56.28, + "tests/integration/test_sensor_filters_value_list.py": 20.6, + "tests/integration/test_sensor_timeout_filter.py": 22.21, + "tests/integration/test_socket_wake_gate_tcp.py": 16.37, + "tests/integration/test_status_flags.py": 29.68, + "tests/integration/test_strftime_to.py": 17.42, + "tests/integration/test_syslog.py": 18.39, + "tests/integration/test_template_alarm_control_panel_many_sensors.py": 25.61, + "tests/integration/test_template_text_save.py": 19.16, + "tests/integration/test_text_command.py": 16.43, + "tests/integration/test_text_sensor_raw_state.py": 17.19, + "tests/integration/test_uart_mock_ld2410.py": 37.0, + "tests/integration/test_uart_mock_ld2412.py": 40.82, + "tests/integration/test_uart_mock_ld2420.py": 32.7, + "tests/integration/test_uart_mock_ld2450.py": 32.84, + "tests/integration/test_uart_mock_modbus.py": 548.87, + "tests/integration/test_udp.py": 16.67, + "tests/integration/test_use_address_runtime.py": 27.26, + "tests/integration/test_valve_control_action.py": 24.58, + "tests/integration/test_varint_five_byte_device_id.py": 22.5, + "tests/integration/test_wait_until_mid_loop_timing.py": 22.05, + "tests/integration/test_wait_until_on_boot.py": 10.37, + "tests/integration/test_wait_until_ordering.py": 18.23, + "tests/integration/test_wait_until_reentrant_restart.py": 19.35, + "tests/integration/test_wake_loop_forces_phase_b.py": 17.83, + "tests/integration/test_water_heater_template.py": 25.7 } From ecbde8ddf4f12e0530ad262ef9a285b030eb8824 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 3 Sep 2026 07:25:08 +1200 Subject: [PATCH 3/4] [uart] Migrate check_uart_settings to final validation (#18940) --- esphome/components/cm1106/cm1106.cpp | 1 - esphome/components/cm1106/sensor.py | 8 ++++++++ esphome/components/cse7761/cse7761.cpp | 1 - esphome/components/cse7761/sensor.py | 8 +++++++- esphome/components/cse7766/cse7766.cpp | 1 - esphome/components/cse7766/sensor.py | 7 ++++++- esphome/components/daly_bms/__init__.py | 8 ++++++++ esphome/components/daly_bms/daly_bms.cpp | 5 +---- esphome/components/dfplayer/__init__.py | 7 ++++++- esphome/components/dfplayer/dfplayer.cpp | 5 +---- esphome/components/hc8/hc8.cpp | 1 - esphome/components/hc8/sensor.py | 3 +++ esphome/components/he60r/he60r.cpp | 1 - .../hrxl_maxsonar_wr/hrxl_maxsonar_wr.cpp | 2 -- esphome/components/hrxl_maxsonar_wr/sensor.py | 8 ++++++++ esphome/components/hydreon_rgxx/hydreon_rgxx.cpp | 1 - esphome/components/hydreon_rgxx/sensor.py | 8 ++++++++ esphome/components/kamstrup_kmp/kamstrup_kmp.cpp | 2 -- esphome/components/kamstrup_kmp/sensor.py | 8 +++++++- esphome/components/mhz19/mhz19.cpp | 2 -- esphome/components/mhz19/sensor.py | 8 ++++++++ esphome/components/mk2pvrouter/mk2pvrouter.cpp | 5 +---- esphome/components/mk2pvrouter/mk2pvrouter.h | 1 - esphome/components/pm1006/pm1006.cpp | 1 - esphome/components/pm1006/sensor.py | 3 +++ esphome/components/pmsx003/pmsx003.cpp | 2 -- esphome/components/pmsx003/sensor.py | 8 +++++++- esphome/components/pylontech/__init__.py | 8 ++++++++ esphome/components/pylontech/pylontech.cpp | 1 - esphome/components/seeed_mr60fda2/__init__.py | 1 + .../components/seeed_mr60fda2/seeed_mr60fda2.cpp | 2 -- esphome/components/smt100/sensor.py | 8 +++++++- esphome/components/smt100/smt100.cpp | 1 - esphome/components/t6615/sensor.py | 8 +++++++- esphome/components/t6615/t6615.cpp | 1 - esphome/components/teleinfo/__init__.py | 16 ++++++++++++++++ esphome/components/teleinfo/teleinfo.cpp | 7 +------ esphome/components/teleinfo/teleinfo.h | 1 - esphome/components/tormatic/tormatic_cover.cpp | 2 -- esphome/components/uart/uart.h | 2 ++ esphome/components/ufm01/__init__.py | 1 + esphome/components/ufm01/ufm01.cpp | 1 - esphome/components/uponor_smatrix/__init__.py | 2 +- .../components/uponor_smatrix/uponor_smatrix.cpp | 2 -- esphome/components/vbus/__init__.py | 8 ++++++++ esphome/components/vbus/vbus.cpp | 5 +---- esphome/components/wl_134/text_sensor.py | 8 ++++++++ esphome/components/wl_134/wl_134.cpp | 2 -- tests/components/cse7761/test.esp32-idf.yaml | 2 +- tests/components/cse7761/test.esp8266-ard.yaml | 2 +- tests/components/cse7761/test.rp2040-ard.yaml | 2 +- .../components/kamstrup_kmp/test.esp32-idf.yaml | 2 +- .../kamstrup_kmp/test.esp8266-ard.yaml | 2 +- tests/components/pylontech/test.esp32-idf.yaml | 2 +- tests/components/pylontech/test.esp8266-ard.yaml | 2 +- tests/components/pylontech/test.rp2040-ard.yaml | 2 +- tests/components/teleinfo/test.esp32-idf.yaml | 2 +- tests/components/teleinfo/test.esp8266-ard.yaml | 2 +- tests/components/teleinfo/test.rp2040-ard.yaml | 2 +- .../teleinfo/validate-standard.esp32-idf.yaml | 14 ++++++++++++++ .../common/uart_1200_even_7bits/esp32-ard.yaml | 14 ++++++++++++++ .../uart_1200_even_7bits/esp32-c3-ard.yaml | 14 ++++++++++++++ .../uart_1200_even_7bits/esp32-c3-idf.yaml | 14 ++++++++++++++ .../common/uart_1200_even_7bits/esp32-idf.yaml | 14 ++++++++++++++ .../common/uart_1200_even_7bits/esp8266-ard.yaml | 14 ++++++++++++++ .../common/uart_1200_even_7bits/rp2040-ard.yaml | 14 ++++++++++++++ .../common/uart_38400_even/esp32-ard.yaml | 12 ++++++++++++ .../common/uart_38400_even/esp32-c3-ard.yaml | 12 ++++++++++++ .../common/uart_38400_even/esp32-c3-idf.yaml | 12 ++++++++++++ .../common/uart_38400_even/esp32-idf.yaml | 12 ++++++++++++ .../common/uart_38400_even/esp8266-ard.yaml | 12 ++++++++++++ .../common/uart_38400_even/rp2040-ard.yaml | 12 ++++++++++++ 72 files changed, 324 insertions(+), 70 deletions(-) create mode 100644 tests/components/teleinfo/validate-standard.esp32-idf.yaml create mode 100644 tests/test_build_components/common/uart_1200_even_7bits/esp32-ard.yaml create mode 100644 tests/test_build_components/common/uart_1200_even_7bits/esp32-c3-ard.yaml create mode 100644 tests/test_build_components/common/uart_1200_even_7bits/esp32-c3-idf.yaml create mode 100644 tests/test_build_components/common/uart_1200_even_7bits/esp32-idf.yaml create mode 100644 tests/test_build_components/common/uart_1200_even_7bits/esp8266-ard.yaml create mode 100644 tests/test_build_components/common/uart_1200_even_7bits/rp2040-ard.yaml create mode 100644 tests/test_build_components/common/uart_38400_even/esp32-ard.yaml create mode 100644 tests/test_build_components/common/uart_38400_even/esp32-c3-ard.yaml create mode 100644 tests/test_build_components/common/uart_38400_even/esp32-c3-idf.yaml create mode 100644 tests/test_build_components/common/uart_38400_even/esp32-idf.yaml create mode 100644 tests/test_build_components/common/uart_38400_even/esp8266-ard.yaml create mode 100644 tests/test_build_components/common/uart_38400_even/rp2040-ard.yaml diff --git a/esphome/components/cm1106/cm1106.cpp b/esphome/components/cm1106/cm1106.cpp index 7e5d25b7ae..2e3352b895 100644 --- a/esphome/components/cm1106/cm1106.cpp +++ b/esphome/components/cm1106/cm1106.cpp @@ -100,7 +100,6 @@ bool CM1106Component::cm1106_write_command_(const uint8_t *command, size_t comma void CM1106Component::dump_config() { ESP_LOGCONFIG(TAG, "CM1106:"); LOG_SENSOR(" ", "CO2", this->co2_sensor_); - this->check_uart_settings(9600); if (this->is_failed()) { ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } diff --git a/esphome/components/cm1106/sensor.py b/esphome/components/cm1106/sensor.py index 936c5fc673..a36f0b0059 100644 --- a/esphome/components/cm1106/sensor.py +++ b/esphome/components/cm1106/sensor.py @@ -46,6 +46,14 @@ CONFIG_SCHEMA = ( .extend(uart.UART_DEVICE_SCHEMA) ) +FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( + "cm1106", + baud_rate=9600, + data_bits=8, + parity="NONE", + stop_bits=1, +) + async def to_code(config: ConfigType) -> None: """Code generation entry point.""" diff --git a/esphome/components/cse7761/cse7761.cpp b/esphome/components/cse7761/cse7761.cpp index 4251751531..103bc84452 100644 --- a/esphome/components/cse7761/cse7761.cpp +++ b/esphome/components/cse7761/cse7761.cpp @@ -58,7 +58,6 @@ void CSE7761Component::dump_config() { ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); - this->check_uart_settings(38400, 1, uart::UART_CONFIG_PARITY_EVEN, 8); } void CSE7761Component::update() { diff --git a/esphome/components/cse7761/sensor.py b/esphome/components/cse7761/sensor.py index b53ed26ca3..5f79be0255 100644 --- a/esphome/components/cse7761/sensor.py +++ b/esphome/components/cse7761/sensor.py @@ -68,7 +68,13 @@ CONFIG_SCHEMA = ( ) FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( - "cse7761", baud_rate=38400, require_rx=True, require_tx=True + "cse7761", + baud_rate=38400, + require_rx=True, + require_tx=True, + data_bits=8, + parity="EVEN", + stop_bits=1, ) diff --git a/esphome/components/cse7766/cse7766.cpp b/esphome/components/cse7766/cse7766.cpp index ce77b62b7b..30f1b7a867 100644 --- a/esphome/components/cse7766/cse7766.cpp +++ b/esphome/components/cse7766/cse7766.cpp @@ -255,7 +255,6 @@ void CSE7766Component::dump_config() { LOG_SENSOR(" ", "Apparent Power", this->apparent_power_sensor_); LOG_SENSOR(" ", "Reactive Power", this->reactive_power_sensor_); LOG_SENSOR(" ", "Power Factor", this->power_factor_sensor_); - this->check_uart_settings(4800, 1, uart::UART_CONFIG_PARITY_EVEN); } } // namespace esphome::cse7766 diff --git a/esphome/components/cse7766/sensor.py b/esphome/components/cse7766/sensor.py index a1a68e18e8..9bed0f3f59 100644 --- a/esphome/components/cse7766/sensor.py +++ b/esphome/components/cse7766/sensor.py @@ -84,7 +84,12 @@ CONFIG_SCHEMA = ( .extend(cv.COMPONENT_SCHEMA) ) FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( - "cse7766", baud_rate=4800, parity="EVEN", require_rx=True + "cse7766", + baud_rate=4800, + require_rx=True, + data_bits=8, + parity="EVEN", + stop_bits=1, ) diff --git a/esphome/components/daly_bms/__init__.py b/esphome/components/daly_bms/__init__.py index ba0be4d3a5..c0d7d0aa62 100644 --- a/esphome/components/daly_bms/__init__.py +++ b/esphome/components/daly_bms/__init__.py @@ -26,6 +26,14 @@ CONFIG_SCHEMA = ( .extend(cv.polling_component_schema("30s")) ) +FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( + "daly_bms", + baud_rate=9600, + data_bits=8, + parity="NONE", + stop_bits=1, +) + async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) diff --git a/esphome/components/daly_bms/daly_bms.cpp b/esphome/components/daly_bms/daly_bms.cpp index 530d8ad541..45d4db4972 100644 --- a/esphome/components/daly_bms/daly_bms.cpp +++ b/esphome/components/daly_bms/daly_bms.cpp @@ -22,10 +22,7 @@ static const uint8_t DALY_REQUEST_TEMPERATURE = 0x96; void DalyBmsComponent::setup() { this->next_request_ = 1; } -void DalyBmsComponent::dump_config() { - ESP_LOGCONFIG(TAG, "Daly BMS:"); - this->check_uart_settings(9600); -} +void DalyBmsComponent::dump_config() { ESP_LOGCONFIG(TAG, "Daly BMS:"); } void DalyBmsComponent::update() { this->trigger_next_ = true; diff --git a/esphome/components/dfplayer/__init__.py b/esphome/components/dfplayer/__init__.py index d589381461..bb18e6ba8c 100644 --- a/esphome/components/dfplayer/__init__.py +++ b/esphome/components/dfplayer/__init__.py @@ -60,7 +60,12 @@ CONFIG_SCHEMA = cv.All( ).extend(uart.UART_DEVICE_SCHEMA) ) FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( - "dfplayer", baud_rate=9600, require_tx=True + "dfplayer", + baud_rate=9600, + require_tx=True, + data_bits=8, + parity="NONE", + stop_bits=1, ) diff --git a/esphome/components/dfplayer/dfplayer.cpp b/esphome/components/dfplayer/dfplayer.cpp index 5c9d497c87..f81d1cd1b6 100644 --- a/esphome/components/dfplayer/dfplayer.cpp +++ b/esphome/components/dfplayer/dfplayer.cpp @@ -277,9 +277,6 @@ void DFPlayer::loop() { } } } -void DFPlayer::dump_config() { - ESP_LOGCONFIG(TAG, "DFPlayer:"); - this->check_uart_settings(9600); -} +void DFPlayer::dump_config() { ESP_LOGCONFIG(TAG, "DFPlayer:"); } } // namespace esphome::dfplayer diff --git a/esphome/components/hc8/hc8.cpp b/esphome/components/hc8/hc8.cpp index 900acca691..6a19f977a6 100644 --- a/esphome/components/hc8/hc8.cpp +++ b/esphome/components/hc8/hc8.cpp @@ -96,7 +96,6 @@ void HC8Component::dump_config() { " Warmup time: %" PRIu32 " s", this->warmup_seconds_); LOG_SENSOR(" ", "CO2", this->co2_sensor_); - this->check_uart_settings(9600); } } // namespace esphome::hc8 diff --git a/esphome/components/hc8/sensor.py b/esphome/components/hc8/sensor.py index 616162eb40..8a19cce8d1 100644 --- a/esphome/components/hc8/sensor.py +++ b/esphome/components/hc8/sensor.py @@ -47,6 +47,9 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( baud_rate=9600, require_rx=True, require_tx=True, + data_bits=8, + parity="NONE", + stop_bits=1, ) diff --git a/esphome/components/he60r/he60r.cpp b/esphome/components/he60r/he60r.cpp index f49224f17c..008505e2bb 100644 --- a/esphome/components/he60r/he60r.cpp +++ b/esphome/components/he60r/he60r.cpp @@ -38,7 +38,6 @@ CoverTraits HE60rCover::get_traits() { void HE60rCover::dump_config() { LOG_COVER("", "HE60R Cover", this); - this->check_uart_settings(1200, 1, uart::UART_CONFIG_PARITY_EVEN, 8); ESP_LOGCONFIG(TAG, " Open Duration: %.1fs\n" " Close Duration: %.1fs", diff --git a/esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.cpp b/esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.cpp index 270bb2709d..b323dd0436 100644 --- a/esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.cpp +++ b/esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.cpp @@ -68,8 +68,6 @@ void HrxlMaxsonarWrComponent::check_buffer_() { void HrxlMaxsonarWrComponent::dump_config() { ESP_LOGCONFIG(TAG, "HRXL MaxSonar WR Sensor:"); LOG_SENSOR(" ", "Distance", this); - // As specified in the sensor's data sheet - this->check_uart_settings(9600, 1, esphome::uart::UART_CONFIG_PARITY_NONE, 8); } } // namespace esphome::hrxl_maxsonar_wr diff --git a/esphome/components/hrxl_maxsonar_wr/sensor.py b/esphome/components/hrxl_maxsonar_wr/sensor.py index e4daacd869..b81a8b273d 100644 --- a/esphome/components/hrxl_maxsonar_wr/sensor.py +++ b/esphome/components/hrxl_maxsonar_wr/sensor.py @@ -23,6 +23,14 @@ CONFIG_SCHEMA = sensor.sensor_schema( state_class=STATE_CLASS_MEASUREMENT, ).extend(uart.UART_DEVICE_SCHEMA) +FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( + "hrxl_maxsonar_wr", + baud_rate=9600, + data_bits=8, + parity="NONE", + stop_bits=1, +) + async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) diff --git a/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp b/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp index 695a823cb7..05557111fc 100644 --- a/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp +++ b/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp @@ -11,7 +11,6 @@ static const char *const PROTOCOL_NAMES[] = {HYDREON_RGXX_PROTOCOL_LIST(, HYDREO static const char *const IGNORE_STRINGS[] = {HYDREON_RGXX_IGNORE_LIST(, HYDREON_RGXX_COMMA)}; void HydreonRGxxComponent::dump_config() { - this->check_uart_settings(9600, 1, esphome::uart::UART_CONFIG_PARITY_NONE, 8); ESP_LOGCONFIG(TAG, "hydreon_rgxx:"); if (this->is_failed()) { ESP_LOGE(TAG, "Connection with hydreon_rgxx failed!"); diff --git a/esphome/components/hydreon_rgxx/sensor.py b/esphome/components/hydreon_rgxx/sensor.py index 58e72571ff..8e269fef9a 100644 --- a/esphome/components/hydreon_rgxx/sensor.py +++ b/esphome/components/hydreon_rgxx/sensor.py @@ -130,6 +130,14 @@ CONFIG_SCHEMA = cv.All( _validate, ) +FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( + "hydreon_rgxx", + baud_rate=9600, + data_bits=8, + parity="NONE", + stop_bits=1, +) + async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) diff --git a/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp b/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp index 70f6d4eaa7..24e5d25921 100644 --- a/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp +++ b/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp @@ -26,8 +26,6 @@ void KamstrupKMPComponent::dump_config() { LOG_SENSOR(" ", "Custom Sensor", this->custom_sensors_[i]); ESP_LOGCONFIG(TAG, " Command: 0x%04X", this->custom_commands_[i]); } - - this->check_uart_settings(1200, 2, uart::UART_CONFIG_PARITY_NONE, 8); } void KamstrupKMPComponent::update() { diff --git a/esphome/components/kamstrup_kmp/sensor.py b/esphome/components/kamstrup_kmp/sensor.py index 6465012897..f6c236b72d 100644 --- a/esphome/components/kamstrup_kmp/sensor.py +++ b/esphome/components/kamstrup_kmp/sensor.py @@ -102,7 +102,13 @@ CONFIG_SCHEMA = ( ) FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( - "kamstrup_kmp", baud_rate=1200, require_rx=True, require_tx=True + "kamstrup_kmp", + baud_rate=1200, + require_rx=True, + require_tx=True, + data_bits=8, + parity="NONE", + stop_bits=2, ) diff --git a/esphome/components/mhz19/mhz19.cpp b/esphome/components/mhz19/mhz19.cpp index ff518808d9..707d952f83 100644 --- a/esphome/components/mhz19/mhz19.cpp +++ b/esphome/components/mhz19/mhz19.cpp @@ -143,8 +143,6 @@ void MHZ19Component::dump_config() { ESP_LOGCONFIG(TAG, "MH-Z19:"); LOG_SENSOR(" ", "CO2", this->co2_sensor_); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); - this->check_uart_settings(9600); - if (this->abc_boot_logic_ == MHZ19_ABC_ENABLED) { ESP_LOGCONFIG(TAG, " Automatic baseline calibration enabled on boot"); } else if (this->abc_boot_logic_ == MHZ19_ABC_DISABLED) { diff --git a/esphome/components/mhz19/sensor.py b/esphome/components/mhz19/sensor.py index 33cb27080c..5852686608 100644 --- a/esphome/components/mhz19/sensor.py +++ b/esphome/components/mhz19/sensor.py @@ -80,6 +80,14 @@ CONFIG_SCHEMA = ( .extend(uart.UART_DEVICE_SCHEMA) ) +FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( + "mhz19", + baud_rate=9600, + data_bits=8, + parity="NONE", + stop_bits=1, +) + async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) diff --git a/esphome/components/mk2pvrouter/mk2pvrouter.cpp b/esphome/components/mk2pvrouter/mk2pvrouter.cpp index a9c922602b..0c0476fb11 100644 --- a/esphome/components/mk2pvrouter/mk2pvrouter.cpp +++ b/esphome/components/mk2pvrouter/mk2pvrouter.cpp @@ -163,10 +163,7 @@ void Mk2PVRouter::publish_value_(const char *tag, const char *val) { #endif } -void Mk2PVRouter::dump_config() { - ESP_LOGCONFIG(TAG, "Mk2PVRouter:"); - this->check_uart_settings(BAUD_RATE, 1, uart::UART_CONFIG_PARITY_EVEN, 7); -} +void Mk2PVRouter::dump_config() { ESP_LOGCONFIG(TAG, "Mk2PVRouter:"); } #ifdef MK2PVROUTER_LISTENER_COUNT void Mk2PVRouter::register_mk2pvrouter_listener(Mk2PVRouterListener *listener) { diff --git a/esphome/components/mk2pvrouter/mk2pvrouter.h b/esphome/components/mk2pvrouter/mk2pvrouter.h index f542436f1d..fc23cf49e8 100644 --- a/esphome/components/mk2pvrouter/mk2pvrouter.h +++ b/esphome/components/mk2pvrouter/mk2pvrouter.h @@ -43,7 +43,6 @@ class Mk2PVRouter final : public Component, public uart::UARTDevice { protected: static constexpr size_t CRC_SUFFIX_LEN = 1; - static constexpr uint32_t BAUD_RATE = 9600; enum class State : uint8_t { WAITING_FOR_START, diff --git a/esphome/components/pm1006/pm1006.cpp b/esphome/components/pm1006/pm1006.cpp index 6a325c57dc..d4c6824713 100644 --- a/esphome/components/pm1006/pm1006.cpp +++ b/esphome/components/pm1006/pm1006.cpp @@ -16,7 +16,6 @@ void PM1006Component::dump_config() { ESP_LOGCONFIG(TAG, "PM1006:"); LOG_SENSOR(" ", "PM2.5", this->pm_2_5_sensor_); LOG_UPDATE_INTERVAL(this); - this->check_uart_settings(9600); } void PM1006Component::update() { diff --git a/esphome/components/pm1006/sensor.py b/esphome/components/pm1006/sensor.py index 8274726ac4..447671ebb3 100644 --- a/esphome/components/pm1006/sensor.py +++ b/esphome/components/pm1006/sensor.py @@ -48,6 +48,9 @@ def validate_interval_uart(config: ConfigType) -> None: baud_rate=9600, require_rx=True, require_tx=interval.total_milliseconds != SCHEDULER_DONT_RUN, + data_bits=8, + parity="NONE", + stop_bits=1, )(config) diff --git a/esphome/components/pmsx003/pmsx003.cpp b/esphome/components/pmsx003/pmsx003.cpp index 6275ff60c2..f8d890ac9e 100644 --- a/esphome/components/pmsx003/pmsx003.cpp +++ b/esphome/components/pmsx003/pmsx003.cpp @@ -46,8 +46,6 @@ void PMSX003Component::dump_config() { } else { ESP_LOGCONFIG(TAG, " Mode: passive with sleep/wake cycles"); } - - this->check_uart_settings(9600); } void PMSX003Component::loop() { diff --git a/esphome/components/pmsx003/sensor.py b/esphome/components/pmsx003/sensor.py index fe784c5ffe..dc85380203 100644 --- a/esphome/components/pmsx003/sensor.py +++ b/esphome/components/pmsx003/sensor.py @@ -302,7 +302,13 @@ CONFIG_SCHEMA = cv.All( def final_validate(config: ConfigType) -> None: require_tx = config[CONF_UPDATE_INTERVAL] > cv.time_period("0s") schema = uart.final_validate_device_schema( - "pmsx003", baud_rate=9600, require_rx=True, require_tx=require_tx + "pmsx003", + baud_rate=9600, + require_rx=True, + require_tx=require_tx, + data_bits=8, + parity="NONE", + stop_bits=1, ) schema(config) diff --git a/esphome/components/pylontech/__init__.py b/esphome/components/pylontech/__init__.py index 4ab606d9f9..242a613a6c 100644 --- a/esphome/components/pylontech/__init__.py +++ b/esphome/components/pylontech/__init__.py @@ -41,6 +41,14 @@ CONFIG_SCHEMA = cv.All( .extend(uart.UART_DEVICE_SCHEMA) ) +FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( + "pylontech", + baud_rate=115200, + data_bits=8, + parity="NONE", + stop_bits=1, +) + async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) diff --git a/esphome/components/pylontech/pylontech.cpp b/esphome/components/pylontech/pylontech.cpp index 54d9e5c654..932b71ba55 100644 --- a/esphome/components/pylontech/pylontech.cpp +++ b/esphome/components/pylontech/pylontech.cpp @@ -33,7 +33,6 @@ static const uint8_t ASCII_LF = 0x0A; PylontechComponent::PylontechComponent() {} void PylontechComponent::dump_config() { - this->check_uart_settings(115200, 1, esphome::uart::UART_CONFIG_PARITY_NONE, 8); ESP_LOGCONFIG(TAG, "pylontech:"); if (this->is_failed()) { ESP_LOGE(TAG, "Connection with pylontech failed!"); diff --git a/esphome/components/seeed_mr60fda2/__init__.py b/esphome/components/seeed_mr60fda2/__init__.py index de6e8ad57b..159a1ece9c 100644 --- a/esphome/components/seeed_mr60fda2/__init__.py +++ b/esphome/components/seeed_mr60fda2/__init__.py @@ -31,6 +31,7 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( require_tx=True, require_rx=True, baud_rate=115200, + data_bits=8, parity="NONE", stop_bits=1, ) diff --git a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp index 4875aa5cff..2d1cd0fbb4 100644 --- a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp +++ b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp @@ -33,8 +33,6 @@ void MR60FDA2Component::dump_config() { // Initialisation functions void MR60FDA2Component::setup() { - this->check_uart_settings(115200); - this->current_frame_locate_ = LOCATE_FRAME_HEADER; this->current_frame_id_ = 0; this->current_frame_len_ = 0; diff --git a/esphome/components/smt100/sensor.py b/esphome/components/smt100/sensor.py index 632a1e7547..7ba7da801c 100644 --- a/esphome/components/smt100/sensor.py +++ b/esphome/components/smt100/sensor.py @@ -68,7 +68,13 @@ CONFIG_SCHEMA = ( ) FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( - "smt100", baud_rate=9600, require_rx=True, require_tx=True + "smt100", + baud_rate=9600, + require_rx=True, + require_tx=True, + data_bits=8, + parity="NONE", + stop_bits=1, ) diff --git a/esphome/components/smt100/smt100.cpp b/esphome/components/smt100/smt100.cpp index ed33fc54c5..2889a9fb4d 100644 --- a/esphome/components/smt100/smt100.cpp +++ b/esphome/components/smt100/smt100.cpp @@ -65,7 +65,6 @@ void SMT100Component::dump_config() { LOG_SENSOR(TAG, "Temperature", this->temperature_sensor_); LOG_SENSOR(TAG, "Moisture", this->moisture_sensor_); LOG_UPDATE_INTERVAL(this); - this->check_uart_settings(9600); } int SMT100Component::readline_(int readch, char *buffer, int len) { diff --git a/esphome/components/t6615/sensor.py b/esphome/components/t6615/sensor.py index 6f3ef372bc..44dba52ae8 100644 --- a/esphome/components/t6615/sensor.py +++ b/esphome/components/t6615/sensor.py @@ -33,7 +33,13 @@ CONFIG_SCHEMA = ( ) FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( - "t6615", baud_rate=19200, require_rx=True, require_tx=True + "t6615", + baud_rate=19200, + require_rx=True, + require_tx=True, + data_bits=8, + parity="NONE", + stop_bits=1, ) diff --git a/esphome/components/t6615/t6615.cpp b/esphome/components/t6615/t6615.cpp index 1a98e48c14..982cc181b7 100644 --- a/esphome/components/t6615/t6615.cpp +++ b/esphome/components/t6615/t6615.cpp @@ -88,7 +88,6 @@ void T6615Component::query_ppm_() { void T6615Component::dump_config() { ESP_LOGCONFIG(TAG, "T6615:"); LOG_SENSOR(" ", "CO2", this->co2_sensor_); - this->check_uart_settings(19200); } } // namespace esphome::t6615 diff --git a/esphome/components/teleinfo/__init__.py b/esphome/components/teleinfo/__init__.py index f9233511e1..67aad11d0f 100644 --- a/esphome/components/teleinfo/__init__.py +++ b/esphome/components/teleinfo/__init__.py @@ -35,6 +35,22 @@ CONFIG_SCHEMA = ( ) +def _final_validate(config: ConfigType) -> ConfigType: + # Historical mode runs at 1200 baud, standard mode at 9600 baud. + baud_rate = 1200 if config[CONF_HISTORICAL_MODE] else 9600 + uart.final_validate_device_schema( + "teleinfo", + baud_rate=baud_rate, + data_bits=7, + parity="EVEN", + stop_bits=1, + )(config) + return config + + +FINAL_VALIDATE_SCHEMA = _final_validate + + async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID], config[CONF_HISTORICAL_MODE]) await cg.register_component(var, config) diff --git a/esphome/components/teleinfo/teleinfo.cpp b/esphome/components/teleinfo/teleinfo.cpp index e00895d162..17d3d6c099 100644 --- a/esphome/components/teleinfo/teleinfo.cpp +++ b/esphome/components/teleinfo/teleinfo.cpp @@ -184,10 +184,7 @@ void TeleInfo::publish_value_(const std::string &tag, const std::string &val) { element->publish_val(val); } } -void TeleInfo::dump_config() { - ESP_LOGCONFIG(TAG, "TeleInfo:"); - this->check_uart_settings(baud_rate_, 1, uart::UART_CONFIG_PARITY_EVEN, 7); -} +void TeleInfo::dump_config() { ESP_LOGCONFIG(TAG, "TeleInfo:"); } TeleInfo::TeleInfo(bool historical_mode) { if (historical_mode) { /* @@ -195,11 +192,9 @@ TeleInfo::TeleInfo(bool historical_mode) { */ checksum_area_end_ = 2; separator_ = 0x20; - baud_rate_ = 1200; } else { checksum_area_end_ = 1; separator_ = 0x9; - baud_rate_ = 9600; } } void TeleInfo::register_teleinfo_listener(TeleInfoListener *listener) { teleinfo_listeners_.push_back(listener); } diff --git a/esphome/components/teleinfo/teleinfo.h b/esphome/components/teleinfo/teleinfo.h index 4aab3bf2cd..b1bf586e9c 100644 --- a/esphome/components/teleinfo/teleinfo.h +++ b/esphome/components/teleinfo/teleinfo.h @@ -31,7 +31,6 @@ class TeleInfo final : public PollingComponent, public uart::UARTDevice { std::vector teleinfo_listeners_{}; protected: - uint32_t baud_rate_; int checksum_area_end_; int separator_; char buf_[MAX_BUF_SIZE]; diff --git a/esphome/components/tormatic/tormatic_cover.cpp b/esphome/components/tormatic/tormatic_cover.cpp index 7004c4f836..5c8d6623b6 100644 --- a/esphome/components/tormatic/tormatic_cover.cpp +++ b/esphome/components/tormatic/tormatic_cover.cpp @@ -36,8 +36,6 @@ cover::CoverTraits Tormatic::get_traits() { void Tormatic::dump_config() { LOG_COVER("", "Tormatic Cover", this); - this->check_uart_settings(9600, 1, uart::UART_CONFIG_PARITY_NONE, 8); - ESP_LOGCONFIG(TAG, " Open Duration: %.1fs\n" " Close Duration: %.1fs", diff --git a/esphome/components/uart/uart.h b/esphome/components/uart/uart.h index 899d349e21..eda5b72ea8 100644 --- a/esphome/components/uart/uart.h +++ b/esphome/components/uart/uart.h @@ -3,6 +3,7 @@ #include #include "esphome/core/component.h" #include "esphome/core/hal.h" +#include "esphome/core/helpers.h" #include "esphome/core/log.h" #include "uart_component.h" @@ -66,6 +67,7 @@ class UARTDevice { } /// Check that the configuration of the UART bus matches the provided values and otherwise print a warning + ESPDEPRECATED("Use uart.final_validate_device_schema() in Python instead. Removed in 2027.3.0", "2026.9.0") void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits = 1, UARTParityOptions parity = UART_CONFIG_PARITY_NONE, uint8_t data_bits = 8); diff --git a/esphome/components/ufm01/__init__.py b/esphome/components/ufm01/__init__.py index ca0ea57796..85ca0eecae 100644 --- a/esphome/components/ufm01/__init__.py +++ b/esphome/components/ufm01/__init__.py @@ -30,6 +30,7 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( require_tx=True, require_rx=True, baud_rate=2400, + data_bits=8, parity="EVEN", stop_bits=1, ) diff --git a/esphome/components/ufm01/ufm01.cpp b/esphome/components/ufm01/ufm01.cpp index bafdb5d853..880132bad3 100644 --- a/esphome/components/ufm01/ufm01.cpp +++ b/esphome/components/ufm01/ufm01.cpp @@ -213,7 +213,6 @@ void UFM01Component::dump_config() { LOG_BINARY_SENSOR(" ", "Empty Tube", this->empty_tube_binary_sensor_); LOG_BINARY_SENSOR(" ", "Flow Rate Out Of Range", this->flow_rate_out_of_range_binary_sensor_); #endif - this->check_uart_settings(2400, 1, uart::UART_CONFIG_PARITY_EVEN, 8); } void UFM01Component::on_active_frame_(uint8_t data[FRAME_SIZE]) { diff --git a/esphome/components/uponor_smatrix/__init__.py b/esphome/components/uponor_smatrix/__init__.py index 093408e868..ba686dc22a 100644 --- a/esphome/components/uponor_smatrix/__init__.py +++ b/esphome/components/uponor_smatrix/__init__.py @@ -50,7 +50,7 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( require_tx=True, require_rx=True, data_bits=8, - parity=None, + parity="NONE", stop_bits=1, ) diff --git a/esphome/components/uponor_smatrix/uponor_smatrix.cpp b/esphome/components/uponor_smatrix/uponor_smatrix.cpp index c77f3468c7..74974548af 100644 --- a/esphome/components/uponor_smatrix/uponor_smatrix.cpp +++ b/esphome/components/uponor_smatrix/uponor_smatrix.cpp @@ -29,8 +29,6 @@ void UponorSmatrixComponent::dump_config() { } #endif - this->check_uart_settings(19200); - if (!this->unknown_devices_.empty()) { ESP_LOGCONFIG(TAG, " Detected unknown device addresses:"); for (auto device_address : this->unknown_devices_) { diff --git a/esphome/components/vbus/__init__.py b/esphome/components/vbus/__init__.py index 94857050f2..fd54658912 100644 --- a/esphome/components/vbus/__init__.py +++ b/esphome/components/vbus/__init__.py @@ -29,6 +29,14 @@ CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend( } ) +FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( + "vbus", + baud_rate=9600, + data_bits=8, + parity="NONE", + stop_bits=1, +) + async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) diff --git a/esphome/components/vbus/vbus.cpp b/esphome/components/vbus/vbus.cpp index 81714a2049..080567e7f9 100644 --- a/esphome/components/vbus/vbus.cpp +++ b/esphome/components/vbus/vbus.cpp @@ -11,10 +11,7 @@ static const char *const TAG = "vbus"; // Maximum bytes to log in verbose hex output (16 frames * 4 bytes = 64 bytes typical) static constexpr size_t VBUS_MAX_LOG_BYTES = 64; -void VBus::dump_config() { - ESP_LOGCONFIG(TAG, "VBus:"); - check_uart_settings(9600); -} +void VBus::dump_config() { ESP_LOGCONFIG(TAG, "VBus:"); } static void septet_spread(uint8_t *data, int start, int count, uint8_t septet) { for (int i = 0; i < count; i++, septet >>= 1) { diff --git a/esphome/components/wl_134/text_sensor.py b/esphome/components/wl_134/text_sensor.py index af5e705786..2e3021504f 100644 --- a/esphome/components/wl_134/text_sensor.py +++ b/esphome/components/wl_134/text_sensor.py @@ -21,6 +21,14 @@ CONFIG_SCHEMA = ( .extend(uart.UART_DEVICE_SCHEMA) ) +FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( + "wl_134", + baud_rate=9600, + data_bits=8, + parity="NONE", + stop_bits=1, +) + async def to_code(config: ConfigType) -> None: var = await text_sensor.new_text_sensor(config) diff --git a/esphome/components/wl_134/wl_134.cpp b/esphome/components/wl_134/wl_134.cpp index 5e86d5a441..858f974f2b 100644 --- a/esphome/components/wl_134/wl_134.cpp +++ b/esphome/components/wl_134/wl_134.cpp @@ -110,7 +110,5 @@ uint64_t Wl134Component::hex_lsb_ascii_to_uint64_(const uint8_t *text, uint8_t t void Wl134Component::dump_config() { ESP_LOGCONFIG(TAG, "WL-134 Sensor:"); LOG_TEXT_SENSOR("", "Tag", this); - // As specified in the sensor's data sheet - this->check_uart_settings(9600, 1, esphome::uart::UART_CONFIG_PARITY_NONE, 8); } } // namespace esphome::wl_134 diff --git a/tests/components/cse7761/test.esp32-idf.yaml b/tests/components/cse7761/test.esp32-idf.yaml index a6a8fee7e9..b9ae061c25 100644 --- a/tests/components/cse7761/test.esp32-idf.yaml +++ b/tests/components/cse7761/test.esp32-idf.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO14 packages: - uart_38400: !include ../../test_build_components/common/uart_38400/esp32-idf.yaml + uart_38400_even: !include ../../test_build_components/common/uart_38400_even/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/cse7761/test.esp8266-ard.yaml b/tests/components/cse7761/test.esp8266-ard.yaml index 134274ffb8..0d57039e1c 100644 --- a/tests/components/cse7761/test.esp8266-ard.yaml +++ b/tests/components/cse7761/test.esp8266-ard.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO3 packages: - uart_38400: !include ../../test_build_components/common/uart_38400/esp8266-ard.yaml + uart_38400_even: !include ../../test_build_components/common/uart_38400_even/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/cse7761/test.rp2040-ard.yaml b/tests/components/cse7761/test.rp2040-ard.yaml index b813e0f7f1..65e6252c51 100644 --- a/tests/components/cse7761/test.rp2040-ard.yaml +++ b/tests/components/cse7761/test.rp2040-ard.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO5 packages: - uart_38400: !include ../../test_build_components/common/uart_38400/rp2040-ard.yaml + uart_38400_even: !include ../../test_build_components/common/uart_38400_even/rp2040-ard.yaml <<: !include common.yaml diff --git a/tests/components/kamstrup_kmp/test.esp32-idf.yaml b/tests/components/kamstrup_kmp/test.esp32-idf.yaml index 1016905720..4e1ff86fb7 100644 --- a/tests/components/kamstrup_kmp/test.esp32-idf.yaml +++ b/tests/components/kamstrup_kmp/test.esp32-idf.yaml @@ -1,4 +1,4 @@ packages: - uart_1200: !include ../../test_build_components/common/uart_1200/esp32-idf.yaml + uart_1200_none_2stopbits: !include ../../test_build_components/common/uart_1200_none_2stopbits/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/kamstrup_kmp/test.esp8266-ard.yaml b/tests/components/kamstrup_kmp/test.esp8266-ard.yaml index f55c18eb76..631516eba9 100644 --- a/tests/components/kamstrup_kmp/test.esp8266-ard.yaml +++ b/tests/components/kamstrup_kmp/test.esp8266-ard.yaml @@ -3,6 +3,6 @@ substitutions: uart_rx_pin: GPIO3 packages: - uart_1200: !include ../../test_build_components/common/uart_1200/esp8266-ard.yaml + uart_1200_none_2stopbits: !include ../../test_build_components/common/uart_1200_none_2stopbits/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/pylontech/test.esp32-idf.yaml b/tests/components/pylontech/test.esp32-idf.yaml index b415125e84..7d5c371187 100644 --- a/tests/components/pylontech/test.esp32-idf.yaml +++ b/tests/components/pylontech/test.esp32-idf.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO5 packages: - uart: !include ../../test_build_components/common/uart/esp32-idf.yaml + uart_115200: !include ../../test_build_components/common/uart_115200/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/pylontech/test.esp8266-ard.yaml b/tests/components/pylontech/test.esp8266-ard.yaml index 96ab4ef6ac..c49b2bfee1 100644 --- a/tests/components/pylontech/test.esp8266-ard.yaml +++ b/tests/components/pylontech/test.esp8266-ard.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO2 packages: - uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml + uart_115200: !include ../../test_build_components/common/uart_115200/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/pylontech/test.rp2040-ard.yaml b/tests/components/pylontech/test.rp2040-ard.yaml index b28f2b5e05..5b2785b792 100644 --- a/tests/components/pylontech/test.rp2040-ard.yaml +++ b/tests/components/pylontech/test.rp2040-ard.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO5 packages: - uart: !include ../../test_build_components/common/uart/rp2040-ard.yaml + uart_115200: !include ../../test_build_components/common/uart_115200/rp2040-ard.yaml <<: !include common.yaml diff --git a/tests/components/teleinfo/test.esp32-idf.yaml b/tests/components/teleinfo/test.esp32-idf.yaml index b415125e84..3071f9a67b 100644 --- a/tests/components/teleinfo/test.esp32-idf.yaml +++ b/tests/components/teleinfo/test.esp32-idf.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO5 packages: - uart: !include ../../test_build_components/common/uart/esp32-idf.yaml + uart_1200_even_7bits: !include ../../test_build_components/common/uart_1200_even_7bits/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/teleinfo/test.esp8266-ard.yaml b/tests/components/teleinfo/test.esp8266-ard.yaml index 96ab4ef6ac..29490b3be3 100644 --- a/tests/components/teleinfo/test.esp8266-ard.yaml +++ b/tests/components/teleinfo/test.esp8266-ard.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO2 packages: - uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml + uart_1200_even_7bits: !include ../../test_build_components/common/uart_1200_even_7bits/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/teleinfo/test.rp2040-ard.yaml b/tests/components/teleinfo/test.rp2040-ard.yaml index b28f2b5e05..f13d5a9f8f 100644 --- a/tests/components/teleinfo/test.rp2040-ard.yaml +++ b/tests/components/teleinfo/test.rp2040-ard.yaml @@ -3,6 +3,6 @@ substitutions: rx_pin: GPIO5 packages: - uart: !include ../../test_build_components/common/uart/rp2040-ard.yaml + uart_1200_even_7bits: !include ../../test_build_components/common/uart_1200_even_7bits/rp2040-ard.yaml <<: !include common.yaml diff --git a/tests/components/teleinfo/validate-standard.esp32-idf.yaml b/tests/components/teleinfo/validate-standard.esp32-idf.yaml new file mode 100644 index 0000000000..2ca014c8af --- /dev/null +++ b/tests/components/teleinfo/validate-standard.esp32-idf.yaml @@ -0,0 +1,14 @@ +packages: + uart_9600_even_7bits: !include ../../test_build_components/common/uart_9600_even_7bits/esp32-idf.yaml + +teleinfo: + id: test_teleinfo_standard + historical_mode: false + update_interval: 60s + +sensor: + - platform: teleinfo + name: sinsts + tag_name: SINSTS + teleinfo_id: test_teleinfo_standard + unit_of_measurement: VA diff --git a/tests/test_build_components/common/uart_1200_even_7bits/esp32-ard.yaml b/tests/test_build_components/common/uart_1200_even_7bits/esp32-ard.yaml new file mode 100644 index 0000000000..931905032d --- /dev/null +++ b/tests/test_build_components/common/uart_1200_even_7bits/esp32-ard.yaml @@ -0,0 +1,14 @@ +# Common UART configuration for ESP32 Arduino tests - 1200 baud, EVEN parity, 7 data bits + +substitutions: + tx_pin: GPIO17 + rx_pin: GPIO16 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 1200 + parity: EVEN + data_bits: 7 + stop_bits: 1 diff --git a/tests/test_build_components/common/uart_1200_even_7bits/esp32-c3-ard.yaml b/tests/test_build_components/common/uart_1200_even_7bits/esp32-c3-ard.yaml new file mode 100644 index 0000000000..a67b0b6ace --- /dev/null +++ b/tests/test_build_components/common/uart_1200_even_7bits/esp32-c3-ard.yaml @@ -0,0 +1,14 @@ +# Common UART configuration for ESP32-C3 Arduino tests - 1200 baud, EVEN parity, 7 data bits + +substitutions: + tx_pin: GPIO20 + rx_pin: GPIO21 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 1200 + parity: EVEN + data_bits: 7 + stop_bits: 1 diff --git a/tests/test_build_components/common/uart_1200_even_7bits/esp32-c3-idf.yaml b/tests/test_build_components/common/uart_1200_even_7bits/esp32-c3-idf.yaml new file mode 100644 index 0000000000..135aaa68c9 --- /dev/null +++ b/tests/test_build_components/common/uart_1200_even_7bits/esp32-c3-idf.yaml @@ -0,0 +1,14 @@ +# Common UART configuration for ESP32-C3 IDF tests - 1200 baud, EVEN parity, 7 data bits + +substitutions: + tx_pin: GPIO20 + rx_pin: GPIO21 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 1200 + parity: EVEN + data_bits: 7 + stop_bits: 1 diff --git a/tests/test_build_components/common/uart_1200_even_7bits/esp32-idf.yaml b/tests/test_build_components/common/uart_1200_even_7bits/esp32-idf.yaml new file mode 100644 index 0000000000..4cbe16dfd5 --- /dev/null +++ b/tests/test_build_components/common/uart_1200_even_7bits/esp32-idf.yaml @@ -0,0 +1,14 @@ +# Common UART configuration for ESP32 IDF tests - 1200 baud, EVEN parity, 7 data bits + +substitutions: + tx_pin: GPIO17 + rx_pin: GPIO16 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 1200 + parity: EVEN + data_bits: 7 + stop_bits: 1 diff --git a/tests/test_build_components/common/uart_1200_even_7bits/esp8266-ard.yaml b/tests/test_build_components/common/uart_1200_even_7bits/esp8266-ard.yaml new file mode 100644 index 0000000000..2eedcad6d3 --- /dev/null +++ b/tests/test_build_components/common/uart_1200_even_7bits/esp8266-ard.yaml @@ -0,0 +1,14 @@ +# Common UART configuration for ESP8266 Arduino tests - 1200 baud, EVEN parity, 7 data bits + +substitutions: + tx_pin: GPIO4 + rx_pin: GPIO5 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 1200 + parity: EVEN + data_bits: 7 + stop_bits: 1 diff --git a/tests/test_build_components/common/uart_1200_even_7bits/rp2040-ard.yaml b/tests/test_build_components/common/uart_1200_even_7bits/rp2040-ard.yaml new file mode 100644 index 0000000000..d3edc1c1c9 --- /dev/null +++ b/tests/test_build_components/common/uart_1200_even_7bits/rp2040-ard.yaml @@ -0,0 +1,14 @@ +# Common UART configuration for RP2040 Arduino tests - 1200 baud, EVEN parity, 7 data bits + +substitutions: + tx_pin: GPIO0 + rx_pin: GPIO1 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 1200 + parity: EVEN + data_bits: 7 + stop_bits: 1 diff --git a/tests/test_build_components/common/uart_38400_even/esp32-ard.yaml b/tests/test_build_components/common/uart_38400_even/esp32-ard.yaml new file mode 100644 index 0000000000..4235c9c027 --- /dev/null +++ b/tests/test_build_components/common/uart_38400_even/esp32-ard.yaml @@ -0,0 +1,12 @@ +# Common UART configuration for ESP32 Arduino tests - 38400 baud, EVEN parity + +substitutions: + tx_pin: GPIO17 + rx_pin: GPIO16 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 38400 + parity: EVEN diff --git a/tests/test_build_components/common/uart_38400_even/esp32-c3-ard.yaml b/tests/test_build_components/common/uart_38400_even/esp32-c3-ard.yaml new file mode 100644 index 0000000000..c20b7939e9 --- /dev/null +++ b/tests/test_build_components/common/uart_38400_even/esp32-c3-ard.yaml @@ -0,0 +1,12 @@ +# Common UART configuration for ESP32-C3 Arduino tests - 38400 baud, EVEN parity + +substitutions: + tx_pin: GPIO20 + rx_pin: GPIO21 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 38400 + parity: EVEN diff --git a/tests/test_build_components/common/uart_38400_even/esp32-c3-idf.yaml b/tests/test_build_components/common/uart_38400_even/esp32-c3-idf.yaml new file mode 100644 index 0000000000..0aeb13a7c3 --- /dev/null +++ b/tests/test_build_components/common/uart_38400_even/esp32-c3-idf.yaml @@ -0,0 +1,12 @@ +# Common UART configuration for ESP32-C3 IDF tests - 38400 baud, EVEN parity + +substitutions: + tx_pin: GPIO20 + rx_pin: GPIO21 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 38400 + parity: EVEN diff --git a/tests/test_build_components/common/uart_38400_even/esp32-idf.yaml b/tests/test_build_components/common/uart_38400_even/esp32-idf.yaml new file mode 100644 index 0000000000..b79b91448e --- /dev/null +++ b/tests/test_build_components/common/uart_38400_even/esp32-idf.yaml @@ -0,0 +1,12 @@ +# Common UART configuration for ESP32 IDF tests - 38400 baud, EVEN parity + +substitutions: + tx_pin: GPIO17 + rx_pin: GPIO16 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 38400 + parity: EVEN diff --git a/tests/test_build_components/common/uart_38400_even/esp8266-ard.yaml b/tests/test_build_components/common/uart_38400_even/esp8266-ard.yaml new file mode 100644 index 0000000000..373680e8e6 --- /dev/null +++ b/tests/test_build_components/common/uart_38400_even/esp8266-ard.yaml @@ -0,0 +1,12 @@ +# Common UART configuration for ESP8266 Arduino tests - 38400 baud, EVEN parity + +substitutions: + tx_pin: GPIO4 + rx_pin: GPIO5 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 38400 + parity: EVEN diff --git a/tests/test_build_components/common/uart_38400_even/rp2040-ard.yaml b/tests/test_build_components/common/uart_38400_even/rp2040-ard.yaml new file mode 100644 index 0000000000..950f7b4957 --- /dev/null +++ b/tests/test_build_components/common/uart_38400_even/rp2040-ard.yaml @@ -0,0 +1,12 @@ +# Common UART configuration for RP2040 Arduino tests - 38400 baud, EVEN parity + +substitutions: + tx_pin: GPIO0 + rx_pin: GPIO1 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 38400 + parity: EVEN From 567f7f9196425e0b8637b16b2a43373e376e2df4 Mon Sep 17 00:00:00 2001 From: Keith Burzinski Date: Wed, 2 Sep 2026 15:01:23 -0500 Subject: [PATCH 4/4] [serial_proxy] Skip no-op reconfigure requests (#18953) Co-authored-by: puddly <32534428+puddly@users.noreply.github.com> --- .../components/serial_proxy/serial_proxy.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/esphome/components/serial_proxy/serial_proxy.cpp b/esphome/components/serial_proxy/serial_proxy.cpp index 2ab0d4ebb4..c1c1510643 100644 --- a/esphome/components/serial_proxy/serial_proxy.cpp +++ b/esphome/components/serial_proxy/serial_proxy.cpp @@ -130,17 +130,26 @@ SerialProxyResult SerialProxy::configure(api::APIConnection *api_connection, uin return SerialProxyResult::SERIAL_PROXY_RESULT_NOT_SUPPORTED; } - // Apply validated parameters - uart_comp->set_baud_rate(baudrate); - uart_comp->set_stop_bits(stop_bits); - uart_comp->set_data_bits(data_size); - - // Map parity value to UARTParityOptions + // Skip a no-op reconfigure. Clients routinely re-send identical settings on every + // port open, and on a USB UART each apply is a CDC SET_LINE_CODING control transfer. + // Some bridges watch line-coding changes as a signalling channel (a magic baud + // sequence to enter a bootloader, say), so redundant applies are not harmless. static const uart::UARTParityOptions PARITY_MAP[] = { uart::UART_CONFIG_PARITY_NONE, uart::UART_CONFIG_PARITY_EVEN, uart::UART_CONFIG_PARITY_ODD, }; + if (uart_comp->get_baud_rate() == baudrate && uart_comp->get_stop_bits() == stop_bits && + uart_comp->get_data_bits() == data_size && uart_comp->get_parity() == PARITY_MAP[parity]) { + ESP_LOGV(TAG, "Settings unchanged, skipping reconfigure [%" PRIu32 "]", this->instance_index_); + return SerialProxyResult::SERIAL_PROXY_RESULT_OK; + } + + // Apply validated parameters + uart_comp->set_baud_rate(baudrate); + uart_comp->set_stop_bits(stop_bits); + uart_comp->set_data_bits(data_size); + uart_comp->set_parity(PARITY_MAP[parity]); // load_settings() is available on ESP8266 and ESP32 platforms