mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-21 05:23:27 +02:00
26dbc30279
* Add support for SGP30 eCO2 and TVOC sensors * Added test for SGP30 * Lint issues fixed * Lint fixes * Fixed light lengths * Cleanup * Add support for Sensirion SCD30 CO2 sensors * Fixed few lint issues * Lint fixes * Fixed line ending for lint * Cleanup * Refactored float conversion * Refactor unnecessary return * Refactoring and cleanup * Updated uptime_sensor_ referencing and simplified checking on availability of copensation * Temperature and Humidity source moved to a separate compensation block; Dependency for Uptime sensor removed. * Both humidity_source and temperature_source are now mandatory if the compensation block is defined; * Clean up * Cleanup * Cleanup in search of perfection * Use correct comment style Co-authored-by: Otto Winter <otto@otto-winter.com>
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import i2c, sensor
|
|
from esphome.const import CONF_ID, ICON_RADIATOR, UNIT_PARTS_PER_MILLION, \
|
|
UNIT_PARTS_PER_BILLION, ICON_PERIODIC_TABLE_CO2
|
|
|
|
DEPENDENCIES = ['i2c']
|
|
|
|
sgp30_ns = cg.esphome_ns.namespace('sgp30')
|
|
SGP30Component = sgp30_ns.class_('SGP30Component', cg.PollingComponent, i2c.I2CDevice)
|
|
|
|
CONF_ECO2 = 'eco2'
|
|
CONF_TVOC = 'tvoc'
|
|
CONF_BASELINE = 'baseline'
|
|
CONF_UPTIME = 'uptime'
|
|
CONF_COMPENSATION = 'compensation'
|
|
CONF_COMPENSATION_HUMIDITY = 'humidity_source'
|
|
CONF_COMPENSATION_TEMPERATURE = 'temperature_source'
|
|
|
|
CONFIG_SCHEMA = cv.Schema({
|
|
cv.GenerateID(): cv.declare_id(SGP30Component),
|
|
cv.Required(CONF_ECO2): sensor.sensor_schema(UNIT_PARTS_PER_MILLION,
|
|
ICON_PERIODIC_TABLE_CO2, 0),
|
|
cv.Required(CONF_TVOC): sensor.sensor_schema(UNIT_PARTS_PER_BILLION, ICON_RADIATOR, 0),
|
|
cv.Optional(CONF_BASELINE): cv.hex_uint16_t,
|
|
cv.Optional(CONF_COMPENSATION): cv.Schema({
|
|
cv.Required(CONF_COMPENSATION_HUMIDITY): cv.use_id(sensor.Sensor),
|
|
cv.Required(CONF_COMPENSATION_TEMPERATURE): cv.use_id(sensor.Sensor)
|
|
}),
|
|
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x58))
|
|
|
|
|
|
def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
yield cg.register_component(var, config)
|
|
yield i2c.register_i2c_device(var, config)
|
|
|
|
if CONF_ECO2 in config:
|
|
sens = yield sensor.new_sensor(config[CONF_ECO2])
|
|
cg.add(var.set_eco2_sensor(sens))
|
|
|
|
if CONF_TVOC in config:
|
|
sens = yield sensor.new_sensor(config[CONF_TVOC])
|
|
cg.add(var.set_tvoc_sensor(sens))
|
|
|
|
if CONF_BASELINE in config:
|
|
cg.add(var.set_baseline(config[CONF_BASELINE]))
|
|
|
|
if CONF_COMPENSATION in config:
|
|
compensation_config = config[CONF_COMPENSATION]
|
|
sens = yield cg.get_variable(compensation_config[CONF_COMPENSATION_HUMIDITY])
|
|
cg.add(var.set_humidity_sensor(sens))
|
|
sens = yield cg.get_variable(compensation_config[CONF_COMPENSATION_TEMPERATURE])
|
|
cg.add(var.set_temperature_sensor(sens))
|