1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-04 04:12:23 +01:00

Allow id() syntax for custom code (#621)

* Allow id() syntax for custom code

* Lint
This commit is contained in:
Otto Winter
2019-06-07 14:26:17 +02:00
committed by GitHub
parent 726b0e73d9
commit 4fe0c95ccb
4 changed files with 20 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/core/helpers.h"
namespace esphome {
namespace globals {
@@ -64,5 +65,7 @@ template<class C, typename... Ts> class GlobalVarSetAction : public Action<Ts...
C *parent_;
};
template<typename T> T &id(GlobalsComponent<T> *value) { return value->value(); }
} // namespace globals
} // namespace esphome

View File

@@ -4,6 +4,7 @@
#include <functional>
#include <vector>
#include <memory>
#include <type_traits>
#include "esphome/core/optional.h"
#include "esphome/core/esphal.h"
@@ -160,6 +161,11 @@ template<int...> struct seq {}; // NOLINT
template<int N, int... S> struct gens : gens<N - 1, N - 1, S...> {}; // NOLINT
template<int... S> struct gens<0, S...> { using type = seq<S...>; }; // NOLINT
template<bool B, class T = void> using enable_if_t = typename std::enable_if<B, T>::type;
template<typename T, enable_if_t<!std::is_pointer<T>::value, int> = 0> T id(T value) { return value; }
template<typename T, enable_if_t<std::is_pointer<T *>::value, int> = 0> T &id(T *value) { return *value; }
template<typename... X> class CallbackManager;
/** Simple helper class to allow having multiple subscribers to a signal.
@@ -192,8 +198,6 @@ struct is_callable // NOLINT
static constexpr auto value = decltype(test<T>(nullptr))::value; // NOLINT
};
template<bool B, class T = void> using enable_if_t = typename std::enable_if<B, T>::type;
template<typename T, typename... X> class TemplatableValue {
public:
TemplatableValue() : type_(EMPTY) {}