1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-19 03:32:20 +01:00
This commit is contained in:
Otto Winter
2018-06-03 07:11:11 +02:00
parent 4f3f460105
commit 967aa53bad
31 changed files with 113 additions and 170 deletions

View File

@@ -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'

View File

@@ -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'

View File

@@ -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'

View File

@@ -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'

View File

@@ -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'

View File

@@ -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'