From 76cdef966bf2559b99deaa08214ac0a124e80531 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 4 Aug 2025 11:14:22 -1000 Subject: [PATCH 1/2] fix --- esphome/components/api/custom_api_device.h | 36 ++++++---------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/esphome/components/api/custom_api_device.h b/esphome/components/api/custom_api_device.h index f67a0832be..2e7bb705af 100644 --- a/esphome/components/api/custom_api_device.h +++ b/esphome/components/api/custom_api_device.h @@ -61,7 +61,8 @@ class CustomAPIDevice { void register_service(void (T::*callback)(Ts...), const std::string &name, const std::array &arg_names) { static_assert( - false, "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration"); + sizeof(T) == 0, + "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration"); } #endif @@ -91,7 +92,8 @@ class CustomAPIDevice { #else template void register_service(void (T::*callback)(), const std::string &name) { static_assert( - false, "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration"); + sizeof(T) == 0, + "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration"); } #endif @@ -151,15 +153,17 @@ class CustomAPIDevice { template void subscribe_homeassistant_state(void (T::*callback)(std::string), const std::string &entity_id, const std::string &attribute = "") { - static_assert(false, "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section " - "of your YAML configuration"); + static_assert(sizeof(T) == 0, + "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section " + "of your YAML configuration"); } template void subscribe_homeassistant_state(void (T::*callback)(std::string, std::string), const std::string &entity_id, const std::string &attribute = "") { - static_assert(false, "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section " - "of your YAML configuration"); + static_assert(sizeof(T) == 0, + "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section " + "of your YAML configuration"); } #endif @@ -248,26 +252,6 @@ class CustomAPIDevice { } global_api_server->send_homeassistant_service_call(resp); } -#else - void call_homeassistant_service(const std::string &service_name) { - static_assert(false, "call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' section " - "of your YAML configuration"); - } - - void call_homeassistant_service(const std::string &service_name, const std::map &data) { - static_assert(false, "call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' section " - "of your YAML configuration"); - } - - void fire_homeassistant_event(const std::string &event_name) { - static_assert(false, "fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' section of " - "your YAML configuration"); - } - - void fire_homeassistant_event(const std::string &service_name, const std::map &data) { - static_assert(false, "fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' section of " - "your YAML configuration"); - } #endif }; From fb1d2368a91c6deba836d5085c5579f69ebad370 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 4 Aug 2025 11:15:47 -1000 Subject: [PATCH 2/2] fix --- esphome/components/api/custom_api_device.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/esphome/components/api/custom_api_device.h b/esphome/components/api/custom_api_device.h index 2e7bb705af..44f9eee571 100644 --- a/esphome/components/api/custom_api_device.h +++ b/esphome/components/api/custom_api_device.h @@ -252,6 +252,28 @@ class CustomAPIDevice { } global_api_server->send_homeassistant_service_call(resp); } +#else + template void call_homeassistant_service(const std::string &service_name) { + static_assert(sizeof(T) == 0, "call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' " + "section of your YAML configuration"); + } + + template + void call_homeassistant_service(const std::string &service_name, const std::map &data) { + static_assert(sizeof(T) == 0, "call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' " + "section of your YAML configuration"); + } + + template void fire_homeassistant_event(const std::string &event_name) { + static_assert(sizeof(T) == 0, "fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' " + "section of your YAML configuration"); + } + + template + void fire_homeassistant_event(const std::string &service_name, const std::map &data) { + static_assert(sizeof(T) == 0, "fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' " + "section of your YAML configuration"); + } #endif };