def setup_conf(config, key): if key in config: conf = config[key] var = cg.new_Pvariable(conf[CONF_ID]) yield cg.register_component(var, conf) yield text_sensor.register_text_sensor(var, conf)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) cg.add_library('CountUpDownTimer', None) yield cg.register_component(var, config) yield text_sensor.register_text_sensor(var, config)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield cover.register_cover(var, config)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield esp32_ble_tracker.register_ble_device(var, config) yield text_sensor.register_text_sensor(var, config)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield i2c.register_i2c_device(var, config) yield sensor.register_sensor(var, config)
def make_gpio_binary_output(id_, number): gpio_var = yield make_gpio(number) output_var = cg.new_Pvariable(id_) cg.add(output_var.set_pin(gpio_var)) yield from cg.register_component(output_var, {})
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) cg.add_define("USE_I2C_MULTIPLEXER") yield cg.register_component(var, config) yield i2c.register_i2c_device(var, config) cg.add(var.set_scan(config[CONF_SCAN]))
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield binary_sensor.register_binary_sensor(var, config) cg.add(var.set_entity_id(config[CONF_ENTITY_ID]))
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield i2c.register_i2c_device(var, config) cg.add(var.set_pcf8575(config[CONF_PCF8575]))
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield modbus.register_modbus_device(var, config) pin = yield cg.gpio_pin_expression(config[CONF_RW_PIN]) cg.add(var.set_rw_pin(pin))
def to_code(config): sender = yield cg.get_variable(config[GCodeSender.CONF_GCODE_SENDER]) var = cg.new_Pvariable(config[CONF_ID], sender, config[CONF_CANCEL_GCODES]) yield cg.register_component(var, config)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield switch.register_switch(var, config) yield rs485.register_rs485_device(var, config)
def to_code(config): paren = yield cg.get_variable(config[CONF_WEB_SERVER_BASE_ID]) var = cg.new_Pvariable(config[CONF_ID], paren) yield cg.register_component(var, config) cg.add_define("USE_CAPTIVE_PORTAL")
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) cg.add(var.set_method(METHODS[config[CONF_METHOD]]))
def to_code(config): cg.add_global(modbus_ns.using) var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield uart.register_uart_device(var, config)
def to_code(config): cg.add_global(cg.global_ns.namespace('esphome').using) cg.add_define('ESPHOME_VERSION', __version__) cg.add(cg.App.pre_setup(config[CONF_NAME], cg.RawExpression('__DATE__ ", " __TIME__'))) for conf in config.get(CONF_ON_BOOT, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf.get(CONF_PRIORITY)) yield cg.register_component(trigger, conf) yield automation.build_automation(trigger, [], conf) for conf in config.get(CONF_ON_SHUTDOWN, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) yield cg.register_component(trigger, conf) yield automation.build_automation(trigger, [], conf) for conf in config.get(CONF_ON_LOOP, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) yield cg.register_component(trigger, conf) yield automation.build_automation(trigger, [], conf) # Build flags if CORE.is_esp8266 and CORE.board in ESP8266_FLASH_SIZES and \ CORE.arduino_version != ARDUINO_VERSION_ESP8266_2_3_0: flash_size = ESP8266_FLASH_SIZES[CORE.board] ld_scripts = ESP8266_LD_SCRIPTS[flash_size] ld_script = None if CORE.arduino_version in ('[email protected]', '[email protected]', '[email protected]'): ld_script = ld_scripts[0] elif CORE.arduino_version in (ARDUINO_VERSION_ESP8266_DEV, ARDUINO_VERSION_ESP8266_2_5_0, ARDUINO_VERSION_ESP8266_2_5_1, ARDUINO_VERSION_ESP8266_2_5_2): ld_script = ld_scripts[1] if ld_script is not None: cg.add_build_flag('-Wl,-T{}'.format(ld_script)) cg.add_build_flag('-fno-exceptions') # Libraries if CORE.is_esp32: cg.add_library('Preferences', None) cg.add_library('ESPmDNS', None) elif CORE.is_esp8266: cg.add_library('ESP8266WiFi', None) cg.add_library('ESP8266mDNS', None) for lib in config[CONF_LIBRARIES]: if '@' in lib: name, vers = lib.split('@', 1) cg.add_library(name, vers) else: cg.add_library(lib, None) cg.add_build_flag('-Wno-unused-variable') cg.add_build_flag('-Wno-unused-but-set-variable') cg.add_build_flag('-Wno-sign-compare') if config.get(CONF_ESP8266_RESTORE_FROM_FLASH, False): cg.add_define('USE_ESP8266_PREFERENCES_FLASH') if config[CONF_INCLUDES]: CORE.add_job(add_includes, config[CONF_INCLUDES])
def to_code(config): var = cg.new_Pvariable(config[CONF_ID], config[CONF_FREQUENCY]) yield cg.register_component(var, config) yield i2c.register_i2c_device(var, config)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) cg.add(var.set_device_address(config[CONF_DEVICEADDRESS])) yield cg.register_component(var, config) yield spi.register_spi_device(var, config)
def make_ledc_output(id_, number, frequency, channel): gpio_var = yield make_gpio(number) ledc_var = cg.new_Pvariable(id_, gpio_var) cg.add(ledc_var.set_frequency(frequency)) cg.add(ledc_var.set_channel(channel)) yield from cg.register_component(ledc_var, {})
def register_light(output_var, config): light_var = cg.new_Pvariable(config[CONF_ID], config[CONF_NAME], output_var) cg.add(cg.App.register_light(light_var)) yield cg.register_component(light_var, config) yield setup_light_core_(light_var, output_var, config)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) cg.add(var.set_timeout(config[CONF_TIMEOUT])) cg.add(var.set_useragent(config[CONF_USERAGENT])) yield cg.register_component(var, config)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield uart.register_uart_device(var, config) cg.add(var.use_strength_icon(config[CONF_STRENGTH_ICON]))
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) # https://github.com/OttoWinter/async-mqtt-client/blob/master/library.json cg.add_library('AsyncMqttClient-esphome', '0.8.4') cg.add_define('USE_MQTT') cg.add_global(mqtt_ns.using) cg.add(var.set_broker_address(config[CONF_BROKER])) cg.add(var.set_broker_port(config[CONF_PORT])) cg.add(var.set_username(config[CONF_USERNAME])) cg.add(var.set_password(config[CONF_PASSWORD])) if CONF_CLIENT_ID in config: cg.add(var.set_client_id(config[CONF_CLIENT_ID])) discovery = config[CONF_DISCOVERY] discovery_retain = config[CONF_DISCOVERY_RETAIN] discovery_prefix = config[CONF_DISCOVERY_PREFIX] if not discovery: cg.add(var.disable_discovery()) elif discovery == "CLEAN": cg.add(var.set_discovery_info(discovery_prefix, discovery_retain, True)) elif CONF_DISCOVERY_RETAIN in config or CONF_DISCOVERY_PREFIX in config: cg.add(var.set_discovery_info(discovery_prefix, discovery_retain)) cg.add(var.set_topic_prefix(config[CONF_TOPIC_PREFIX])) birth_message = config[CONF_BIRTH_MESSAGE] if not birth_message: cg.add(var.disable_birth_message()) else: cg.add(var.set_birth_message(exp_mqtt_message(birth_message))) will_message = config[CONF_WILL_MESSAGE] if not will_message: cg.add(var.disable_last_will()) else: cg.add(var.set_last_will(exp_mqtt_message(will_message))) shutdown_message = config[CONF_SHUTDOWN_MESSAGE] if not shutdown_message: cg.add(var.disable_shutdown_message()) else: cg.add(var.set_shutdown_message(exp_mqtt_message(shutdown_message))) log_topic = config[CONF_LOG_TOPIC] if not log_topic: cg.add(var.disable_log_message()) else: cg.add(var.set_log_message_template(exp_mqtt_message(log_topic))) if CONF_LEVEL in log_topic: cg.add(var.set_log_level(logger.LOG_LEVELS[log_topic[CONF_LEVEL]])) if CONF_SSL_FINGERPRINTS in config: for fingerprint in config[CONF_SSL_FINGERPRINTS]: arr = [cg.RawExpression("0x{}".format(fingerprint[i:i + 2])) for i in range(0, 40, 2)] cg.add(var.add_ssl_fingerprint(arr)) cg.add_build_flag('-DASYNC_TCP_SSL_ENABLED=1') cg.add(var.set_keep_alive(config[CONF_KEEPALIVE])) cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT])) for conf in config.get(CONF_ON_MESSAGE, []): trig = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf[CONF_TOPIC]) cg.add(trig.set_qos(conf[CONF_QOS])) if CONF_PAYLOAD in conf: cg.add(trig.set_payload(conf[CONF_PAYLOAD])) yield cg.register_component(trig, conf) yield automation.build_automation(trig, [(cg.std_string, 'x')], conf) for conf in config.get(CONF_ON_JSON_MESSAGE, []): trig = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf[CONF_TOPIC], conf[CONF_QOS]) yield automation.build_automation(trig, [(cg.JsonObjectConstRef, 'x')], conf)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield uart.register_uart_device(var, config)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) irq_pin = yield cg.gpio_pin_expression(config[CONF_IRQ_PIN]) cg.add(var.set_irq_pin(irq_pin)) yield i2c.register_i2c_device(var, config)
def delay_action_to_code(config, action_id, template_arg, args): var = cg.new_Pvariable(action_id, template_arg) yield cg.register_component(var, {}) template_ = yield cg.templatable(config, args, cg.uint32) cg.add(var.set_delay(template_)) yield var
def debounce_filter_to_code(config, filter_id): var = cg.new_Pvariable(filter_id, config) yield cg.register_component(var, {}) yield var
def wait_until_action_to_code(config, action_id, template_arg, args): conditions = yield build_condition(config[CONF_CONDITION], template_arg, args) var = cg.new_Pvariable(action_id, template_arg, conditions) yield cg.register_component(var, {}) yield var
def setup_lcd_display(var, config): yield cg.register_component(var, config) yield display.register_display(var, config) cg.add( var.set_dimensions(config[CONF_DIMENSIONS][0], config[CONF_DIMENSIONS][1]))
def to_code(config): parent = yield cg.get_variable(config[CONF_MCP3008_ID]) var = cg.new_Pvariable(config[CONF_ID], parent, config[CONF_NAME], config[CONF_NUMBER]) yield cg.register_component(var, config)