diff --git a/esphome/components/mapping/mapping.h b/esphome/components/mapping/mapping.h index 99c1f38829..92138c4377 100644 --- a/esphome/components/mapping/mapping.h +++ b/esphome/components/mapping/mapping.h @@ -2,6 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" +#include #include #include @@ -43,7 +44,20 @@ template class Mapping { esph_log_e(TAG, "Key '%p' not found in mapping", key); } else if constexpr (std::is_same_v) { esph_log_e(TAG, "Key '%s' not found in mapping", key.c_str()); + } else if constexpr (std::is_integral_v) { + char buf[24]; // enough for int64_t + buf_append_printf(buf, sizeof(buf), 0, "%" PRId64, static_cast(key)); + esph_log_e(TAG, "Key '%s' not found in mapping", buf); + } else if constexpr (std::is_floating_point_v) { + char buf[24]; + buf_append_printf(buf, sizeof(buf), 0, "%g", static_cast(key)); + esph_log_e(TAG, "Key '%s' not found in mapping", buf); + } else if constexpr (std::is_enum_v) { + char buf[24]; // enough for underlying integral type + buf_append_printf(buf, sizeof(buf), 0, "%" PRId64, static_cast(key)); + esph_log_e(TAG, "Key '%s' not found in mapping", buf); } else { + // Fallback for custom types - likely unreachable but kept for compatibility esph_log_e(TAG, "Key '%s' not found in mapping", to_string(key).c_str()); } return {};