def to_code(config): if CORE.is_esp32: # https://github.com/esphome/AsyncTCP/blob/master/library.json cg.add_library("esphome/AsyncTCP-esphome", "1.2.2") elif CORE.is_esp8266: # https://github.com/OttoWinter/ESPAsyncTCP cg.add_library("ESPAsyncTCP-esphome", "1.2.3")
async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await uart.register_uart_device(var, config) await climate.register_climate(var, config) cg.add(var.set_period(config[CONF_PERIOD].total_milliseconds)) cg.add(var.set_response_timeout(config[CONF_TIMEOUT].total_milliseconds)) cg.add(var.set_request_attempts(config[CONF_NUM_ATTEMPTS])) if CONF_TRANSMITTER_ID in config: cg.add_define("USE_REMOTE_TRANSMITTER") transmitter_ = await cg.get_variable(config[CONF_TRANSMITTER_ID]) cg.add(var.set_transmitter(transmitter_)) cg.add(var.set_beeper_feedback(config[CONF_BEEPER])) cg.add(var.set_autoconf(config[CONF_AUTOCONF])) if CONF_SUPPORTED_MODES in config: cg.add(var.set_supported_modes(config[CONF_SUPPORTED_MODES])) if CONF_SUPPORTED_SWING_MODES in config: cg.add( var.set_supported_swing_modes(config[CONF_SUPPORTED_SWING_MODES])) if CONF_SUPPORTED_PRESETS in config: cg.add(var.set_supported_presets(config[CONF_SUPPORTED_PRESETS])) if CONF_CUSTOM_PRESETS in config: cg.add(var.set_custom_presets(config[CONF_CUSTOM_PRESETS])) if CONF_CUSTOM_FAN_MODES in config: cg.add(var.set_custom_fan_modes(config[CONF_CUSTOM_FAN_MODES])) if CONF_OUTDOOR_TEMPERATURE in config: sens = await sensor.new_sensor(config[CONF_OUTDOOR_TEMPERATURE]) cg.add(var.set_outdoor_temperature_sensor(sens)) if CONF_POWER_USAGE in config: sens = await sensor.new_sensor(config[CONF_POWER_USAGE]) cg.add(var.set_power_sensor(sens)) if CONF_HUMIDITY_SETPOINT in config: sens = await sensor.new_sensor(config[CONF_HUMIDITY_SETPOINT]) cg.add(var.set_humidity_setpoint_sensor(sens)) cg.add_library("dudanov/MideaUART", "1.1.8")
async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await setup_entity(var, config) await cg.register_component(var, config) for key, setter in SETTERS.items(): if key in config: cg.add(getattr(var, setter)(config[key])) extclk = config[CONF_EXTERNAL_CLOCK] cg.add(var.set_external_clock(extclk[CONF_PIN], extclk[CONF_FREQUENCY])) i2c_pins = config[CONF_I2C_PINS] cg.add(var.set_i2c_pins(i2c_pins[CONF_SDA], i2c_pins[CONF_SCL])) cg.add(var.set_max_update_interval(1000 / config[CONF_MAX_FRAMERATE])) if config[CONF_IDLE_FRAMERATE] == 0: cg.add(var.set_idle_update_interval(0)) else: cg.add(var.set_idle_update_interval(1000 / config[CONF_IDLE_FRAMERATE])) cg.add(var.set_frame_size(config[CONF_RESOLUTION])) cg.add_define("USE_ESP32_CAMERA") cg.add_build_flag("-DBOARD_HAS_PSRAM") if CORE.using_esp_idf: cg.add_library("espressif/esp32-camera", "1.0.0") add_idf_sdkconfig_option("CONFIG_RTCIO_SUPPORT_RTC_GPIO_DESC", True) add_idf_sdkconfig_option("CONFIG_ESP32_SPIRAM_SUPPORT", True)
async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await uart.register_uart_device(var, config) if CONF_LATITUDE in config: sens = await sensor.new_sensor(config[CONF_LATITUDE]) cg.add(var.set_latitude_sensor(sens)) if CONF_LONGITUDE in config: sens = await sensor.new_sensor(config[CONF_LONGITUDE]) cg.add(var.set_longitude_sensor(sens)) if CONF_SPEED in config: sens = await sensor.new_sensor(config[CONF_SPEED]) cg.add(var.set_speed_sensor(sens)) if CONF_COURSE in config: sens = await sensor.new_sensor(config[CONF_COURSE]) cg.add(var.set_course_sensor(sens)) if CONF_ALTITUDE in config: sens = await sensor.new_sensor(config[CONF_ALTITUDE]) cg.add(var.set_altitude_sensor(sens)) if CONF_SATELLITES in config: sens = await sensor.new_sensor(config[CONF_SATELLITES]) cg.add(var.set_satellites_sensor(sens)) # https://platformio.org/lib/show/1655/TinyGPSPlus cg.add_library("1655", "1.0.2") # TinyGPSPlus, has name conflict
async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) cg.add(var.set_port(config[CONF_PORT])) cg.add(var.set_password(config[CONF_PASSWORD])) cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT])) for conf in config.get(CONF_SERVICES, []): template_args = [] func_args = [] service_arg_names = [] for name, var_ in conf[CONF_VARIABLES].items(): native = SERVICE_ARG_NATIVE_TYPES[var_] template_args.append(native) func_args.append((native, name)) service_arg_names.append(name) templ = cg.TemplateArguments(*template_args) trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], templ, conf[CONF_SERVICE], service_arg_names) cg.add(var.register_user_service(trigger)) await automation.build_automation(trigger, func_args, conf) if CONF_ENCRYPTION in config: conf = config[CONF_ENCRYPTION] decoded = base64.b64decode(conf[CONF_KEY]) cg.add(var.set_noise_psk(list(decoded))) cg.add_define("USE_API_NOISE") cg.add_library("esphome/noise-c", "0.1.4") else: cg.add_define("USE_API_PLAINTEXT") cg.add_define("USE_API") cg.add_global(api_ns.using)
def to_code(config): if CORE.is_esp32: # https://github.com/OttoWinter/AsyncTCP/blob/master/library.json cg.add_library('AsyncTCP-esphome', '1.1.1') elif CORE.is_esp8266: # https://github.com/OttoWinter/ESPAsyncTCP cg.add_library('ESPAsyncTCP-esphome', '1.2.2')
def to_code(config): if CORE.is_esp32: # https://github.com/me-no-dev/AsyncTCP/blob/master/library.json cg.add_library('AsyncTCP', '1.0.3') elif CORE.is_esp8266: # https://github.com/me-no-dev/ESPAsyncTCP/blob/master/library.json cg.add_library('ESPAsyncTCP', '1.2.0')
async def to_code(config): if CORE.is_esp8266: cg.add_library("ESPAsyncUDP", "") var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) for plug_config in config[CONF_PLUGS]: plug_var = cg.new_Pvariable(plug_config[CONF_ID]) cg.add(plug_var.set_name(plug_config[CONF_NAME])) if CONF_POWER_SENSOR in plug_config: power_sensor = await cg.get_variable(plug_config[CONF_POWER_SENSOR] ) cg.add(plug_var.set_power_sensor(power_sensor)) if CONF_CURRENT_SENSOR in plug_config: current_sensor = await cg.get_variable( plug_config[CONF_CURRENT_SENSOR]) cg.add(plug_var.set_current_sensor(current_sensor)) if CONF_VOLTAGE_SENSOR in plug_config: voltage_sensor = await cg.get_variable( plug_config[CONF_VOLTAGE_SENSOR]) cg.add(plug_var.set_voltage_sensor(voltage_sensor)) if CONF_MAC_ADDRESS in plug_config: cg.add(plug_var.set_mac_address(plug_config[CONF_MAC_ADDRESS])) cg.add(plug_var.set_voltage(plug_config[CONF_VOLTAGE])) cg.add(plug_var.set_encrypt(plug_config[CONF_ENCRYPT])) cg.add(var.addPlug(plug_var))
def to_code(config): cg.add_global(cg.global_ns.namespace('esphome').using) 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(f'-Wl,-T{ld_script}') cg.add_build_flag('-fno-exceptions') # Libraries if CORE.is_esp32: 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])
async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await i2c.register_i2c_device(var, config) if CONF_PM_1_0 in config: sens = await sensor.new_sensor(config[CONF_PM_1_0]) cg.add(var.set_pm_1_0_sensor(sens)) if CONF_PM_2_5 in config: sens = await sensor.new_sensor(config[CONF_PM_2_5]) cg.add(var.set_pm_2_5_sensor(sens)) if CONF_PM_10_0 in config: sens = await sensor.new_sensor(config[CONF_PM_10_0]) cg.add(var.set_pm_10_0_sensor(sens)) if CONF_AQI in config: sens = await sensor.new_sensor(config[CONF_AQI]) cg.add(var.set_aqi_sensor(sens)) cg.add( var.set_aqi_calculation_type( config[CONF_AQI][CONF_CALCULATION_TYPE])) # https://platformio.org/lib/show/6306/Grove%20-%20Laser%20PM2.5%20Sensor%20HM3301 cg.add_library("6306", "1.0.3")
async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await spi.register_spi_device(var, config) if CORE.is_esp32: cg.add_library("SPI", None)
async def to_code(config): has_white = "W" in config[CONF_TYPE] method = config[CONF_METHOD] method_template = METHODS[method[CONF_TYPE]].to_code( method, config[CONF_VARIANT], config[CONF_INVERT] ) if has_white: out_type = NeoPixelRGBWLightOutput.template(method_template) else: out_type = NeoPixelRGBLightOutput.template(method_template) rhs = out_type.new() var = cg.Pvariable(config[CONF_OUTPUT_ID], rhs, out_type) await light.register_light(var, config) await cg.register_component(var, config) if CONF_PIN in config: cg.add(var.add_leds(config[CONF_NUM_LEDS], config[CONF_PIN])) else: cg.add( var.add_leds( config[CONF_NUM_LEDS], config[CONF_CLOCK_PIN], config[CONF_DATA_PIN] ) ) cg.add(var.set_pixel_order(getattr(ESPNeoPixelOrder, config[CONF_TYPE]))) # https://github.com/Makuna/NeoPixelBus/blob/master/library.json cg.add_library("makuna/NeoPixelBus", "2.6.9")
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) cg.add(var.set_use_address(config[CONF_USE_ADDRESS])) for network in config.get(CONF_NETWORKS, []): cg.add(var.add_sta(wifi_network(network, config.get(CONF_MANUAL_IP)))) if CONF_AP in config: conf = config[CONF_AP] ip_config = conf.get(CONF_MANUAL_IP, config.get(CONF_MANUAL_IP)) cg.add(var.set_ap(wifi_network(conf, ip_config))) cg.add(var.set_ap_timeout(conf[CONF_AP_TIMEOUT])) cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT])) cg.add(var.set_power_save_mode(config[CONF_POWER_SAVE_MODE])) cg.add(var.set_fast_connect(config[CONF_FAST_CONNECT])) if CONF_OUTPUT_POWER in config: cg.add(var.set_output_power(config[CONF_OUTPUT_POWER])) if CORE.is_esp8266: cg.add_library("ESP8266WiFi", None) cg.add_define("USE_WIFI") if config[CONF_ENABLE_MDNS]: add_mdns_library() # Register at end for OTA safe mode 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) # https://platformio.org/lib/show/1655/TinyGPSPlus cg.add_library('TinyGPSPlus', '1.0.2')
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) parent = yield cg.get_variable(config[CONF_MQTT_PARENT_ID]) cg.add(var.set_parent(parent)) cg.add(var.set_topic(config[CONF_TOPIC])) if CONF_QOS in config: cg.add(var.set_qos(config[CONF_QOS])) for conf in config.get(CONF_ON_END, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) yield cg.register_component(trigger, conf) yield cg.register_parented(trigger, var) cg.add(trigger.set_testState(True)) yield automation.build_automation(trigger, [], conf) for conf in config.get(CONF_ON_START, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) yield cg.register_component(trigger, conf) yield cg.register_parented(trigger, var) cg.add(trigger.set_testState(False)) yield automation.build_automation(trigger, [], conf)
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) cg.add(var.set_port(config[CONF_PORT])) cg.add(var.set_password(config[CONF_PASSWORD])) cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT])) for conf in config.get(CONF_SERVICES, []): template_args = [] func_args = [] service_type_args = [] for name, var_ in conf[CONF_VARIABLES].items(): native = SERVICE_ARG_NATIVE_TYPES[var_] template_args.append(native) func_args.append((native, name)) service_type_args.append( ServiceTypeArgument(name, SERVICE_ARG_TYPES[var_])) templ = cg.TemplateArguments(*template_args) trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], templ, conf[CONF_SERVICE], service_type_args) cg.add(var.register_user_service(trigger)) yield automation.build_automation(trigger, func_args, conf) cg.add_define('USE_API') if CORE.is_esp32: cg.add_library('AsyncTCP', '1.0.3') elif CORE.is_esp8266: cg.add_library('ESPAsyncTCP', '1.2.0')
async def to_code(config): cg.add_global(cg.global_ns.namespace("esphome").using) cg.add( cg.App.pre_setup( config[CONF_NAME], cg.RawExpression('__DATE__ ", " __TIME__'), config[CONF_NAME_ADD_MAC_SUFFIX], )) CORE.add_job(_add_automations, config) # Set LWIP build constants for ESP8266 if CORE.is_esp8266: CORE.add_job(_esp8266_add_lwip_type) cg.add_build_flag("-fno-exceptions") # Libraries 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])
async def to_code(config): uart_component = await cg.get_variable(config[CONF_UART_ID]) var = cg.new_Pvariable(config[CONF_ID], uart_component, config[CONF_CRC_CHECK]) cg.add(var.set_max_telegram_length(config[CONF_MAX_TELEGRAM_LENGTH])) if CONF_DECRYPTION_KEY in config: cg.add(var.set_decryption_key(config[CONF_DECRYPTION_KEY])) await cg.register_component(var, config) if CONF_REQUEST_PIN in config: request_pin = await cg.gpio_pin_expression(config[CONF_REQUEST_PIN]) cg.add(var.set_request_pin(request_pin)) cg.add( var.set_request_interval( config[CONF_REQUEST_INTERVAL].total_milliseconds)) cg.add( var.set_receive_timeout( config[CONF_RECEIVE_TIMEOUT].total_milliseconds)) cg.add_build_flag("-DDSMR_GAS_MBUS_ID=" + str(config[CONF_GAS_MBUS_ID])) # DSMR Parser cg.add_library("glmnet/Dsmr", "0.5") # Crypto cg.add_library("rweather/Crypto", "0.4.0")
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) if CORE.is_esp32: cg.add_library('FS', None) # https://github.com/me-no-dev/ESPAsyncWebServer/blob/master/library.json cg.add_library('ESP Async WebServer', '1.2.2')
async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) if CORE.is_esp32: cg.add_library("FS", None) # https://github.com/esphome/ESPAsyncWebServer/blob/master/library.json cg.add_library("esphome/ESPAsyncWebServer-esphome", "1.3.0")
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) if CONF_PRINTER_NAME in config: cg.add(var.setPrinterName(config[CONF_PRINTER_NAME])) yield cg.register_component(var, config) yield GCodeQueue.register_gcode_analyzer(var, config) cg.add_library("ArduinoJson-esphomelib", "6.15.2")
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) if CORE.is_esp32: cg.add_library("FS", None) # https://github.com/OttoWinter/ESPAsyncWebServer/blob/master/library.json cg.add_library("ESPAsyncWebServer-esphome", "1.2.7")
def to_code(config): if CORE.is_esp8266: cg.add_library('ESP8266WiFi', None) var = cg.new_Pvariable(config[ehc.CONF_ID]) for conf in config.get("subscribe", []): yield subscribe_to_code(var, conf) yield cg.register_component(var, config) yield var
async def to_code(config): cg.add_library("wjtje/qr-code-generator-library", "^1.7.0") var = cg.new_Pvariable(config[CONF_ID]) cg.add(var.set_value(config[CONF_VALUE])) cg.add(var.set_ecc(ECC[config[CONF_ECC]])) await cg.register_component(var, config) cg.add_define("USE_QR_CODE")
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield sensor.register_sensor(var, config) cg.add_library('EmonLib', '1.1.0') cg.add(var.set_pin(config[CONF_PIN])) cg.add(var.set_conf_calibration(config[CONF_CALIBRATION])) cg.add(var.set_conf_number_of_samples(config[CONF_NUMBER_OF_SAMPLES])) cg.add(var.set_conf_frequency(config[CONF_FREQUENCY])) cg.add(var.set_conf_phase_shift(config[CONF_PHASE_SHIFT]))
def to_code(config): cg.add_global(i2c_ns.using) var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) cg.add(var.set_sda_pin(config[CONF_SDA])) cg.add(var.set_scl_pin(config[CONF_SCL])) cg.add(var.set_frequency(int(config[CONF_FREQUENCY]))) cg.add(var.set_scan(config[CONF_SCAN])) cg.add_library("Wire", None)
def new_fastled_light(config): var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) yield cg.register_component(var, config) if CONF_MAX_REFRESH_RATE in config: cg.add(var.set_max_refresh_rate(config[CONF_MAX_REFRESH_RATE])) yield light.register_light(var, config) # https://github.com/FastLED/FastLED/blob/master/library.json cg.add_library('FastLED', '3.2.9') yield var
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) clk_pin = yield cg.gpio_pin_expression(config[CONF_CLK_PIN]) cg.add(var.set_clk_pin(clk_pin)) dio_pin = yield cg.gpio_pin_expression(config[CONF_DIO_PIN]) cg.add(var.set_dio_pin(dio_pin)) # https://platformio.org/lib/show/6865/TM1651 cg.add_library('6865', '1.0.0')
def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) cg.add(var.set_port(config[CONF_PORT])) cg.add(var.set_css_url(config[CONF_CSS_URL])) cg.add(var.set_js_url(config[CONF_JS_URL])) if CORE.is_esp32: cg.add_library('FS', None) cg.add_library('ESP Async WebServer', '1.1.1')
async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) clk_pin = await cg.gpio_pin_expression(config[CONF_CLK_PIN]) cg.add(var.set_clk_pin(clk_pin)) dio_pin = await cg.gpio_pin_expression(config[CONF_DIO_PIN]) cg.add(var.set_dio_pin(dio_pin)) # https://platformio.org/lib/show/6865/TM1651 cg.add_library("freekode/TM1651", "1.0.1")