Change files, folders and namespace to include 'i2c'

This commit is contained in:
thetestspecimen 2024-10-10 11:59:54 +03:00
parent e624c7e275
commit 4c28ec09e3
No known key found for this signature in database
GPG Key ID: C88001C355A25170
4 changed files with 20 additions and 20 deletions

View File

@ -1,11 +1,11 @@
#include "sen0501.h"
#include "sen0501_i2c.h"
#include "esphome/core/log.h"
#include "esphome/core/hal.h"
namespace esphome {
namespace sen0501 {
namespace sen0501_i2c {
static const char *const TAG = "sen0501";
static const char *const TAG = "sen0501_i2c";
// Device Address
static const uint8_t SEN050X_DEFAULT_DEVICE_ADDRESS = 0x22;
@ -29,7 +29,7 @@ static const uint16_t REG_ATMOSPHERIC_PRESSURE = 0x0018;
// PUBLIC
void Sen0501Component::setup() {
void Sen0501_i2cComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up sen0501...");
uint8_t product_id_first_byte;
if (!this->read_byte(REG_PID, &product_id_first_byte)) {
@ -55,7 +55,7 @@ void Sen0501Component::setup() {
}
}
void Sen0501Component::update() {
void Sen0501_i2cComponent::update() {
this->read_temperature_();
this->read_humidity_();
this->read_uv_intensity_();
@ -63,7 +63,7 @@ void Sen0501Component::update() {
this->read_atmospheric_pressure_();
}
void Sen0501Component::dump_config() {
void Sen0501_i2cComponent::dump_config() {
ESP_LOGCONFIG(TAG, "DFRobot Environmental Sensor - sen0501:");
LOG_I2C_DEVICE(this);
switch (this->error_code_) {
@ -89,11 +89,11 @@ void Sen0501Component::dump_config() {
LOG_SENSOR(" ", "Elevation", this->elevation_);
}
float Sen0501Component::get_setup_priority() const { return setup_priority::DATA; }
float Sen0501_i2cComponent::get_setup_priority() const { return setup_priority::DATA; }
// PROTECTED
void Sen0501Component::read_temperature_() {
void Sen0501_i2cComponent::read_temperature_() {
if (this->temperature_ == nullptr)
return;
uint8_t buffer[2];
@ -104,7 +104,7 @@ void Sen0501Component::read_temperature_() {
this->temperature_->publish_state(temp);
}
void Sen0501Component::read_humidity_() {
void Sen0501_i2cComponent::read_humidity_() {
if (this->humidity_ == nullptr)
return;
uint8_t buffer[2];
@ -115,7 +115,7 @@ void Sen0501Component::read_humidity_() {
this->humidity_->publish_state(humidity);
}
void Sen0501Component::read_uv_intensity_() {
void Sen0501_i2cComponent::read_uv_intensity_() {
if (this->uv_intensity_ == nullptr)
return;
uint8_t buffer[2];
@ -141,7 +141,7 @@ void Sen0501Component::read_uv_intensity_() {
this->uv_intensity_->publish_state(ultra_violet);
}
void Sen0501Component::read_luminous_intensity_() {
void Sen0501_i2cComponent::read_luminous_intensity_() {
if (this->luminous_intensity_ == nullptr)
return;
uint8_t buffer[2];
@ -152,7 +152,7 @@ void Sen0501Component::read_luminous_intensity_() {
this->luminous_intensity_->publish_state(luminous);
}
void Sen0501Component::read_atmospheric_pressure_() {
void Sen0501_i2cComponent::read_atmospheric_pressure_() {
if (this->atmospheric_pressure_ == nullptr && this->elevation_ == nullptr)
return;
uint8_t buffer[2];
@ -166,5 +166,5 @@ void Sen0501Component::read_atmospheric_pressure_() {
}
}
} // namespace sen0501
} // namespace sen0501_i2c
} // namespace esphome

View File

@ -8,9 +8,9 @@
// https://github.com/DFRobot/DFRobot_EnvironmentalSensor
namespace esphome {
namespace sen0501 {
namespace sen0501_i2c {
class Sen0501Component : public PollingComponent, public i2c::I2CDevice {
class Sen0501_i2cComponent : public PollingComponent, public i2c::I2CDevice {
public:
void set_temperature(sensor::Sensor *temperature) { this->temperature_ = temperature; }
void set_humidity(sensor::Sensor *humidity) { this->humidity_ = humidity; }
@ -48,5 +48,5 @@ class Sen0501Component : public PollingComponent, public i2c::I2CDevice {
} error_code_{NONE};
};
} // namespace sen0501
} // namespace sen0501_i2c
} // namespace esphome

View File

@ -33,15 +33,15 @@ CONF_ELEVATION = "elevation"
DEPENDENCIES = ["i2c"]
sen0501_ns = cg.esphome_ns.namespace("sen0501")
Sen0501Component = sen0501_ns.class_(
"Sen0501Component", cg.PollingComponent, i2c.I2CDevice
sen0501_ns = cg.esphome_ns.namespace("sen0501_i2c")
Sen0501_i2cComponent = sen0501_ns.class_(
"Sen0501_i2cComponent", cg.PollingComponent, i2c.I2CDevice
)
CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(Sen0501Component),
cv.GenerateID(): cv.declare_id(Sen0501_i2cComponent),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
unit_of_measurement=UNIT_CELSIUS,
icon=ICON_THERMOMETER,