esphome/esphomeyaml/components/sensor/sht3xd.py

39 lines
1.6 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
2018-06-07 17:04:33 +02:00
from esphomeyaml.helpers import App, Application, variable
2018-05-14 21:13:51 +02:00
DEPENDENCIES = ['i2c']
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),
vol.Required(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA),
vol.Required(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA),
2018-05-14 21:13:51 +02:00
vol.Optional(CONF_ADDRESS, default=0x44): cv.i2c_address,
vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds,
2018-06-07 11:27:04 +02:00
vol.Optional(CONF_ACCURACY): cv.invalid("The accuracy option has been removed and now "
"defaults to HIGH."),
2018-05-14 21:13:51 +02:00
})
def to_code(config):
rhs = App.make_sht3xd_sensor(config[CONF_TEMPERATURE][CONF_NAME],
config[CONF_HUMIDITY][CONF_NAME],
2018-06-06 09:06:14 +02:00
config[CONF_ADDRESS],
2018-05-14 21:13:51 +02:00
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
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'