esphome/esphomeyaml/components/sensor/sht3xd.py

45 lines
1.7 KiB
Python
Raw Normal View History

2018-05-14 21:13:51 +02:00
import voluptuous as vol
import esphomeyaml.config_validation as cv
from esphomeyaml.components import sensor
2018-05-20 12:41:52 +02:00
from esphomeyaml.const import CONF_ACCURACY, CONF_ADDRESS, CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, \
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
from esphomeyaml.helpers import App, Application, add, variable
2018-05-14 21:13:51 +02:00
DEPENDENCIES = ['i2c']
SHT_ACCURACIES = {
2018-05-20 12:41:52 +02:00
'LOW': sensor.sensor_ns.SHT3XD_ACCURACY_LOW,
'MEDIUM': sensor.sensor_ns.SHT3XD_ACCURACY_MEDIUM,
'HIGH': sensor.sensor_ns.SHT3XD_ACCURACY_HIGH,
2018-05-14 21:13:51 +02:00
}
2018-06-02 22:22:20 +02:00
MakeSHT3XDSensor = Application.MakeSHT3XDSensor
2018-05-14 21:13:51 +02:00
PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
2018-06-02 22:22:20 +02:00
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeSHT3XDSensor),
2018-05-20 12:41:52 +02:00
vol.Required(CONF_TEMPERATURE): sensor.SENSOR_SCHEMA,
vol.Required(CONF_HUMIDITY): sensor.SENSOR_SCHEMA,
2018-05-14 21:13:51 +02:00
vol.Optional(CONF_ADDRESS, default=0x44): cv.i2c_address,
2018-05-20 12:41:52 +02:00
vol.Optional(CONF_ACCURACY): vol.All(vol.Upper, cv.one_of(*SHT_ACCURACIES)),
2018-05-14 21:13:51 +02:00
vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds,
})
def to_code(config):
rhs = App.make_sht3xd_sensor(config[CONF_TEMPERATURE][CONF_NAME],
config[CONF_HUMIDITY][CONF_NAME],
config.get(CONF_UPDATE_INTERVAL))
2018-06-02 22:22:20 +02:00
sht3xd = variable(config[CONF_MAKE_ID], rhs)
2018-05-14 21:13:51 +02:00
if CONF_ACCURACY in config:
2018-05-20 12:41:52 +02:00
add(sht3xd.Psht3xd.set_accuracy(SHT_ACCURACIES[config[CONF_ACCURACY]]))
2018-05-14 21:13:51 +02:00
2018-06-03 07:11:11 +02:00
sensor.setup_sensor(sht3xd.Psht3xd.Pget_temperature_sensor(), sht3xd.Pmqtt_temperature,
config[CONF_TEMPERATURE])
sensor.setup_sensor(sht3xd.Psht3xd.Pget_humidity_sensor(), sht3xd.Pmqtt_humidity,
config[CONF_HUMIDITY])
2018-05-14 21:13:51 +02:00
BUILD_FLAGS = '-DUSE_SHT3XD'