ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
sen0321.cpp
Go to the documentation of this file.
1#include "sen0321.h"
2#include "esphome/core/log.h"
3#include "esphome/core/hal.h"
4
6
7static const char *const TAG = "sen0321_sensor.sensor";
8
10 if (!this->write_byte(SENSOR_MODE_REGISTER, SENSOR_MODE_AUTO)) {
11 ESP_LOGW(TAG, "Error setting measurement mode.");
12 this->mark_failed();
13 };
14}
15
17
19 ESP_LOGCONFIG(TAG, "DF Robot Ozone Sensor sen0321:");
20 LOG_I2C_DEVICE(this);
21 if (this->is_failed()) {
22 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
23 }
24 LOG_UPDATE_INTERVAL(this);
25}
26
28 uint8_t result[2];
29 this->read_bytes(SENSOR_AUTO_READ_REG, result, (uint8_t) 2);
30 this->publish_state(((uint16_t) (result[0] << 8) + result[1]));
31}
32
33} // namespace esphome::sen0321_sensor
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:272
bool write_byte(uint8_t a_register, uint8_t data) const
Definition i2c.h:265
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
Definition i2c.h:217
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68