ESPHome 2026.11.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
7ESPHOME_LOG_TAG(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(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
13 };
14}
15
17
19 ESP_LOGCONFIG(TAG, "DF Robot Ozone Sensor sen0321:");
20 LOG_I2C_DEVICE(this);
21 LOG_UPDATE_INTERVAL(this);
22}
23
25 uint8_t result[2];
26 this->read_bytes(SENSOR_AUTO_READ_REG, result, (uint8_t) 2);
27 this->publish_state(((uint16_t) (result[0] << 8) + result[1]));
28}
29
30} // namespace esphome::sen0321_sensor
void mark_failed()
Mark this component as failed.
bool write_byte(uint8_t a_register, uint8_t data) const
Definition i2c.h:312
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:249
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
ESPHOME_LOG_TAG(TAG, "sen0321_sensor.sensor")