esphome/esphomeyaml/components/sensor/max6675.py

39 lines
1.4 KiB
Python
Raw Normal View History

2018-05-20 12:41:52 +02:00
import voluptuous as vol
import esphomeyaml.config_validation as cv
from esphomeyaml import pins
from esphomeyaml.components import sensor
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN_CLOCK, CONF_PIN_CS, CONF_PIN_MISO, \
CONF_UPDATE_INTERVAL
from esphomeyaml.helpers import App, Application, gpio_input_pin_expression, \
gpio_output_pin_expression, variable
2018-06-02 22:22:20 +02:00
MakeMAX6675Sensor = Application.MakeMAX6675Sensor
PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
2018-06-02 22:22:20 +02:00
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeMAX6675Sensor),
2018-06-06 08:55:53 +02:00
vol.Required(CONF_PIN_CS): pins.gpio_output_pin_schema,
vol.Required(CONF_PIN_CLOCK): pins.gpio_output_pin_schema,
vol.Required(CONF_PIN_MISO): pins.gpio_input_pin_schema,
2018-05-20 12:41:52 +02:00
vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds,
}))
2018-05-20 12:41:52 +02:00
def to_code(config):
2018-06-02 22:22:20 +02:00
pin_cs = None
for pin_cs in gpio_output_pin_expression(config[CONF_PIN_CS]):
yield
pin_clock = None
for pin_clock in gpio_output_pin_expression(config[CONF_PIN_CLOCK]):
yield
pin_miso = None
for pin_miso in gpio_input_pin_expression(config[CONF_PIN_MISO]):
yield
2018-05-20 12:41:52 +02:00
rhs = App.make_max6675_sensor(config[CONF_NAME], pin_cs, pin_clock, pin_miso,
config.get(CONF_UPDATE_INTERVAL))
2018-06-02 22:22:20 +02:00
make = variable(config[CONF_MAKE_ID], rhs)
2018-06-03 07:11:11 +02:00
sensor.setup_sensor(make.Pmax6675, make.Pmqtt, config)
2018-05-20 12:41:52 +02:00
BUILD_FLAGS = '-DUSE_MAX6675_SENSOR'