-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
automation.h
59 lines (44 loc) · 1.41 KB
/
automation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/sensor/sensor.h"
#include "energy_tariffs.h"
namespace esphome {
namespace energy_tariffs {
using sensor::Sensor;
// TODO use Parented<EnergyStatistics>
class TariffChangeTrigger : public Trigger<Sensor *> {
public:
explicit TariffChangeTrigger(EnergyTariffs *parent) {
parent->add_on_tariff_callback([this](Sensor *value) { this->trigger(value); });
}
};
class BeforeTariffChangeTrigger : public Trigger<> {
public:
explicit BeforeTariffChangeTrigger(EnergyTariffs *parent) {
parent->add_on_before_tariff_callback([this] { this->trigger(); });
}
};
/*
template<typename... Ts> class TariffIsCondition : public Condition<Ts...>, public Parented<EnergyTariffs>{
public:
TariffIsCondition(EnergyStatistics *parent) : Parented(parent) {}
TEMPLATABLE_VALUE(EnergyTariff *, tariff)
bool check(Ts... x) override { return this->parent_->get_current_tariff() == this->tariff_.value(x...); }
};
*/
/*
template<typename... Ts> class TariffSetAction : public Action<Ts...> {
public:
explicit TariffSetAction(EnergyTariff *tariff) : tariff_(tariff) {}
TEMPLATABLE_VALUE(float, state)
void play(Ts... x) override {
auto v = this->state_.value(x...);
this->tariff_->publish_state(v);
}
protected:
EnergyTariff *tariff_;
};
*/
} // namespace energy_tariffs
} // namespace esphome