diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 9bf5b0eeb4..dfca1e51f0 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -1841,4 +1841,10 @@ class CompactString { static_assert(sizeof(CompactString) == 20, "CompactString must be exactly 20 bytes"); +// Reverse comparison overloads so CompactString works on either side of == and != +inline bool operator==(const std::string &lhs, const CompactString &rhs) { return rhs == lhs; } +inline bool operator==(const char *lhs, const CompactString &rhs) { return rhs == lhs; } +inline bool operator!=(const std::string &lhs, const CompactString &rhs) { return !(rhs == lhs); } +inline bool operator!=(const char *lhs, const CompactString &rhs) { return !(rhs == lhs); } + } // namespace esphome