This commit is contained in:
J. Nick Koston
2025-11-19 22:49:52 -06:00
parent efe2a1a506
commit b9595c0795
4 changed files with 24 additions and 0 deletions
@@ -17,6 +17,10 @@ void CustomAPIDeviceComponent::setup() {
// Test array types
register_service(&CustomAPIDeviceComponent::on_service_with_arrays, "custom_service_with_arrays",
{"bool_array", "int_array", "float_array", "string_array"});
// Test Home Assistant state subscription using std::string API (custom_api_device.h)
// This tests the backward compatibility of the std::string overloads
subscribe_homeassistant_state(&CustomAPIDeviceComponent::on_ha_state_changed, std::string("sensor.custom_test"));
}
void CustomAPIDeviceComponent::on_test_service() { ESP_LOGI(TAG, "Custom test service called!"); }
@@ -48,6 +52,11 @@ void CustomAPIDeviceComponent::on_service_with_arrays(std::vector<bool> bool_arr
}
}
void CustomAPIDeviceComponent::on_ha_state_changed(std::string entity_id, std::string state) {
ESP_LOGI(TAG, "Home Assistant state changed for %s: %s", entity_id.c_str(), state.c_str());
ESP_LOGI(TAG, "This subscription uses std::string API for backward compatibility");
}
} // namespace custom_api_device_component
} // namespace esphome
#endif // USE_API
@@ -22,6 +22,9 @@ class CustomAPIDeviceComponent : public Component, public CustomAPIDevice {
void on_service_with_arrays(std::vector<bool> bool_array, std::vector<int32_t> int_array,
std::vector<float> float_array, std::vector<std::string> string_array);
// Test Home Assistant state subscription with std::string API
void on_ha_state_changed(std::string entity_id, std::string state);
};
} // namespace custom_api_device_component