ESPHome  2024.11.2
ruuvitag.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #ifdef USE_ESP32
9 
10 namespace esphome {
11 namespace ruuvitag {
12 
14  public:
15  void set_address(uint64_t address) { address_ = address; }
16 
17  bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override {
18  if (device.address_uint64() != this->address_)
19  return false;
20 
21  auto res = ruuvi_ble::parse_ruuvi(device);
22  if (!res.has_value())
23  return false;
24 
25  if (res->humidity.has_value() && this->humidity_ != nullptr)
26  this->humidity_->publish_state(*res->humidity);
27  if (res->temperature.has_value() && this->temperature_ != nullptr)
28  this->temperature_->publish_state(*res->temperature);
29  if (res->pressure.has_value() && this->pressure_ != nullptr)
30  this->pressure_->publish_state(*res->pressure);
31  if (res->acceleration.has_value() && this->acceleration_ != nullptr)
32  this->acceleration_->publish_state(*res->acceleration);
33  if (res->acceleration_x.has_value() && this->acceleration_x_ != nullptr)
34  this->acceleration_x_->publish_state(*res->acceleration_x);
35  if (res->acceleration_y.has_value() && this->acceleration_y_ != nullptr)
36  this->acceleration_y_->publish_state(*res->acceleration_y);
37  if (res->acceleration_z.has_value() && this->acceleration_z_ != nullptr)
38  this->acceleration_z_->publish_state(*res->acceleration_z);
39  if (res->battery_voltage.has_value() && this->battery_voltage_ != nullptr)
40  this->battery_voltage_->publish_state(*res->battery_voltage);
41  if (res->tx_power.has_value() && this->tx_power_ != nullptr)
42  this->tx_power_->publish_state(*res->tx_power);
43  if (res->movement_counter.has_value() && this->movement_counter_ != nullptr)
44  this->movement_counter_->publish_state(*res->movement_counter);
45  if (res->measurement_sequence_number.has_value() && this->measurement_sequence_number_ != nullptr)
46  this->measurement_sequence_number_->publish_state(*res->measurement_sequence_number);
47  return true;
48  }
49 
50  void dump_config() override;
51  float get_setup_priority() const override { return setup_priority::DATA; }
52  void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; }
55  void set_acceleration(sensor::Sensor *acceleration) { acceleration_ = acceleration; }
56  void set_acceleration_x(sensor::Sensor *acceleration_x) { acceleration_x_ = acceleration_x; }
57  void set_acceleration_y(sensor::Sensor *acceleration_y) { acceleration_y_ = acceleration_y; }
58  void set_acceleration_z(sensor::Sensor *acceleration_z) { acceleration_z_ = acceleration_z; }
59  void set_battery_voltage(sensor::Sensor *battery_voltage) { battery_voltage_ = battery_voltage; }
60  void set_tx_power(sensor::Sensor *tx_power) { tx_power_ = tx_power; }
61  void set_movement_counter(sensor::Sensor *movement_counter) { movement_counter_ = movement_counter; }
62  void set_measurement_sequence_number(sensor::Sensor *measurement_sequence_number) {
63  measurement_sequence_number_ = measurement_sequence_number;
64  }
65 
66  protected:
67  uint64_t address_;
79 };
80 
81 } // namespace ruuvitag
82 } // namespace esphome
83 
84 #endif
void set_temperature(sensor::Sensor *temperature)
Definition: ruuvitag.h:53
sensor::Sensor * acceleration_y_
Definition: ruuvitag.h:73
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void set_address(uint64_t address)
Definition: ruuvitag.h:15
uint8_t pressure
Definition: tt21100.cpp:19
sensor::Sensor * measurement_sequence_number_
Definition: ruuvitag.h:78
sensor::Sensor * acceleration_
Definition: ruuvitag.h:71
void set_humidity(sensor::Sensor *humidity)
Definition: ruuvitag.h:52
void set_acceleration_x(sensor::Sensor *acceleration_x)
Definition: ruuvitag.h:56
void set_acceleration(sensor::Sensor *acceleration)
Definition: ruuvitag.h:55
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
Definition: ruuvitag.h:17
uint16_t temperature
Definition: sun_gtil2.cpp:26
float get_setup_priority() const override
Definition: ruuvitag.h:51
void set_battery_voltage(sensor::Sensor *battery_voltage)
Definition: ruuvitag.h:59
void set_measurement_sequence_number(sensor::Sensor *measurement_sequence_number)
Definition: ruuvitag.h:62
optional< RuuviParseResult > parse_ruuvi(const esp32_ble_tracker::ESPBTDevice &device)
Definition: ruuvi_ble.cpp:81
sensor::Sensor * battery_voltage_
Definition: ruuvitag.h:75
void set_movement_counter(sensor::Sensor *movement_counter)
Definition: ruuvitag.h:61
sensor::Sensor * tx_power_
Definition: ruuvitag.h:76
void set_pressure(sensor::Sensor *pressure)
Definition: ruuvitag.h:54
sensor::Sensor * acceleration_x_
Definition: ruuvitag.h:72
void dump_config() override
Definition: ruuvitag.cpp:11
sensor::Sensor * humidity_
Definition: ruuvitag.h:69
void set_acceleration_y(sensor::Sensor *acceleration_y)
Definition: ruuvitag.h:57
sensor::Sensor * temperature_
Definition: ruuvitag.h:68
sensor::Sensor * movement_counter_
Definition: ruuvitag.h:77
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
uint8_t address
Definition: bl0906.h:211
void set_tx_power(sensor::Sensor *tx_power)
Definition: ruuvitag.h:60
void set_acceleration_z(sensor::Sensor *acceleration_z)
Definition: ruuvitag.h:58
Base-class for all sensors.
Definition: sensor.h:57
sensor::Sensor * pressure_
Definition: ruuvitag.h:70
sensor::Sensor * acceleration_z_
Definition: ruuvitag.h:74