mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 07:08:20 +00:00
Flattened config.
This commit is contained in:
parent
4ac8ec255e
commit
8a90a72a34
@ -6,18 +6,16 @@ from esphome.const import CONF_ID, CONF_TEMPERATURE, ICON_THERMOMETER, UNIT_CELS
|
|||||||
DEPENDENCIES = ['i2c']
|
DEPENDENCIES = ['i2c']
|
||||||
|
|
||||||
sts3x_ns = cg.esphome_ns.namespace('sts3x')
|
sts3x_ns = cg.esphome_ns.namespace('sts3x')
|
||||||
STS3XComponent = sts3x_ns.class_('STS3XComponent', cg.PollingComponent, i2c.I2CDevice)
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.Schema({
|
STS3XComponent = sts3x_ns.class_('STS3XComponent', sensor.Sensor, cg.PollingComponent, i2c.I2CDevice)
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = sensor.sensor_schema(CONF_TEMPERATURE, ICON_THERMOMETER, 1).extend({
|
||||||
cv.GenerateID(): cv.declare_id(STS3XComponent),
|
cv.GenerateID(): cv.declare_id(STS3XComponent),
|
||||||
cv.Required(CONF_TEMPERATURE): sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 1),
|
|
||||||
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x4A))
|
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x4A))
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
yield cg.register_component(var, config)
|
yield cg.register_component(var, config)
|
||||||
|
yield sensor.register_sensor(var, config)
|
||||||
yield i2c.register_i2c_device(var, config)
|
yield i2c.register_i2c_device(var, config)
|
||||||
sens = yield sensor.new_sensor(config[CONF_TEMPERATURE])
|
|
||||||
|
|
||||||
cg.add(var.set_temperature_sensor(sens))
|
|
||||||
|
@ -38,7 +38,7 @@ void STS3XComponent::dump_config() {
|
|||||||
}
|
}
|
||||||
LOG_UPDATE_INTERVAL(this);
|
LOG_UPDATE_INTERVAL(this);
|
||||||
|
|
||||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
LOG_SENSOR(" ", "STS3x", this);
|
||||||
}
|
}
|
||||||
float STS3XComponent::get_setup_priority() const { return setup_priority::DATA; }
|
float STS3XComponent::get_setup_priority() const { return setup_priority::DATA; }
|
||||||
void STS3XComponent::update() {
|
void STS3XComponent::update() {
|
||||||
@ -59,10 +59,8 @@ void STS3XComponent::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float temperature = 175.0f * float(raw_data[0]) / 65535.0f - 45.0f;
|
float temperature = 175.0f * float(raw_data[0]) / 65535.0f - 45.0f;
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Got temperature=%.2f°C", temperature);
|
ESP_LOGD(TAG, "Got temperature=%.2f°C", temperature);
|
||||||
if (this->temperature_sensor_ != nullptr)
|
this->publish_state(temperature);
|
||||||
this->temperature_sensor_->publish_state(temperature);
|
|
||||||
this->status_clear_warning();
|
this->status_clear_warning();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,8 @@ namespace esphome {
|
|||||||
namespace sts3x {
|
namespace sts3x {
|
||||||
|
|
||||||
/// This class implements support for the ST3x-DIS family of temperature i2c sensors.
|
/// This class implements support for the ST3x-DIS family of temperature i2c sensors.
|
||||||
class STS3XComponent : public PollingComponent, public i2c::I2CDevice {
|
class STS3XComponent : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice {
|
||||||
public:
|
public:
|
||||||
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
|
|
||||||
|
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
@ -21,7 +20,6 @@ class STS3XComponent : public PollingComponent, public i2c::I2CDevice {
|
|||||||
bool write_command_(uint16_t command);
|
bool write_command_(uint16_t command);
|
||||||
bool read_data_(uint16_t *data, uint8_t len);
|
bool read_data_(uint16_t *data, uint8_t len);
|
||||||
|
|
||||||
sensor::Sensor *temperature_sensor_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sts3x
|
} // namespace sts3x
|
||||||
|
@ -503,8 +503,7 @@ sensor:
|
|||||||
address: 0x44
|
address: 0x44
|
||||||
update_interval: 15s
|
update_interval: 15s
|
||||||
- platform: sts3x
|
- platform: sts3x
|
||||||
temperature:
|
name: "Living Room Temperature 9"
|
||||||
name: "Living Room Temperature 9"
|
|
||||||
address: 0x4A
|
address: 0x4A
|
||||||
update_interval: 15s
|
update_interval: 15s
|
||||||
- platform: template
|
- platform: template
|
||||||
|
Loading…
x
Reference in New Issue
Block a user