Skip to content

Commit

Permalink
use esphome optioanl and fake it for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed Feb 7, 2024
1 parent 3bcd080 commit b7d1678
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
5 changes: 3 additions & 2 deletions components/samsung_ac/protocol.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "esphome/core/optional.h"
#include "util.h"

namespace esphome
Expand Down Expand Up @@ -79,8 +80,8 @@ namespace esphome
class ProtocolRequest
{
public:
opt<bool> power;
opt<Mode> mode;
optional<bool> power;
optional<Mode> mode;
};

class Protocol
Expand Down
8 changes: 0 additions & 8 deletions components/samsung_ac/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <bitset>
#include <optional>
#include <functional>
#include <experimental/optional>

namespace esphome
{
Expand All @@ -19,12 +18,5 @@ namespace esphome
std::string bytes_to_hex(const std::vector<uint8_t> &data);
std::vector<uint8_t> 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 <typename T>
using opt = std::experimental::optional<T>;
using opt_null_t = std::experimental::nullopt_t;
constexpr auto nullopt = std::experimental::nullopt;

} // namespace samsung_ac
} // namespace esphome
13 changes: 13 additions & 0 deletions test/esphome/core/optional.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <experimental/optional>

// Fakes the esphome optional type with std experimental/optional

namespace esphome
{
template <typename T>
using optional = std::experimental::optional<T>;
/* using opt_null_t = std::experimental::nullopt_t;
constexpr auto nullopt = std::experimental::nullopt;*/
}
1 change: 1 addition & 0 deletions test/test_stuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <bitset>
#include <cassert>
#include <optional>
#include <experimental/optional>

#include "../components/samsung_ac/util.h"
#include "../components/samsung_ac/protocol.h"
Expand Down

0 comments on commit b7d1678

Please sign in to comment.