From 139ce4c655bc649f2184f67f410bf8e8e7d3db51 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 11 Jul 2025 15:54:20 -1000 Subject: [PATCH] lint --- .../custom_api_device_component.cpp | 52 +++++++++++++++++++ .../custom_api_device_component.h | 43 +++------------ 2 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp diff --git a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp new file mode 100644 index 0000000000..892ad17842 --- /dev/null +++ b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp @@ -0,0 +1,52 @@ +#include "custom_api_device_component.h" +#include "esphome/core/log.h" + +#ifdef USE_API +namespace esphome { +namespace custom_api_device_component { + +static const char *const TAG = "custom_api"; + +void CustomAPIDeviceComponent::setup() { + // Register services using CustomAPIDevice + register_service(&CustomAPIDeviceComponent::on_test_service, "custom_test_service"); + + register_service(&CustomAPIDeviceComponent::on_service_with_args, "custom_service_with_args", + {"arg_string", "arg_int", "arg_bool", "arg_float"}); + + // Test array types + register_service(&CustomAPIDeviceComponent::on_service_with_arrays, "custom_service_with_arrays", + {"bool_array", "int_array", "float_array", "string_array"}); +} + +void CustomAPIDeviceComponent::on_test_service() { ESP_LOGI(TAG, "Custom test service called!"); } + +void CustomAPIDeviceComponent::on_service_with_args(std::string arg_string, int32_t arg_int, bool arg_bool, + float arg_float) { + ESP_LOGI(TAG, "Custom service called with: %s, %d, %d, %.2f", arg_string.c_str(), arg_int, arg_bool, arg_float); +} + +void CustomAPIDeviceComponent::on_service_with_arrays(std::vector bool_array, std::vector int_array, + std::vector float_array, + std::vector string_array) { + ESP_LOGI(TAG, "Array service called with %zu bools, %zu ints, %zu floats, %zu strings", bool_array.size(), + int_array.size(), float_array.size(), string_array.size()); + + // Log first element of each array if not empty + if (!bool_array.empty()) { + ESP_LOGI(TAG, "First bool: %d", bool_array[0]); + } + if (!int_array.empty()) { + ESP_LOGI(TAG, "First int: %d", int_array[0]); + } + if (!float_array.empty()) { + ESP_LOGI(TAG, "First float: %.2f", float_array[0]); + } + if (!string_array.empty()) { + ESP_LOGI(TAG, "First string: %s", string_array[0].c_str()); + } +} + +} // namespace custom_api_device_component +} // namespace esphome +#endif // USE_API diff --git a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h index a0d98f0444..cdfda63348 100644 --- a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h +++ b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h @@ -1,6 +1,9 @@ #pragma once -#include "esphome.h" +#include +#include +#include "esphome/core/component.h" +#include "esphome/components/api/custom_api_device.h" #ifdef USE_API namespace esphome { @@ -10,44 +13,14 @@ using namespace api; class CustomAPIDeviceComponent : public Component, public CustomAPIDevice { public: - void setup() override { - // Register services using CustomAPIDevice - register_service(&CustomAPIDeviceComponent::on_test_service, "custom_test_service"); + void setup() override; - register_service(&CustomAPIDeviceComponent::on_service_with_args, "custom_service_with_args", - {"arg_string", "arg_int", "arg_bool", "arg_float"}); + void on_test_service(); - // Test array types - register_service(&CustomAPIDeviceComponent::on_service_with_arrays, "custom_service_with_arrays", - {"bool_array", "int_array", "float_array", "string_array"}); - } - - void on_test_service() { ESP_LOGI("custom_api", "Custom test service called!"); } - - void on_service_with_args(std::string arg_string, int32_t arg_int, bool arg_bool, float arg_float) { - ESP_LOGI("custom_api", "Custom service called with: %s, %d, %d, %.2f", arg_string.c_str(), arg_int, arg_bool, - arg_float); - } + void on_service_with_args(std::string arg_string, int32_t arg_int, bool arg_bool, float arg_float); void on_service_with_arrays(std::vector bool_array, std::vector int_array, - std::vector float_array, std::vector string_array) { - ESP_LOGI("custom_api", "Array service called with %zu bools, %zu ints, %zu floats, %zu strings", bool_array.size(), - int_array.size(), float_array.size(), string_array.size()); - - // Log first element of each array if not empty - if (!bool_array.empty()) { - ESP_LOGI("custom_api", "First bool: %d", bool_array[0]); - } - if (!int_array.empty()) { - ESP_LOGI("custom_api", "First int: %d", int_array[0]); - } - if (!float_array.empty()) { - ESP_LOGI("custom_api", "First float: %.2f", float_array[0]); - } - if (!string_array.empty()) { - ESP_LOGI("custom_api", "First string: %s", string_array[0].c_str()); - } - } + std::vector float_array, std::vector string_array); }; } // namespace custom_api_device_component