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