ESPHome  2024.11.1
airthings_wave_mini.cpp
Go to the documentation of this file.
1 #include "airthings_wave_mini.h"
2 
3 #ifdef USE_ESP32
4 
5 namespace esphome {
6 namespace airthings_wave_mini {
7 
8 static const char *const TAG = "airthings_wave_mini";
9 
10 void AirthingsWaveMini::read_sensors(uint8_t *raw_value, uint16_t value_len) {
11  auto *value = (WaveMiniReadings *) raw_value;
12 
13  if (sizeof(WaveMiniReadings) <= value_len) {
14  if (this->humidity_sensor_ != nullptr) {
15  this->humidity_sensor_->publish_state(value->humidity / 100.0f);
16  }
17 
18  if (this->pressure_sensor_ != nullptr) {
19  this->pressure_sensor_->publish_state(value->pressure / 50.0f);
20  }
21 
22  if (this->temperature_sensor_ != nullptr) {
23  this->temperature_sensor_->publish_state(value->temperature / 100.0f - 273.15f);
24  }
25 
26  if ((this->tvoc_sensor_ != nullptr) && this->is_valid_voc_value_(value->voc)) {
27  this->tvoc_sensor_->publish_state(value->voc);
28  }
29  }
30 
31  this->response_received_();
32 }
33 
35  // these really don't belong here, but there doesn't seem to be a
36  // practical way to have the base class use LOG_SENSOR and include
37  // the TAG from this component
38  LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
39  LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
40  LOG_SENSOR(" ", "Pressure", this->pressure_sensor_);
41  LOG_SENSOR(" ", "TVOC", this->tvoc_sensor_);
42  LOG_SENSOR(" ", "Battery Voltage", this->battery_voltage_);
43 }
44 
46  this->service_uuid_ = espbt::ESPBTUUID::from_raw(SERVICE_UUID);
49  espbt::ESPBTUUID::from_raw(ACCESS_CONTROL_POINT_CHARACTERISTIC_UUID);
50 }
51 
52 } // namespace airthings_wave_mini
53 } // namespace esphome
54 
55 #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