-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathenergy_statistics.h
65 lines (50 loc) · 1.79 KB
/
energy_statistics.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
60
61
62
63
64
65
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/preferences.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/time/real_time_clock.h"
namespace esphome {
namespace energy_statistics {
using sensor::Sensor;
class EnergyStatistics : public Component {
public:
float get_setup_priority() const override { return setup_priority::DATA; }
void dump_config() override;
void setup() override;
void loop() override;
void set_time(time::RealTimeClock *time) { this->time_ = time; }
void set_total(Sensor *sensor) { this->total_ = sensor; }
void set_energy_today(Sensor *sensor) { this->energy_today_ = sensor; }
void set_energy_yesterday(Sensor *sensor) { this->energy_yesterday_ = sensor; }
void set_energy_week(Sensor *sensor) { this->energy_week_ = sensor; }
void set_energy_month(Sensor *sensor) { this->energy_month_ = sensor; }
void set_energy_year(Sensor *sensor) { this->energy_year_ = sensor; }
protected:
ESPPreferenceObject pref_;
time::RealTimeClock *time_;
// input sensors
Sensor *total_{nullptr};
// exposed sensors
Sensor *energy_today_{nullptr};
Sensor *energy_yesterday_{nullptr};
Sensor *energy_week_{nullptr};
Sensor *energy_month_{nullptr};
Sensor *energy_year_{nullptr};
// start day of week configuration
int energy_week_start_day_{2};
// start day of month configuration
int energy_month_start_day_{1};
struct energy_data_v1_t {
uint16_t current_day_of_year{0};
float start_today{NAN};
float start_yesterday{NAN};
float start_week{NAN};
float start_month{NAN};
};
struct energy_data_t : public energy_data_v1_t {
float start_year{NAN};
} energy_;
void process_(float total);
}; // class EnergyStatistics
} // namespace energy_statistics
} // namespace esphome