From b7d16787cd874f22c390ebc2ff4b65d2bf3ebd49 Mon Sep 17 00:00:00 2001 From: Steve Wagner Date: Wed, 7 Feb 2024 17:13:23 +0100 Subject: [PATCH] use esphome optioanl and fake it for tests --- components/samsung_ac/protocol.h | 5 +++-- components/samsung_ac/util.h | 8 -------- test/esphome/core/optional.h | 13 +++++++++++++ test/test_stuff.h | 1 + 4 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 test/esphome/core/optional.h diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 0389bed2..10d283c0 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -1,5 +1,6 @@ #pragma once +#include "esphome/core/optional.h" #include "util.h" namespace esphome @@ -79,8 +80,8 @@ namespace esphome class ProtocolRequest { public: - opt power; - opt mode; + optional power; + optional mode; }; class Protocol diff --git a/components/samsung_ac/util.h b/components/samsung_ac/util.h index 1f213678..fbe8fba4 100644 --- a/components/samsung_ac/util.h +++ b/components/samsung_ac/util.h @@ -6,7 +6,6 @@ #include #include #include -#include namespace esphome { @@ -19,12 +18,5 @@ namespace esphome std::string bytes_to_hex(const std::vector &data); std::vector hex_to_bytes(const std::string &hex); void print_bits_8(uint8_t value); - - // esphome optional did not work in tests and std::optional is not available in c++ 14. - template - using opt = std::experimental::optional; - using opt_null_t = std::experimental::nullopt_t; - constexpr auto nullopt = std::experimental::nullopt; - } // namespace samsung_ac } // namespace esphome diff --git a/test/esphome/core/optional.h b/test/esphome/core/optional.h new file mode 100644 index 00000000..3518c53a --- /dev/null +++ b/test/esphome/core/optional.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +// Fakes the esphome optional type with std experimental/optional + +namespace esphome +{ + template + using optional = std::experimental::optional; + /* using opt_null_t = std::experimental::nullopt_t; + constexpr auto nullopt = std::experimental::nullopt;*/ +} \ No newline at end of file diff --git a/test/test_stuff.h b/test/test_stuff.h index 7ce53d7c..cd1d0bff 100644 --- a/test/test_stuff.h +++ b/test/test_stuff.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "../components/samsung_ac/util.h" #include "../components/samsung_ac/protocol.h"