-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_cgAnem.h
47 lines (39 loc) · 1.35 KB
/
_cgAnem.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
#include "esphome.h"
#include "cgAnem.h"
#define SECONDS_PER_INTERVAL 5
#define AREA 100
#ifdef ANEM_I2C_ADDR
#undef ANEM_I2C_ADDR
#define ANEM_I2C_ADDR 0x11
#endif
using namespace esphome;
class MyCgAnem: public PollingComponent, public CustomAPIDevice {
public: Sensor * Temperature_Sensor = new Sensor();
Sensor * AirFlowRate_Sensor = new Sensor();
Sensor * AirConsumption_Sensor = new Sensor();
Sensor * Duct_Area_Sensor = new Sensor();
Sensor * MaxAirFlowRate_Sensor = new Sensor();
Sensor * MinAirFlowRate_Sensor = new Sensor();
CG_Anem myself {
ANEM_I2C_ADDR
};
MyCgAnem(): PollingComponent(SECONDS_PER_INTERVAL * 1000) {}
void setup() override {
myself.init();
myself.set_duct_area(AREA);
}
void update() override {
float Temperature = myself.getTemperature();
float AirFlowRate = myself.getAirflowRate();
float AirConsumption = myself.calculateAirConsumption();
float MaxAirFlowRate = myself.getMaxAirFlowRate();
float MinAirFlowRate = myself.getMinAirFlowRate();
if (myself.data_update()) {
Temperature_Sensor -> publish_state(Temperature);
AirFlowRate_Sensor -> publish_state(AirFlowRate);
AirConsumption_Sensor -> publish_state(AirConsumption);
MaxAirFlowRate_Sensor -> publish_state(MaxAirFlowRate);
MinAirFlowRate_Sensor -> publish_state(MinAirFlowRate);
}
}
};