ESPHome  2024.10.2
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  if (this->humidity_sensor_ != nullptr) {
18  this->humidity_sensor_->publish_state(value->humidity / 2.0f);
19  }
20 
21  if ((this->radon_sensor_ != nullptr) && this->is_valid_radon_value_(value->radon)) {
22  this->radon_sensor_->publish_state(value->radon);
23  }
24 
25  if ((this->radon_long_term_sensor_ != nullptr) && this->is_valid_radon_value_(value->radon_lt)) {
26  this->radon_long_term_sensor_->publish_state(value->radon_lt);
27  }
28 
29  if (this->temperature_sensor_ != nullptr) {
30  this->temperature_sensor_->publish_state(value->temperature / 100.0f);
31  }
32 
33  if (this->pressure_sensor_ != nullptr) {
34  this->pressure_sensor_->publish_state(value->pressure / 50.0f);
35  }
36 
37  if ((this->co2_sensor_ != nullptr) && this->is_valid_co2_value_(value->co2)) {
38  this->co2_sensor_->publish_state(value->co2);
39  }
40 
41  if ((this->tvoc_sensor_ != nullptr) && this->is_valid_voc_value_(value->voc)) {
42  this->tvoc_sensor_->publish_state(value->voc);
43  }
44 
45  if (this->illuminance_sensor_ != nullptr) {
46  this->illuminance_sensor_->publish_state(value->ambientLight);
47  }
48  } else {
49  ESP_LOGE(TAG, "Invalid payload version (%d != 1, newer version or not a Wave Plus?)", value->version);
50  }
51  }
52 
53  this->response_received_();
54 }
55 
56 bool AirthingsWavePlus::is_valid_radon_value_(uint16_t radon) { return radon <= 16383; }
57 
58 bool AirthingsWavePlus::is_valid_co2_value_(uint16_t co2) { return co2 <= 16383; }
59 
61  // these really don't belong here, but there doesn't seem to be a
62  // practical way to have the base class use LOG_SENSOR and include
63  // the TAG from this component
64  LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
65  LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
66  LOG_SENSOR(" ", "Pressure", this->pressure_sensor_);
67  LOG_SENSOR(" ", "TVOC", this->tvoc_sensor_);
68  LOG_SENSOR(" ", "Battery Voltage", this->battery_voltage_);
69 
70  LOG_SENSOR(" ", "Radon", this->radon_sensor_);
71  LOG_SENSOR(" ", "Radon Long Term", this->radon_long_term_sensor_);
72  LOG_SENSOR(" ", "CO2", this->co2_sensor_);
73  LOG_SENSOR(" ", "Illuminance", this->illuminance_sensor_);
74 }
75 
77  this->service_uuid_ = espbt::ESPBTUUID::from_raw(SERVICE_UUID);
80  espbt::ESPBTUUID::from_raw(ACCESS_CONTROL_POINT_CHARACTERISTIC_UUID);
81 }
82 
83 } // namespace airthings_wave_plus
84 } // namespace esphome
85 
86 #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
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
static ESPBTUUID from_raw(const uint8_t *data)
Definition: ble_uuid.cpp:28