ESPHome  2024.5.4
airthings_wave_plus.cpp
Go to the documentation of this file.
1 #include "airthings_wave_plus.h"
2 
3 #ifdef USE_ESP32
4 
5 namespace esphome {
6 namespace airthings_wave_plus {
7 
8 static const char *const TAG = "airthings_wave_plus";
9 
10 void AirthingsWavePlus::read_sensors(uint8_t *raw_value, uint16_t value_len) {
11  auto *value = (WavePlusReadings *) raw_value;
12 
13  if (sizeof(WavePlusReadings) <= value_len) {
14  ESP_LOGD(TAG, "version = %d", value->version);
15 
16  if (value->version == 1) {
17  ESP_LOGD(TAG, "ambient light = %d", value->ambientLight);
18 
19  if (this->humidity_sensor_ != nullptr) {
20  this->humidity_sensor_->publish_state(value->humidity / 2.0f);
21  }
22 
23  if ((this->radon_sensor_ != nullptr) && this->is_valid_radon_value_(value->radon)) {
24  this->radon_sensor_->publish_state(value->radon);
25  }
26 
27  if ((this->radon_long_term_sensor_ != nullptr) && this->is_valid_radon_value_(value->radon_lt)) {
28  this->radon_long_term_sensor_->publish_state(value->radon_lt);
29  }
30 
31  if (this->temperature_sensor_ != nullptr) {
32  this->temperature_sensor_->publish_state(value->temperature / 100.0f);
33  }
34 
35  if (this->pressure_sensor_ != nullptr) {
36  this->pressure_sensor_->publish_state(value->pressure / 50.0f);
37  }
38 
39  if ((this->co2_sensor_ != nullptr) && this->is_valid_co2_value_(value->co2)) {
40  this->co2_sensor_->publish_state(value->co2);
41  }
42 
43  if ((this->tvoc_sensor_ != nullptr) && this->is_valid_voc_value_(value->voc)) {
44  this->tvoc_sensor_->publish_state(value->voc);
45  }
46  } else {
47  ESP_LOGE(TAG, "Invalid payload version (%d != 1, newer version or not a Wave Plus?)", value->version);
48  }
49  }
50 
51  this->response_received_();
52 }
53 
54 bool AirthingsWavePlus::is_valid_radon_value_(uint16_t radon) { return radon <= 16383; }
55 
56 bool AirthingsWavePlus::is_valid_co2_value_(uint16_t co2) { return co2 <= 16383; }
57 
59  // these really don't belong here, but there doesn't seem to be a
60  // practical way to have the base class use LOG_SENSOR and include
61  // the TAG from this component
62  LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
63  LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
64  LOG_SENSOR(" ", "Pressure", this->pressure_sensor_);
65  LOG_SENSOR(" ", "TVOC", this->tvoc_sensor_);
66  LOG_SENSOR(" ", "Battery Voltage", this->battery_voltage_);
67 
68  LOG_SENSOR(" ", "Radon", this->radon_sensor_);
69  LOG_SENSOR(" ", "Radon Long Term", this->radon_long_term_sensor_);
70  LOG_SENSOR(" ", "CO2", this->co2_sensor_);
71 }
72 
74  this->service_uuid_ = espbt::ESPBTUUID::from_raw(SERVICE_UUID);
77  espbt::ESPBTUUID::from_raw(ACCESS_CONTROL_POINT_CHARACTERISTIC_UUID);
78 }
79 
80 } // namespace airthings_wave_plus
81 } // namespace esphome
82 
83 #endif // USE_ESP32
void read_sensors(uint8_t *raw_value, uint16_t value_len) override
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
static ESPBTUUID from_raw(const uint8_t *data)
Definition: ble_uuid.cpp:28