mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 11:37:27 +01:00
add_job
This commit is contained in:
parent
4f3f460105
commit
967aa53bad
@ -13,7 +13,7 @@ from esphomeyaml.const import CONF_BAUD_RATE, CONF_DOMAIN, CONF_ESPHOMEYAML, CON
|
|||||||
CONF_LOGGER, CONF_MANUAL_IP, CONF_NAME, CONF_STATIC_IP, CONF_WIFI, ESP_PLATFORM_ESP8266
|
CONF_LOGGER, CONF_MANUAL_IP, CONF_NAME, CONF_STATIC_IP, CONF_WIFI, ESP_PLATFORM_ESP8266
|
||||||
from esphomeyaml.core import ESPHomeYAMLError
|
from esphomeyaml.core import ESPHomeYAMLError
|
||||||
from esphomeyaml.helpers import AssignmentExpression, Expression, RawStatement, _EXPRESSIONS, add, \
|
from esphomeyaml.helpers import AssignmentExpression, Expression, RawStatement, _EXPRESSIONS, add, \
|
||||||
add_task, color, flush_tasks, indent, quote, statement
|
add_job, color, flush_tasks, indent, quote, statement
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -113,24 +113,20 @@ def run_miniterm(config, port, escape=False):
|
|||||||
def write_cpp(config):
|
def write_cpp(config):
|
||||||
_LOGGER.info("Generating C++ source...")
|
_LOGGER.info("Generating C++ source...")
|
||||||
|
|
||||||
add_task(core_to_code, config[CONF_ESPHOMEYAML], 'esphomeyaml')
|
add_job(core_to_code, config[CONF_ESPHOMEYAML], domain='esphomeyaml')
|
||||||
for domain in PRE_INITIALIZE:
|
for domain in PRE_INITIALIZE:
|
||||||
if domain == CONF_ESPHOMEYAML:
|
if domain == CONF_ESPHOMEYAML or domain not in config:
|
||||||
continue
|
continue
|
||||||
if domain in config:
|
add_job(get_component(domain).to_code, config[domain], domain=domain)
|
||||||
add_task(get_component(domain).to_code, config[domain], domain)
|
|
||||||
|
|
||||||
for domain, component, conf in iter_components(config):
|
for domain, component, conf in iter_components(config):
|
||||||
if domain in PRE_INITIALIZE:
|
if domain in PRE_INITIALIZE or not hasattr(component, 'to_code'):
|
||||||
continue
|
continue
|
||||||
if not hasattr(component, 'to_code'):
|
add_job(component.to_code, conf, domain=domain)
|
||||||
continue
|
|
||||||
add_task(component.to_code, conf, domain)
|
|
||||||
|
|
||||||
flush_tasks()
|
flush_tasks()
|
||||||
add(RawStatement(''))
|
add(RawStatement(''))
|
||||||
add(RawStatement(''))
|
add(RawStatement(''))
|
||||||
|
|
||||||
all_code = []
|
all_code = []
|
||||||
for exp in _EXPRESSIONS:
|
for exp in _EXPRESSIONS:
|
||||||
if core.SIMPLIFY:
|
if core.SIMPLIFY:
|
||||||
|
@ -11,7 +11,7 @@ from esphomeyaml.const import CONF_ABOVE, CONF_ACTION_ID, CONF_AND, CONF_AUTOMAT
|
|||||||
from esphomeyaml.core import ESPHomeYAMLError
|
from esphomeyaml.core import ESPHomeYAMLError
|
||||||
from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, TemplateArguments, add, \
|
from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, TemplateArguments, add, \
|
||||||
bool_, esphomelib_ns, float_, get_variable, process_lambda, std_string, templatable, uint32, \
|
bool_, esphomelib_ns, float_, get_variable, process_lambda, std_string, templatable, uint32, \
|
||||||
uint8
|
uint8, add_job
|
||||||
|
|
||||||
CONF_MQTT_PUBLISH = 'mqtt.publish'
|
CONF_MQTT_PUBLISH = 'mqtt.publish'
|
||||||
CONF_LIGHT_TOGGLE = 'light.toggle'
|
CONF_LIGHT_TOGGLE = 'light.toggle'
|
||||||
@ -390,7 +390,7 @@ def build_actions(config, arg_type):
|
|||||||
yield ArrayInitializer(*actions)
|
yield ArrayInitializer(*actions)
|
||||||
|
|
||||||
|
|
||||||
def build_automation(trigger, arg_type, config):
|
def build_automation_(trigger, arg_type, config):
|
||||||
rhs = App.make_automation(trigger)
|
rhs = App.make_automation(trigger)
|
||||||
type = Automation.template(arg_type)
|
type = Automation.template(arg_type)
|
||||||
obj = Pvariable(config[CONF_AUTOMATION_ID], rhs, type=type)
|
obj = Pvariable(config[CONF_AUTOMATION_ID], rhs, type=type)
|
||||||
@ -403,3 +403,7 @@ def build_automation(trigger, arg_type, config):
|
|||||||
for actions in build_actions(config[CONF_THEN], arg_type):
|
for actions in build_actions(config[CONF_THEN], arg_type):
|
||||||
yield
|
yield
|
||||||
add(obj.add_actions(actions))
|
add(obj.add_actions(actions))
|
||||||
|
|
||||||
|
|
||||||
|
def build_automation(trigger, arg_type, config):
|
||||||
|
add_job(build_automation_, trigger, arg_type, config)
|
||||||
|
@ -5,7 +5,8 @@ from esphomeyaml import automation
|
|||||||
from esphomeyaml.const import CONF_DEVICE_CLASS, CONF_ID, CONF_INVERTED, CONF_MAX_LENGTH, \
|
from esphomeyaml.const import CONF_DEVICE_CLASS, CONF_ID, CONF_INVERTED, CONF_MAX_LENGTH, \
|
||||||
CONF_MIN_LENGTH, CONF_MQTT_ID, CONF_ON_CLICK, CONF_ON_DOUBLE_CLICK, CONF_ON_PRESS, \
|
CONF_MIN_LENGTH, CONF_MQTT_ID, CONF_ON_CLICK, CONF_ON_DOUBLE_CLICK, CONF_ON_PRESS, \
|
||||||
CONF_ON_RELEASE, CONF_TRIGGER_ID
|
CONF_ON_RELEASE, CONF_TRIGGER_ID
|
||||||
from esphomeyaml.helpers import App, NoArg, Pvariable, add, esphomelib_ns, setup_mqtt_component
|
from esphomeyaml.helpers import App, NoArg, Pvariable, add, esphomelib_ns, setup_mqtt_component, \
|
||||||
|
add_job
|
||||||
|
|
||||||
DEVICE_CLASSES = [
|
DEVICE_CLASSES = [
|
||||||
'', 'battery', 'cold', 'connectivity', 'door', 'garage_door', 'gas',
|
'', 'battery', 'cold', 'connectivity', 'door', 'garage_door', 'gas',
|
||||||
@ -60,27 +61,23 @@ def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config):
|
|||||||
for conf in config.get(CONF_ON_PRESS, []):
|
for conf in config.get(CONF_ON_PRESS, []):
|
||||||
rhs = binary_sensor_var.make_press_trigger()
|
rhs = binary_sensor_var.make_press_trigger()
|
||||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||||
for _ in automation.build_automation(trigger, NoArg, conf):
|
automation.build_automation(trigger, NoArg, conf)
|
||||||
yield
|
|
||||||
|
|
||||||
for conf in config.get(CONF_ON_RELEASE, []):
|
for conf in config.get(CONF_ON_RELEASE, []):
|
||||||
rhs = binary_sensor_var.make_release_trigger()
|
rhs = binary_sensor_var.make_release_trigger()
|
||||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||||
for _ in automation.build_automation(trigger, NoArg, conf):
|
automation.build_automation(trigger, NoArg, conf)
|
||||||
yield
|
|
||||||
|
|
||||||
for conf in config.get(CONF_ON_CLICK, []):
|
for conf in config.get(CONF_ON_CLICK, []):
|
||||||
rhs = binary_sensor_var.make_click_trigger(conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH])
|
rhs = binary_sensor_var.make_click_trigger(conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH])
|
||||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||||
for _ in automation.build_automation(trigger, NoArg, conf):
|
automation.build_automation(trigger, NoArg, conf)
|
||||||
yield
|
|
||||||
|
|
||||||
for conf in config.get(CONF_ON_DOUBLE_CLICK, []):
|
for conf in config.get(CONF_ON_DOUBLE_CLICK, []):
|
||||||
rhs = binary_sensor_var.make_double_click_trigger(conf[CONF_MIN_LENGTH],
|
rhs = binary_sensor_var.make_double_click_trigger(conf[CONF_MIN_LENGTH],
|
||||||
conf[CONF_MAX_LENGTH])
|
conf[CONF_MAX_LENGTH])
|
||||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||||
for _ in automation.build_automation(trigger, NoArg, conf):
|
automation.build_automation(trigger, NoArg, conf)
|
||||||
yield
|
|
||||||
|
|
||||||
setup_mqtt_component(mqtt_var, config)
|
setup_mqtt_component(mqtt_var, config)
|
||||||
|
|
||||||
@ -90,16 +87,14 @@ def setup_binary_sensor(binary_sensor_obj, mqtt_obj, config):
|
|||||||
has_side_effects=False)
|
has_side_effects=False)
|
||||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj,
|
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj,
|
||||||
has_side_effects=False)
|
has_side_effects=False)
|
||||||
for _ in setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config):
|
add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
def register_binary_sensor(var, config):
|
def register_binary_sensor(var, config):
|
||||||
binary_sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
binary_sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
||||||
rhs = App.register_binary_sensor(binary_sensor_var)
|
rhs = App.register_binary_sensor(binary_sensor_var)
|
||||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
|
mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
|
||||||
for _ in setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config):
|
add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_BINARY_SENSOR'
|
BUILD_FLAGS = '-DUSE_BINARY_SENSOR'
|
||||||
|
@ -42,8 +42,7 @@ def to_code(config):
|
|||||||
yield
|
yield
|
||||||
addr = [HexInt(i) for i in config[CONF_MAC_ADDRESS].parts]
|
addr = [HexInt(i) for i in config[CONF_MAC_ADDRESS].parts]
|
||||||
rhs = hub.make_device(config[CONF_NAME], ArrayInitializer(*addr, multiline=False))
|
rhs = hub.make_device(config[CONF_NAME], ArrayInitializer(*addr, multiline=False))
|
||||||
for _ in binary_sensor.register_binary_sensor(rhs, config):
|
binary_sensor.register_binary_sensor(rhs, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_ESP32_BLE_TRACKER'
|
BUILD_FLAGS = '-DUSE_ESP32_BLE_TRACKER'
|
||||||
|
@ -47,8 +47,7 @@ def to_code(config):
|
|||||||
yield
|
yield
|
||||||
touch_pad = TOUCH_PADS[config[CONF_PIN]]
|
touch_pad = TOUCH_PADS[config[CONF_PIN]]
|
||||||
rhs = hub.make_touch_pad(config[CONF_NAME], touch_pad, config[CONF_THRESHOLD])
|
rhs = hub.make_touch_pad(config[CONF_NAME], touch_pad, config[CONF_THRESHOLD])
|
||||||
for _ in binary_sensor.register_binary_sensor(rhs, config):
|
binary_sensor.register_binary_sensor(rhs, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_ESP32_TOUCH_BINARY_SENSOR'
|
BUILD_FLAGS = '-DUSE_ESP32_TOUCH_BINARY_SENSOR'
|
||||||
|
@ -20,8 +20,7 @@ def to_code(config):
|
|||||||
yield
|
yield
|
||||||
rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin)
|
rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin)
|
||||||
gpio = variable(config[CONF_MAKE_ID], rhs)
|
gpio = variable(config[CONF_MAKE_ID], rhs)
|
||||||
for _ in binary_sensor.setup_binary_sensor(gpio.Pgpio, gpio.Pmqtt, config):
|
binary_sensor.setup_binary_sensor(gpio.Pgpio, gpio.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_GPIO_BINARY_SENSOR'
|
BUILD_FLAGS = '-DUSE_GPIO_BINARY_SENSOR'
|
||||||
|
@ -15,8 +15,7 @@ PLATFORM_SCHEMA = binary_sensor.PLATFORM_SCHEMA.extend({
|
|||||||
def to_code(config):
|
def to_code(config):
|
||||||
rhs = App.make_status_binary_sensor(config[CONF_NAME])
|
rhs = App.make_status_binary_sensor(config[CONF_NAME])
|
||||||
status = variable(config[CONF_MAKE_ID], rhs)
|
status = variable(config[CONF_MAKE_ID], rhs)
|
||||||
for _ in binary_sensor.setup_binary_sensor(status.Pstatus, status.Pmqtt, config):
|
binary_sensor.setup_binary_sensor(status.Pstatus, status.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_STATUS_BINARY_SENSOR'
|
BUILD_FLAGS = '-DUSE_STATUS_BINARY_SENSOR'
|
||||||
|
@ -19,8 +19,7 @@ def to_code(config):
|
|||||||
yield
|
yield
|
||||||
rhs = App.make_template_binary_sensor(config[CONF_NAME], template_)
|
rhs = App.make_template_binary_sensor(config[CONF_NAME], template_)
|
||||||
make = variable(config[CONF_MAKE_ID], rhs)
|
make = variable(config[CONF_MAKE_ID], rhs)
|
||||||
for _ in binary_sensor.setup_binary_sensor(make.Ptemplate_, make.Pmqtt, config):
|
binary_sensor.setup_binary_sensor(make.Ptemplate_, make.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_TEMPLATE_BINARY_SENSOR'
|
BUILD_FLAGS = '-DUSE_TEMPLATE_BINARY_SENSOR'
|
||||||
|
@ -134,8 +134,7 @@ def to_code(config):
|
|||||||
for conf in config.get(CONF_ON_MESSAGE, []):
|
for conf in config.get(CONF_ON_MESSAGE, []):
|
||||||
rhs = mqtt.make_message_trigger(conf[CONF_TOPIC], conf[CONF_QOS])
|
rhs = mqtt.make_message_trigger(conf[CONF_TOPIC], conf[CONF_QOS])
|
||||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||||
for _ in automation.build_automation(trigger, std_string, conf):
|
automation.build_automation(trigger, std_string, conf)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
def required_build_flags(config):
|
def required_build_flags(config):
|
||||||
|
@ -9,7 +9,7 @@ from esphomeyaml.const import CONF_ABOVE, CONF_ACCURACY_DECIMALS, CONF_ALPHA, CO
|
|||||||
CONF_ON_VALUE_RANGE, CONF_OR, CONF_SEND_EVERY, CONF_SLIDING_WINDOW_MOVING_AVERAGE, \
|
CONF_ON_VALUE_RANGE, CONF_OR, CONF_SEND_EVERY, CONF_SLIDING_WINDOW_MOVING_AVERAGE, \
|
||||||
CONF_THROTTLE, CONF_TRIGGER_ID, CONF_UNIQUE, CONF_UNIT_OF_MEASUREMENT, CONF_WINDOW_SIZE
|
CONF_THROTTLE, CONF_TRIGGER_ID, CONF_UNIQUE, CONF_UNIT_OF_MEASUREMENT, CONF_WINDOW_SIZE
|
||||||
from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, add, esphomelib_ns, float_, \
|
from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, add, esphomelib_ns, float_, \
|
||||||
process_lambda, setup_mqtt_component, templatable
|
process_lambda, setup_mqtt_component, templatable, add_job
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
@ -152,13 +152,11 @@ def setup_sensor_core_(sensor_var, mqtt_var, config):
|
|||||||
for conf in config.get(CONF_ON_VALUE, []):
|
for conf in config.get(CONF_ON_VALUE, []):
|
||||||
rhs = sensor_var.make_value_trigger()
|
rhs = sensor_var.make_value_trigger()
|
||||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||||
for _ in automation.build_automation(trigger, float_, conf):
|
automation.build_automation(trigger, float_, conf)
|
||||||
yield
|
|
||||||
for conf in config.get(CONF_ON_RAW_VALUE, []):
|
for conf in config.get(CONF_ON_RAW_VALUE, []):
|
||||||
rhs = sensor_var.make_raw_value_trigger()
|
rhs = sensor_var.make_raw_value_trigger()
|
||||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||||
for _ in automation.build_automation(trigger, float_, conf):
|
automation.build_automation(trigger, float_, conf)
|
||||||
yield
|
|
||||||
for conf in config.get(CONF_ON_VALUE_RANGE, []):
|
for conf in config.get(CONF_ON_VALUE_RANGE, []):
|
||||||
rhs = sensor_var.make_value_range_trigger()
|
rhs = sensor_var.make_value_range_trigger()
|
||||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||||
@ -172,8 +170,7 @@ def setup_sensor_core_(sensor_var, mqtt_var, config):
|
|||||||
for template_ in templatable(conf[CONF_BELOW], float_, float_):
|
for template_ in templatable(conf[CONF_BELOW], float_, float_):
|
||||||
yield
|
yield
|
||||||
trigger.set_max(template_)
|
trigger.set_max(template_)
|
||||||
for _ in automation.build_automation(trigger, float_, conf):
|
automation.build_automation(trigger, float_, conf)
|
||||||
yield
|
|
||||||
|
|
||||||
if CONF_EXPIRE_AFTER in config:
|
if CONF_EXPIRE_AFTER in config:
|
||||||
if config[CONF_EXPIRE_AFTER] is None:
|
if config[CONF_EXPIRE_AFTER] is None:
|
||||||
@ -186,16 +183,14 @@ def setup_sensor_core_(sensor_var, mqtt_var, config):
|
|||||||
def setup_sensor(sensor_obj, mqtt_obj, config):
|
def setup_sensor(sensor_obj, mqtt_obj, config):
|
||||||
sensor_var = Pvariable(config[CONF_ID], sensor_obj, has_side_effects=False)
|
sensor_var = Pvariable(config[CONF_ID], sensor_obj, has_side_effects=False)
|
||||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
|
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
|
||||||
for _ in setup_sensor_core_(sensor_var, mqtt_var, config):
|
add_job(setup_sensor_core_, sensor_var, mqtt_var, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
def register_sensor(var, config):
|
def register_sensor(var, config):
|
||||||
sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
||||||
rhs = App.register_sensor(sensor_var)
|
rhs = App.register_sensor(sensor_var)
|
||||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
|
mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
|
||||||
for _ in setup_sensor_core_(sensor_var, mqtt_var, config):
|
add_job(setup_sensor_core_, sensor_var, mqtt_var, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_SENSOR'
|
BUILD_FLAGS = '-DUSE_SENSOR'
|
||||||
|
@ -42,8 +42,7 @@ def to_code(config):
|
|||||||
adc = make.Padc
|
adc = make.Padc
|
||||||
if CONF_ATTENUATION in config:
|
if CONF_ATTENUATION in config:
|
||||||
add(adc.set_attenuation(ATTENUATION_MODES[config[CONF_ATTENUATION]]))
|
add(adc.set_attenuation(ATTENUATION_MODES[config[CONF_ATTENUATION]]))
|
||||||
for _ in sensor.setup_sensor(make.Padc, make.Pmqtt, config):
|
sensor.setup_sensor(make.Padc, make.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_ADC_SENSOR'
|
BUILD_FLAGS = '-DUSE_ADC_SENSOR'
|
||||||
|
@ -61,8 +61,7 @@ def to_code(config):
|
|||||||
mux = MUX[config[CONF_MULTIPLEXER]]
|
mux = MUX[config[CONF_MULTIPLEXER]]
|
||||||
gain = GAIN[config[CONF_GAIN]]
|
gain = GAIN[config[CONF_GAIN]]
|
||||||
rhs = hub.get_sensor(config[CONF_NAME], mux, gain, config.get(CONF_UPDATE_INTERVAL))
|
rhs = hub.get_sensor(config[CONF_NAME], mux, gain, config.get(CONF_UPDATE_INTERVAL))
|
||||||
for _ in sensor.register_sensor(rhs, config):
|
sensor.register_sensor(rhs, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_ADS1115_SENSOR'
|
BUILD_FLAGS = '-DUSE_ADS1115_SENSOR'
|
||||||
|
@ -31,8 +31,7 @@ def to_code(config):
|
|||||||
bh1750 = make_bh1750.Pbh1750
|
bh1750 = make_bh1750.Pbh1750
|
||||||
if CONF_RESOLUTION in config:
|
if CONF_RESOLUTION in config:
|
||||||
add(bh1750.set_resolution(BH1750_RESOLUTIONS[config[CONF_RESOLUTION]]))
|
add(bh1750.set_resolution(BH1750_RESOLUTIONS[config[CONF_RESOLUTION]]))
|
||||||
for _ in sensor.setup_sensor(bh1750, make_bh1750.Pmqtt, config):
|
sensor.setup_sensor(bh1750, make_bh1750.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_BH1750'
|
BUILD_FLAGS = '-DUSE_BH1750'
|
||||||
|
@ -63,15 +63,12 @@ def to_code(config):
|
|||||||
constant = IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]]
|
constant = IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]]
|
||||||
add(bme280.set_iir_filter(constant))
|
add(bme280.set_iir_filter(constant))
|
||||||
|
|
||||||
for _ in sensor.setup_sensor(bme280.Pget_temperature_sensor(), make.Pmqtt_temperature,
|
sensor.setup_sensor(bme280.Pget_temperature_sensor(), make.Pmqtt_temperature,
|
||||||
config[CONF_TEMPERATURE]):
|
config[CONF_TEMPERATURE])
|
||||||
yield
|
sensor.setup_sensor(bme280.Pget_pressure_sensor(), make.Pmqtt_pressure,
|
||||||
for _ in sensor.setup_sensor(bme280.Pget_pressure_sensor(), make.Pmqtt_pressure,
|
config[CONF_PRESSURE])
|
||||||
config[CONF_PRESSURE]):
|
sensor.setup_sensor(bme280.Pget_humidity_sensor(), make.Pmqtt_humidity,
|
||||||
yield
|
config[CONF_HUMIDITY])
|
||||||
for _ in sensor.setup_sensor(bme280.Pget_humidity_sensor(), make.Pmqtt_humidity,
|
|
||||||
config[CONF_HUMIDITY]):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_BME280'
|
BUILD_FLAGS = '-DUSE_BME280'
|
||||||
|
@ -70,18 +70,14 @@ def to_code(config):
|
|||||||
constant = IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]]
|
constant = IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]]
|
||||||
add(bme680.set_iir_filter(constant))
|
add(bme680.set_iir_filter(constant))
|
||||||
|
|
||||||
for _ in sensor.setup_sensor(bme680.Pget_temperature_sensor(), make.Pmqtt_temperature,
|
sensor.setup_sensor(bme680.Pget_temperature_sensor(), make.Pmqtt_temperature,
|
||||||
config[CONF_TEMPERATURE]):
|
config[CONF_TEMPERATURE])
|
||||||
yield
|
sensor.setup_sensor(bme680.Pget_pressure_sensor(), make.Pmqtt_pressure,
|
||||||
for _ in sensor.setup_sensor(bme680.Pget_pressure_sensor(), make.Pmqtt_pressure,
|
config[CONF_PRESSURE])
|
||||||
config[CONF_PRESSURE]):
|
sensor.setup_sensor(bme680.Pget_humidity_sensor(), make.Pmqtt_humidity,
|
||||||
yield
|
config[CONF_HUMIDITY])
|
||||||
for _ in sensor.setup_sensor(bme680.Pget_humidity_sensor(), make.Pmqtt_humidity,
|
sensor.setup_sensor(bme680.Pget_gas_resistance_sensor(), make.Pmqtt_gas_resistance,
|
||||||
config[CONF_HUMIDITY]):
|
config[CONF_GAS_RESISTANCE])
|
||||||
yield
|
|
||||||
for _ in sensor.setup_sensor(bme680.Pget_gas_resistance_sensor(), make.Pmqtt_gas_resistance,
|
|
||||||
config[CONF_GAS_RESISTANCE]):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_BME680'
|
BUILD_FLAGS = '-DUSE_BME680'
|
||||||
|
@ -4,7 +4,7 @@ import esphomeyaml.config_validation as cv
|
|||||||
from esphomeyaml.components import sensor
|
from esphomeyaml.components import sensor
|
||||||
from esphomeyaml.const import CONF_ADDRESS, CONF_MAKE_ID, CONF_NAME, CONF_PRESSURE, \
|
from esphomeyaml.const import CONF_ADDRESS, CONF_MAKE_ID, CONF_NAME, CONF_PRESSURE, \
|
||||||
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
||||||
from esphomeyaml.helpers import App, HexIntLiteral, add, variable, Application
|
from esphomeyaml.helpers import App, Application, HexIntLiteral, add, variable
|
||||||
|
|
||||||
DEPENDENCIES = ['i2c']
|
DEPENDENCIES = ['i2c']
|
||||||
|
|
||||||
@ -27,12 +27,10 @@ def to_code(config):
|
|||||||
if CONF_ADDRESS in config:
|
if CONF_ADDRESS in config:
|
||||||
add(bmp.Pbmp.set_address(HexIntLiteral(config[CONF_ADDRESS])))
|
add(bmp.Pbmp.set_address(HexIntLiteral(config[CONF_ADDRESS])))
|
||||||
|
|
||||||
for _ in sensor.setup_sensor(bmp.Pbmp.Pget_temperature_sensor(), bmp.Pmqtt_temperature,
|
sensor.setup_sensor(bmp.Pbmp.Pget_temperature_sensor(), bmp.Pmqtt_temperature,
|
||||||
config[CONF_TEMPERATURE]):
|
config[CONF_TEMPERATURE])
|
||||||
yield
|
sensor.setup_sensor(bmp.Pbmp.Pget_pressure_sensor(), bmp.Pmqtt_pressure,
|
||||||
for _ in sensor.setup_sensor(bmp.Pbmp.Pget_pressure_sensor(), bmp.Pmqtt_pressure,
|
config[CONF_PRESSURE])
|
||||||
config[CONF_PRESSURE]):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_BMP085_SENSOR'
|
BUILD_FLAGS = '-DUSE_BMP085_SENSOR'
|
||||||
|
@ -30,8 +30,7 @@ def to_code(config):
|
|||||||
else:
|
else:
|
||||||
rhs = hub.Pget_sensor_by_index(config[CONF_NAME], config[CONF_INDEX],
|
rhs = hub.Pget_sensor_by_index(config[CONF_NAME], config[CONF_INDEX],
|
||||||
update_interval, config.get(CONF_RESOLUTION))
|
update_interval, config.get(CONF_RESOLUTION))
|
||||||
for _ in sensor.register_sensor(rhs, config):
|
sensor.register_sensor(rhs, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_DALLAS_SENSOR'
|
BUILD_FLAGS = '-DUSE_DALLAS_SENSOR'
|
||||||
|
@ -39,12 +39,10 @@ def to_code(config):
|
|||||||
constant = DHT_MODELS[config[CONF_MODEL]]
|
constant = DHT_MODELS[config[CONF_MODEL]]
|
||||||
add(dht.Pdht.set_dht_model(constant))
|
add(dht.Pdht.set_dht_model(constant))
|
||||||
|
|
||||||
for _ in sensor.setup_sensor(dht.Pdht.Pget_temperature_sensor(),
|
sensor.setup_sensor(dht.Pdht.Pget_temperature_sensor(),
|
||||||
dht.Pmqtt_temperature, config[CONF_TEMPERATURE]):
|
dht.Pmqtt_temperature, config[CONF_TEMPERATURE])
|
||||||
yield
|
sensor.setup_sensor(dht.Pdht.Pget_humidity_sensor(),
|
||||||
for _ in sensor.setup_sensor(dht.Pdht.Pget_humidity_sensor(),
|
dht.Pmqtt_humidity, config[CONF_HUMIDITY])
|
||||||
dht.Pmqtt_humidity, config[CONF_HUMIDITY]):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_DHT_SENSOR'
|
BUILD_FLAGS = '-DUSE_DHT_SENSOR'
|
||||||
|
@ -24,12 +24,10 @@ def to_code(config):
|
|||||||
config.get(CONF_UPDATE_INTERVAL))
|
config.get(CONF_UPDATE_INTERVAL))
|
||||||
dht = variable(config[CONF_MAKE_ID], rhs)
|
dht = variable(config[CONF_MAKE_ID], rhs)
|
||||||
|
|
||||||
for _ in sensor.setup_sensor(dht.Pdht.Pget_temperature_sensor(), dht.Pmqtt_temperature,
|
sensor.setup_sensor(dht.Pdht.Pget_temperature_sensor(), dht.Pmqtt_temperature,
|
||||||
config[CONF_TEMPERATURE]):
|
config[CONF_TEMPERATURE])
|
||||||
yield
|
sensor.setup_sensor(dht.Pdht.Pget_humidity_sensor(), dht.Pmqtt_humidity,
|
||||||
for _ in sensor.setup_sensor(dht.Pdht.Pget_humidity_sensor(), dht.Pmqtt_humidity,
|
config[CONF_HUMIDITY])
|
||||||
config[CONF_HUMIDITY]):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_DHT12_SENSOR'
|
BUILD_FLAGS = '-DUSE_DHT12_SENSOR'
|
||||||
|
@ -18,8 +18,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
|
|||||||
def to_code(config):
|
def to_code(config):
|
||||||
rhs = App.make_esp32_hall_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
|
rhs = App.make_esp32_hall_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
|
||||||
make = variable(config[CONF_MAKE_ID], rhs)
|
make = variable(config[CONF_MAKE_ID], rhs)
|
||||||
for _ in sensor.setup_sensor(make.Phall, make.Pmqtt, config):
|
sensor.setup_sensor(make.Phall, make.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_ESP32_HALL_SENSOR'
|
BUILD_FLAGS = '-DUSE_ESP32_HALL_SENSOR'
|
||||||
|
@ -4,7 +4,7 @@ import esphomeyaml.config_validation as cv
|
|||||||
from esphomeyaml.components import sensor
|
from esphomeyaml.components import sensor
|
||||||
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, \
|
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, \
|
||||||
CONF_UPDATE_INTERVAL
|
CONF_UPDATE_INTERVAL
|
||||||
from esphomeyaml.helpers import App, variable, Application
|
from esphomeyaml.helpers import App, Application, variable
|
||||||
|
|
||||||
DEPENDENCIES = ['i2c']
|
DEPENDENCIES = ['i2c']
|
||||||
|
|
||||||
@ -24,13 +24,11 @@ def to_code(config):
|
|||||||
config.get(CONF_UPDATE_INTERVAL))
|
config.get(CONF_UPDATE_INTERVAL))
|
||||||
hdc1080 = variable(config[CONF_MAKE_ID], rhs)
|
hdc1080 = variable(config[CONF_MAKE_ID], rhs)
|
||||||
|
|
||||||
for _ in sensor.setup_sensor(hdc1080.Phdc1080.Pget_temperature_sensor(),
|
sensor.setup_sensor(hdc1080.Phdc1080.Pget_temperature_sensor(),
|
||||||
hdc1080.Pmqtt_temperature,
|
hdc1080.Pmqtt_temperature,
|
||||||
config[CONF_TEMPERATURE]):
|
config[CONF_TEMPERATURE])
|
||||||
yield
|
sensor.setup_sensor(hdc1080.Phdc1080.Pget_humidity_sensor(), hdc1080.Pmqtt_humidity,
|
||||||
for _ in sensor.setup_sensor(hdc1080.Phdc1080.Pget_humidity_sensor(), hdc1080.Pmqtt_humidity,
|
config[CONF_HUMIDITY])
|
||||||
config[CONF_HUMIDITY]):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_HDC1080_SENSOR'
|
BUILD_FLAGS = '-DUSE_HDC1080_SENSOR'
|
||||||
|
@ -4,7 +4,7 @@ import esphomeyaml.config_validation as cv
|
|||||||
from esphomeyaml.components import sensor
|
from esphomeyaml.components import sensor
|
||||||
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, \
|
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, \
|
||||||
CONF_UPDATE_INTERVAL
|
CONF_UPDATE_INTERVAL
|
||||||
from esphomeyaml.helpers import App, variable, Application
|
from esphomeyaml.helpers import App, Application, variable
|
||||||
|
|
||||||
DEPENDENCIES = ['i2c']
|
DEPENDENCIES = ['i2c']
|
||||||
|
|
||||||
@ -23,12 +23,10 @@ def to_code(config):
|
|||||||
config[CONF_HUMIDITY][CONF_NAME],
|
config[CONF_HUMIDITY][CONF_NAME],
|
||||||
config.get(CONF_UPDATE_INTERVAL))
|
config.get(CONF_UPDATE_INTERVAL))
|
||||||
htu21d = variable(config[CONF_MAKE_ID], rhs)
|
htu21d = variable(config[CONF_MAKE_ID], rhs)
|
||||||
for _ in sensor.setup_sensor(htu21d.Phtu21d.Pget_temperature_sensor(), htu21d.Pmqtt_temperature,
|
sensor.setup_sensor(htu21d.Phtu21d.Pget_temperature_sensor(), htu21d.Pmqtt_temperature,
|
||||||
config[CONF_TEMPERATURE]):
|
config[CONF_TEMPERATURE])
|
||||||
yield
|
sensor.setup_sensor(htu21d.Phtu21d.Pget_humidity_sensor(), htu21d.Pmqtt_humidity,
|
||||||
for _ in sensor.setup_sensor(htu21d.Phtu21d.Pget_humidity_sensor(), htu21d.Pmqtt_humidity,
|
config[CONF_HUMIDITY])
|
||||||
config[CONF_HUMIDITY]):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_HTU21D_SENSOR'
|
BUILD_FLAGS = '-DUSE_HTU21D_SENSOR'
|
||||||
|
@ -32,8 +32,7 @@ def to_code(config):
|
|||||||
rhs = App.make_max6675_sensor(config[CONF_NAME], pin_cs, pin_clock, pin_miso,
|
rhs = App.make_max6675_sensor(config[CONF_NAME], pin_cs, pin_clock, pin_miso,
|
||||||
config.get(CONF_UPDATE_INTERVAL))
|
config.get(CONF_UPDATE_INTERVAL))
|
||||||
make = variable(config[CONF_MAKE_ID], rhs)
|
make = variable(config[CONF_MAKE_ID], rhs)
|
||||||
for _ in sensor.setup_sensor(make.Pmax6675, make.Pmqtt, config):
|
sensor.setup_sensor(make.Pmax6675, make.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_MAX6675_SENSOR'
|
BUILD_FLAGS = '-DUSE_MAX6675_SENSOR'
|
||||||
|
@ -41,38 +41,31 @@ def to_code(config):
|
|||||||
if CONF_ACCEL_X in config:
|
if CONF_ACCEL_X in config:
|
||||||
conf = config[CONF_ACCEL_X]
|
conf = config[CONF_ACCEL_X]
|
||||||
rhs = mpu.Pmake_accel_x_sensor(conf[CONF_NAME])
|
rhs = mpu.Pmake_accel_x_sensor(conf[CONF_NAME])
|
||||||
for _ in sensor.register_sensor(rhs, conf):
|
sensor.register_sensor(rhs, conf)
|
||||||
yield
|
|
||||||
if CONF_ACCEL_Y in config:
|
if CONF_ACCEL_Y in config:
|
||||||
conf = config[CONF_ACCEL_Y]
|
conf = config[CONF_ACCEL_Y]
|
||||||
rhs = mpu.Pmake_accel_y_sensor(conf[CONF_NAME])
|
rhs = mpu.Pmake_accel_y_sensor(conf[CONF_NAME])
|
||||||
for _ in sensor.register_sensor(rhs, conf):
|
sensor.register_sensor(rhs, conf)
|
||||||
yield
|
|
||||||
if CONF_ACCEL_Z in config:
|
if CONF_ACCEL_Z in config:
|
||||||
conf = config[CONF_ACCEL_Z]
|
conf = config[CONF_ACCEL_Z]
|
||||||
rhs = mpu.Pmake_accel_z_sensor(conf[CONF_NAME])
|
rhs = mpu.Pmake_accel_z_sensor(conf[CONF_NAME])
|
||||||
for _ in sensor.register_sensor(rhs, conf):
|
sensor.register_sensor(rhs, conf)
|
||||||
yield
|
|
||||||
if CONF_GYRO_X in config:
|
if CONF_GYRO_X in config:
|
||||||
conf = config[CONF_GYRO_X]
|
conf = config[CONF_GYRO_X]
|
||||||
rhs = mpu.Pmake_gyro_x_sensor(conf[CONF_NAME])
|
rhs = mpu.Pmake_gyro_x_sensor(conf[CONF_NAME])
|
||||||
for _ in sensor.register_sensor(rhs, conf):
|
sensor.register_sensor(rhs, conf)
|
||||||
yield
|
|
||||||
if CONF_GYRO_Y in config:
|
if CONF_GYRO_Y in config:
|
||||||
conf = config[CONF_GYRO_Y]
|
conf = config[CONF_GYRO_Y]
|
||||||
rhs = mpu.Pmake_gyro_y_sensor(conf[CONF_NAME])
|
rhs = mpu.Pmake_gyro_y_sensor(conf[CONF_NAME])
|
||||||
for _ in sensor.register_sensor(rhs, conf):
|
sensor.register_sensor(rhs, conf)
|
||||||
yield
|
|
||||||
if CONF_GYRO_Z in config:
|
if CONF_GYRO_Z in config:
|
||||||
conf = config[CONF_GYRO_Z]
|
conf = config[CONF_GYRO_Z]
|
||||||
rhs = mpu.Pmake_gyro_z_sensor(conf[CONF_NAME])
|
rhs = mpu.Pmake_gyro_z_sensor(conf[CONF_NAME])
|
||||||
for _ in sensor.register_sensor(rhs, conf):
|
sensor.register_sensor(rhs, conf)
|
||||||
yield
|
|
||||||
if CONF_TEMPERATURE in config:
|
if CONF_TEMPERATURE in config:
|
||||||
conf = config[CONF_TEMPERATURE]
|
conf = config[CONF_TEMPERATURE]
|
||||||
rhs = mpu.Pmake_temperature_sensor(conf[CONF_NAME])
|
rhs = mpu.Pmake_temperature_sensor(conf[CONF_NAME])
|
||||||
for _ in sensor.register_sensor(rhs, conf):
|
sensor.register_sensor(rhs, conf)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_MPU6050'
|
BUILD_FLAGS = '-DUSE_MPU6050'
|
||||||
|
@ -57,8 +57,7 @@ def to_code(config):
|
|||||||
add(pcnt.set_edge_mode(rising_edge, falling_edge))
|
add(pcnt.set_edge_mode(rising_edge, falling_edge))
|
||||||
if CONF_INTERNAL_FILTER in config:
|
if CONF_INTERNAL_FILTER in config:
|
||||||
add(pcnt.set_filter(config[CONF_INTERNAL_FILTER]))
|
add(pcnt.set_filter(config[CONF_INTERNAL_FILTER]))
|
||||||
for _ in sensor.setup_sensor(make.Ppcnt, make.Pmqtt, config):
|
sensor.setup_sensor(make.Ppcnt, make.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_PULSE_COUNTER_SENSOR'
|
BUILD_FLAGS = '-DUSE_PULSE_COUNTER_SENSOR'
|
||||||
|
@ -45,8 +45,7 @@ def to_code(config):
|
|||||||
if CONF_RESOLUTION in config:
|
if CONF_RESOLUTION in config:
|
||||||
resolution = RESOLUTIONS[config[CONF_RESOLUTION]]
|
resolution = RESOLUTIONS[config[CONF_RESOLUTION]]
|
||||||
add(encoder.set_resolution(resolution))
|
add(encoder.set_resolution(resolution))
|
||||||
for _ in sensor.setup_sensor(encoder, make.Pmqtt, config):
|
sensor.setup_sensor(encoder, make.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_ROTARY_ENCODER_SENSOR'
|
BUILD_FLAGS = '-DUSE_ROTARY_ENCODER_SENSOR'
|
||||||
|
@ -35,12 +35,10 @@ def to_code(config):
|
|||||||
if CONF_ACCURACY in config:
|
if CONF_ACCURACY in config:
|
||||||
add(sht3xd.Psht3xd.set_accuracy(SHT_ACCURACIES[config[CONF_ACCURACY]]))
|
add(sht3xd.Psht3xd.set_accuracy(SHT_ACCURACIES[config[CONF_ACCURACY]]))
|
||||||
|
|
||||||
for _ in sensor.setup_sensor(sht3xd.Psht3xd.Pget_temperature_sensor(), sht3xd.Pmqtt_temperature,
|
sensor.setup_sensor(sht3xd.Psht3xd.Pget_temperature_sensor(), sht3xd.Pmqtt_temperature,
|
||||||
config[CONF_TEMPERATURE]):
|
config[CONF_TEMPERATURE])
|
||||||
yield
|
sensor.setup_sensor(sht3xd.Psht3xd.Pget_humidity_sensor(), sht3xd.Pmqtt_humidity,
|
||||||
for _ in sensor.setup_sensor(sht3xd.Psht3xd.Pget_humidity_sensor(), sht3xd.Pmqtt_humidity,
|
config[CONF_HUMIDITY])
|
||||||
config[CONF_HUMIDITY]):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_SHT3XD'
|
BUILD_FLAGS = '-DUSE_SHT3XD'
|
||||||
|
@ -21,8 +21,7 @@ def to_code(config):
|
|||||||
rhs = App.make_template_sensor(config[CONF_NAME], template_,
|
rhs = App.make_template_sensor(config[CONF_NAME], template_,
|
||||||
config.get(CONF_UPDATE_INTERVAL))
|
config.get(CONF_UPDATE_INTERVAL))
|
||||||
make = variable(config[CONF_MAKE_ID], rhs)
|
make = variable(config[CONF_MAKE_ID], rhs)
|
||||||
for _ in sensor.setup_sensor(make.Ptemplate_, make.Pmqtt, config):
|
sensor.setup_sensor(make.Ptemplate_, make.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_TEMPLATE_SENSOR'
|
BUILD_FLAGS = '-DUSE_TEMPLATE_SENSOR'
|
||||||
|
@ -51,8 +51,7 @@ def to_code(config):
|
|||||||
add(tsl2561.set_gain(GAINS[config[CONF_GAIN]]))
|
add(tsl2561.set_gain(GAINS[config[CONF_GAIN]]))
|
||||||
if CONF_IS_CS_PACKAGE in config:
|
if CONF_IS_CS_PACKAGE in config:
|
||||||
add(tsl2561.set_is_cs_package(config[CONF_IS_CS_PACKAGE]))
|
add(tsl2561.set_is_cs_package(config[CONF_IS_CS_PACKAGE]))
|
||||||
for _ in sensor.setup_sensor(tsl2561, make_tsl.Pmqtt, config):
|
sensor.setup_sensor(tsl2561, make_tsl.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_TSL2561'
|
BUILD_FLAGS = '-DUSE_TSL2561'
|
||||||
|
@ -35,8 +35,7 @@ def to_code(config):
|
|||||||
add(ultrasonic.set_timeout_us(config[CONF_TIMEOUT_TIME]))
|
add(ultrasonic.set_timeout_us(config[CONF_TIMEOUT_TIME]))
|
||||||
elif CONF_TIMEOUT_METER in config:
|
elif CONF_TIMEOUT_METER in config:
|
||||||
add(ultrasonic.set_timeout_m(config[CONF_TIMEOUT_METER]))
|
add(ultrasonic.set_timeout_m(config[CONF_TIMEOUT_METER]))
|
||||||
for _ in sensor.setup_sensor(ultrasonic, make.Pmqtt, config):
|
sensor.setup_sensor(ultrasonic, make.Pmqtt, config)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_ULTRASONIC_SENSOR'
|
BUILD_FLAGS = '-DUSE_ULTRASONIC_SENSOR'
|
||||||
|
@ -3,7 +3,7 @@ from __future__ import print_function
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict, deque
|
||||||
|
|
||||||
from esphomeyaml import core
|
from esphomeyaml import core
|
||||||
from esphomeyaml.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, CONF_DISCOVERY, \
|
from esphomeyaml.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, CONF_DISCOVERY, \
|
||||||
@ -388,7 +388,7 @@ def Pvariable(id, rhs, has_side_effects=True, type=None):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
_TASKS = []
|
_TASKS = deque()
|
||||||
_VARIABLES = {}
|
_VARIABLES = {}
|
||||||
_EXPRESSIONS = []
|
_EXPRESSIONS = []
|
||||||
|
|
||||||
@ -426,39 +426,35 @@ def templatable(value, input_type, output_type):
|
|||||||
yield value
|
yield value
|
||||||
|
|
||||||
|
|
||||||
def add_task(func, config, domain):
|
def add_job(func, *args, **kwargs):
|
||||||
|
domain = kwargs.get('domain')
|
||||||
if inspect.isgeneratorfunction(func):
|
if inspect.isgeneratorfunction(func):
|
||||||
def func_():
|
def func_():
|
||||||
yield
|
yield
|
||||||
for _ in func(config):
|
for _ in func(*args):
|
||||||
yield
|
yield
|
||||||
else:
|
else:
|
||||||
def func_():
|
def func_():
|
||||||
yield
|
yield
|
||||||
func(config)
|
func(*args)
|
||||||
_TASKS.append((func_(), domain))
|
gen = func_()
|
||||||
|
_TASKS.append((gen, domain))
|
||||||
|
return gen
|
||||||
def run_tasks():
|
|
||||||
global _TASKS
|
|
||||||
|
|
||||||
new_tasks = []
|
|
||||||
for task, domain in _TASKS:
|
|
||||||
try:
|
|
||||||
task.next()
|
|
||||||
new_tasks.append((task, domain))
|
|
||||||
except StopIteration:
|
|
||||||
pass
|
|
||||||
_TASKS = new_tasks
|
|
||||||
|
|
||||||
|
|
||||||
def flush_tasks():
|
def flush_tasks():
|
||||||
for _ in range(1000000):
|
i = 0
|
||||||
run_tasks()
|
while _TASKS:
|
||||||
if not _TASKS:
|
i += 1
|
||||||
break
|
if i > 1000000:
|
||||||
else:
|
raise ESPHomeYAMLError("Circular dependency detected!")
|
||||||
raise ESPHomeYAMLError("Circular dependency detected!")
|
|
||||||
|
task, domain = _TASKS.popleft()
|
||||||
|
try:
|
||||||
|
task.next()
|
||||||
|
_TASKS.append((task, domain))
|
||||||
|
except StopIteration:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def add(expression, require=True):
|
def add(expression, require=True):
|
||||||
|
Loading…
Reference in New Issue
Block a user