def to_code(config): for pin in gpio_output_pin_expression(config[CONF_PIN]): yield rhs = App.make_gpio_output(pin) gpio = Pvariable(config[CONF_ID], rhs) output.setup_output_platform(gpio, config) setup_component(gpio, config)
def to_code(config): rhs = App.make_esp32_ble_tracker() ble = Pvariable(config[CONF_ID], rhs) if CONF_SCAN_INTERVAL in config: add(ble.set_scan_interval(config[CONF_SCAN_INTERVAL])) setup_component(ble, config)
def to_code(config): rhs = App.make_gpio_lcd_display(config[CONF_DIMENSIONS][0], config[CONF_DIMENSIONS][1]) lcd = Pvariable(config[CONF_ID], rhs) pins_ = [] for conf in config[CONF_DATA_PINS]: for pin in gpio_output_pin_expression(conf): yield pins_.append(pin) add(lcd.set_data_pins(*pins_)) for enable in gpio_output_pin_expression(config[CONF_ENABLE_PIN]): yield add(lcd.set_enable_pin(enable)) for rs in gpio_output_pin_expression(config[CONF_RS_PIN]): yield add(lcd.set_rs_pin(rs)) if CONF_RW_PIN in config: for rw in gpio_output_pin_expression(config[CONF_RW_PIN]): yield add(lcd.set_rw_pin(rw)) if CONF_LAMBDA in config: for lambda_ in process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')], return_type=void): yield add(lcd.set_writer(lambda_)) display.setup_display(lcd, config) setup_component(lcd, config)
def to_code(config): for spi_ in get_variable(config[CONF_SPI_ID]): yield for cs in gpio_output_pin_expression(config[CONF_CS_PIN]): yield for dc in gpio_output_pin_expression(config[CONF_DC_PIN]): yield rhs = App.make_spi_ssd1306(spi_, cs, dc) ssd = Pvariable(config[CONF_ID], rhs) add(ssd.set_model(MODELS[config[CONF_MODEL]])) if CONF_RESET_PIN in config: for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]): yield add(ssd.set_reset_pin(reset)) if CONF_EXTERNAL_VCC in config: add(ssd.set_external_vcc(config[CONF_EXTERNAL_VCC])) if CONF_LAMBDA in config: for lambda_ in process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')], return_type=void): yield add(ssd.set_writer(lambda_)) display.setup_display(ssd, config) setup_component(ssd, config)
def setup_time_core_(time_var, config): add(time_var.set_timezone(config[CONF_TIMEZONE])) for conf in config.get(CONF_ON_TIME, []): rhs = App.register_component(time_var.Pmake_cron_trigger()) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) seconds = conf.get(CONF_SECONDS, [x for x in range(0, 61)]) add(trigger.add_seconds(ArrayInitializer(*seconds, multiline=False))) minutes = conf.get(CONF_MINUTES, [x for x in range(0, 60)]) add(trigger.add_minutes(ArrayInitializer(*minutes, multiline=False))) hours = conf.get(CONF_HOURS, [x for x in range(0, 24)]) add(trigger.add_hours(ArrayInitializer(*hours, multiline=False))) days_of_month = conf.get(CONF_DAYS_OF_MONTH, [x for x in range(1, 32)]) add( trigger.add_days_of_month( ArrayInitializer(*days_of_month, multiline=False))) months = conf.get(CONF_MONTHS, [x for x in range(1, 13)]) add(trigger.add_months(ArrayInitializer(*months, multiline=False))) days_of_week = conf.get(CONF_DAYS_OF_WEEK, [x for x in range(1, 8)]) add( trigger.add_days_of_week( ArrayInitializer(*days_of_week, multiline=False))) automation.build_automation(trigger, NoArg, conf)
def to_code(config): rhs = App.init_wifi() wifi = Pvariable(config[CONF_ID], rhs) for network in config.get(CONF_NETWORKS, []): add(wifi.add_sta(wifi_network(network, config.get(CONF_MANUAL_IP)))) if CONF_AP in config: add( wifi.set_ap( wifi_network(config[CONF_AP], config.get(CONF_MANUAL_IP)))) if CONF_HOSTNAME in config: add(wifi.set_hostname(config[CONF_HOSTNAME])) if CONF_REBOOT_TIMEOUT in config: add(wifi.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT])) if CONF_POWER_SAVE_MODE in config: add( wifi.set_power_save_mode( WIFI_POWER_SAVE_MODES[config[CONF_POWER_SAVE_MODE]])) if CONF_FAST_CONNECT in config: add(wifi.set_fast_connect(config[CONF_FAST_CONNECT]))
def to_code(config): rhs = App.make_esp32_touch_component() touch = Pvariable(config[CONF_ID], rhs) if CONF_SETUP_MODE in config: add(touch.set_setup_mode(config[CONF_SETUP_MODE])) if CONF_IIR_FILTER in config: add(touch.set_iir_filter(config[CONF_IIR_FILTER])) if CONF_SLEEP_DURATION in config: sleep_duration = int(config[CONF_SLEEP_DURATION].total_microseconds * 0.15) add(touch.set_sleep_duration(sleep_duration)) if CONF_MEASUREMENT_DURATION in config: measurement_duration = int( config[CONF_MEASUREMENT_DURATION].total_microseconds * 0.125) add(touch.set_measurement_duration(measurement_duration)) if CONF_LOW_VOLTAGE_REFERENCE in config: value = LOW_VOLTAGE_REFERENCE[config[CONF_LOW_VOLTAGE_REFERENCE]] add(touch.set_low_voltage_reference(value)) if CONF_HIGH_VOLTAGE_REFERENCE in config: value = HIGH_VOLTAGE_REFERENCE[config[CONF_HIGH_VOLTAGE_REFERENCE]] add(touch.set_high_voltage_reference(value)) if CONF_VOLTAGE_ATTENUATION in config: value = VOLTAGE_ATTENUATION[config[CONF_VOLTAGE_ATTENUATION]] add(touch.set_voltage_attenuation(value)) setup_component(touch, config)
def to_code(config): for conf in config: rhs = App.register_component(IntervalTrigger.new(conf[CONF_INTERVAL])) trigger = Pvariable(conf[CONF_ID], rhs) setup_component(trigger, conf) automation.build_automation(trigger, NoArg, conf)
def to_code(config): rhs = App.make_template_switch(config[CONF_NAME]) make = variable(config[CONF_MAKE_ID], rhs) template = make.Ptemplate_ switch.setup_switch(template, make.Pmqtt, config) if CONF_LAMBDA in config: for template_ in process_lambda(config[CONF_LAMBDA], [], return_type=optional.template(bool_)): yield add(template.set_state_lambda(template_)) if CONF_TURN_OFF_ACTION in config: automation.build_automation(template.get_turn_off_trigger(), NoArg, config[CONF_TURN_OFF_ACTION]) if CONF_TURN_ON_ACTION in config: automation.build_automation(template.get_turn_on_trigger(), NoArg, config[CONF_TURN_ON_ACTION]) if CONF_OPTIMISTIC in config: add(template.set_optimistic(config[CONF_OPTIMISTIC])) if CONF_RESTORE_STATE in config: add(template.set_restore_state(config[CONF_RESTORE_STATE])) setup_component(template, config)
def to_code(config): rhs = App.make_bme280_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_PRESSURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) bme280 = make.Pbme280 if CONF_OVERSAMPLING in config[CONF_TEMPERATURE]: constant = OVERSAMPLING_OPTIONS[config[CONF_TEMPERATURE] [CONF_OVERSAMPLING]] add(bme280.set_temperature_oversampling(constant)) if CONF_OVERSAMPLING in config[CONF_PRESSURE]: constant = OVERSAMPLING_OPTIONS[config[CONF_PRESSURE] [CONF_OVERSAMPLING]] add(bme280.set_pressure_oversampling(constant)) if CONF_OVERSAMPLING in config[CONF_HUMIDITY]: constant = OVERSAMPLING_OPTIONS[config[CONF_HUMIDITY] [CONF_OVERSAMPLING]] add(bme280.set_humidity_oversampling(constant)) if CONF_IIR_FILTER in config: constant = IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]] add(bme280.set_iir_filter(constant)) 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]) setup_component(bme280, config)
def to_code(config): for pin in gpio_output_pin_expression(config[CONF_PIN]): yield rhs = App.make_status_led(pin) var = Pvariable(config[CONF_ID], rhs) setup_component(var, config)
def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_monochromatic_light(config[CONF_NAME], output_) light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config) setup_component(light_struct.Pstate, config)
def to_code(config): for uart_ in get_variable(config[CONF_UART_ID]): yield rhs = App.make_pmsx003(uart_, PMSX003_TYPES[config[CONF_TYPE]]) pms = Pvariable(config[CONF_ID], rhs) if CONF_PM_1_0 in config: conf = config[CONF_PM_1_0] sensor.register_sensor(pms.make_pm_1_0_sensor(conf[CONF_NAME]), conf) if CONF_PM_2_5 in config: conf = config[CONF_PM_2_5] sensor.register_sensor(pms.make_pm_2_5_sensor(conf[CONF_NAME]), conf) if CONF_PM_10_0 in config: conf = config[CONF_PM_10_0] sensor.register_sensor(pms.make_pm_10_0_sensor(conf[CONF_NAME]), conf) if CONF_TEMPERATURE in config: conf = config[CONF_TEMPERATURE] sensor.register_sensor(pms.make_temperature_sensor(conf[CONF_NAME]), conf) if CONF_HUMIDITY in config: conf = config[CONF_HUMIDITY] sensor.register_sensor(pms.make_humidity_sensor(conf[CONF_NAME]), conf) if CONF_FORMALDEHYDE in config: conf = config[CONF_FORMALDEHYDE] sensor.register_sensor(pms.make_formaldehyde_sensor(conf[CONF_NAME]), conf) setup_component(pms, config)
def to_code(config): rhs = App.make_mpu6050_sensor(config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) mpu = Pvariable(config[CONF_ID], rhs) if CONF_ACCEL_X in config: conf = config[CONF_ACCEL_X] rhs = mpu.Pmake_accel_x_sensor(conf[CONF_NAME]) 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]) 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]) 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]) 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]) 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]) sensor.register_sensor(rhs, conf) if CONF_TEMPERATURE in config: conf = config[CONF_TEMPERATURE] rhs = mpu.Pmake_temperature_sensor(conf[CONF_NAME]) sensor.register_sensor(rhs, conf) setup_component(mpu, config)
def to_code(config): rhs = App.make_fast_led_light(config[CONF_NAME]) make = variable(config[CONF_MAKE_ID], rhs) fast_led = make.Pfast_led rgb_order = None if CONF_RGB_ORDER in config: rgb_order = RawExpression(config[CONF_RGB_ORDER]) template_args = TemplateArguments(RawExpression(config[CONF_CHIPSET]), config[CONF_DATA_PIN], config[CONF_CLOCK_PIN], rgb_order) add(fast_led.add_leds(template_args, config[CONF_NUM_LEDS])) if CONF_MAX_REFRESH_RATE in config: add(fast_led.set_max_refresh_rate(config[CONF_MAX_REFRESH_RATE])) if CONF_POWER_SUPPLY in config: for power_supply in get_variable(config[CONF_POWER_SUPPLY]): yield add(fast_led.set_power_supply(power_supply)) if CONF_COLOR_CORRECT in config: r, g, b = config[CONF_COLOR_CORRECT] add(fast_led.set_correction(r, g, b)) light.setup_light(make.Pstate, make.Pmqtt, config) setup_component(fast_led, config)
def to_code(config): rhs = App.make_deep_sleep_component() deep_sleep = Pvariable(config[CONF_ID], rhs) if CONF_SLEEP_DURATION in config: add(deep_sleep.set_sleep_duration(config[CONF_SLEEP_DURATION])) if CONF_WAKEUP_PIN in config: for pin in gpio_input_pin_expression(config[CONF_WAKEUP_PIN]): yield add(deep_sleep.set_wakeup_pin(pin)) if CONF_WAKEUP_PIN_MODE in config: add( deep_sleep.set_wakeup_pin_mode( WAKEUP_PIN_MODES[config[CONF_WAKEUP_PIN_MODE]])) if CONF_RUN_CYCLES in config: add(deep_sleep.set_run_cycles(config[CONF_RUN_CYCLES])) if CONF_RUN_DURATION in config: add(deep_sleep.set_run_duration(config[CONF_RUN_DURATION])) if CONF_ESP32_EXT1_WAKEUP in config: conf = config[CONF_ESP32_EXT1_WAKEUP] mask = 0 for pin in conf[CONF_PINS]: mask |= 1 << pin[CONF_NUMBER] struct = StructInitializer( Ext1Wakeup, ('mask', mask), ('wakeup_mode', EXT1_WAKEUP_MODES[conf[CONF_MODE]])) add(deep_sleep.set_ext1_wakeup(struct)) setup_component(deep_sleep, config)
def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config): if CONF_INTERNAL in config: add(binary_sensor_var.set_internal(CONF_INTERNAL)) if CONF_DEVICE_CLASS in config: add(binary_sensor_var.set_device_class(config[CONF_DEVICE_CLASS])) if CONF_INVERTED in config: add(binary_sensor_var.set_inverted(config[CONF_INVERTED])) if CONF_FILTERS in config: filters = None for filters in setup_filters(config[CONF_FILTERS]): yield add(binary_sensor_var.add_filters(filters)) for conf in config.get(CONF_ON_PRESS, []): rhs = binary_sensor_var.make_press_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) 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) 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) 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) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_MULTI_CLICK, []): timings = [] for tim in conf[CONF_TIMING]: timings.append( StructInitializer( MultiClickTriggerEvent, ('state', tim[CONF_STATE]), ('min_length', tim[CONF_MIN_LENGTH]), ('max_length', tim.get(CONF_MAX_LENGTH, 4294967294)), )) timings = ArrayInitializer(*timings, multiline=False) rhs = App.register_component( binary_sensor_var.make_multi_click_trigger(timings)) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) if CONF_INVALID_COOLDOWN in conf: add(trigger.set_invalid_cooldown(conf[CONF_INVALID_COOLDOWN])) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_STATE, []): rhs = binary_sensor_var.make_state_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, bool_, conf) setup_mqtt_component(mqtt_var, config)
def to_code(config): rhs = App.init_i2c(config[CONF_SDA], config[CONF_SCL], config.get(CONF_SCAN)) i2c = Pvariable(config[CONF_ID], rhs) if CONF_FREQUENCY in config: add(i2c.set_frequency(config[CONF_FREQUENCY])) setup_component(i2c, config)
def to_code(config): rhs = App.make_uptime_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) uptime = make.Puptime sensor.setup_sensor(uptime, make.Pmqtt, config) setup_component(uptime, config)
def to_code(config): rhs = App.make_apds9960(config.get(CONF_UPDATE_INTERVAL)) var = Pvariable(config[CONF_ID], rhs) if CONF_ADDRESS in config: add(var.set_address(config[CONF_ADDRESS])) setup_component(var, config)
def setup_filter(config): if CONF_INVERT in config: yield InvertFilter.new() elif CONF_DELAYED_OFF in config: yield App.register_component( DelayedOffFilter.new(config[CONF_DELAYED_OFF])) elif CONF_DELAYED_ON in config: yield App.register_component( DelayedOnFilter.new(config[CONF_DELAYED_ON])) elif CONF_HEARTBEAT in config: yield App.register_component( HeartbeatFilter.new(config[CONF_HEARTBEAT])) elif CONF_LAMBDA in config: lambda_ = None for lambda_ in process_lambda(config[CONF_LAMBDA], [(bool_, 'x')]): yield None yield LambdaFilter.new(lambda_)
def to_code(config): pin = None for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin) gpio = variable(config[CONF_MAKE_ID], rhs) binary_sensor.setup_binary_sensor(gpio.Pgpio, gpio.Pmqtt, config) setup_component(gpio.Pgpio, config)
def delay_action_to_code(config, action_id, arg_type, template_arg): rhs = App.register_component(DelayAction.new(template_arg)) type = DelayAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config, arg_type, uint32): yield add(action.set_delay(template_)) yield action
def to_code(config): rhs = App.init_ota() ota = Pvariable(config[CONF_ID], rhs) if CONF_PASSWORD in config: add(ota.set_auth_password(config[CONF_PASSWORD])) if CONF_PORT in config: add(ota.set_port(config[CONF_PORT])) if config[CONF_SAFE_MODE]: add(ota.start_safe_mode())
def to_code(config): rhs = App.init_web_server(config.get(CONF_PORT)) web_server = Pvariable(config[CONF_ID], rhs) if CONF_CSS_URL in config: add(web_server.set_css_url(config[CONF_CSS_URL])) if CONF_JS_URL in config: add(web_server.set_js_url(config[CONF_JS_URL])) setup_component(web_server, config)
def to_code(config): rhs = App.make_bh1750_sensor(config[CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) make_bh1750 = variable(config[CONF_MAKE_ID], rhs) bh1750 = make_bh1750.Pbh1750 if CONF_RESOLUTION in config: add(bh1750.set_resolution(BH1750_RESOLUTIONS[config[CONF_RESOLUTION]])) sensor.setup_sensor(bh1750, make_bh1750.Pmqtt, config) setup_component(bh1750, config)
def to_code(config): add(App.set_name(config[CONF_NAME])) for conf in config.get(CONF_ON_BOOT, []): rhs = App.register_component(StartupTrigger.new(conf.get(CONF_PRIORITY))) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_SHUTDOWN, []): trigger = Pvariable(conf[CONF_TRIGGER_ID], ShutdownTrigger.new()) automation.build_automation(trigger, const_char_ptr, conf) for conf in config.get(CONF_ON_LOOP, []): rhs = App.register_component(LoopTrigger.new()) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) add(App.set_compilation_datetime(RawExpression('__DATE__ ", " __TIME__')))
def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_output_switch(config[CONF_NAME], output_) make = variable(config[CONF_MAKE_ID], rhs) switch_ = make.Pswitch_ switch.setup_switch(switch_, make.Pmqtt, config) setup_component(switch, config)
def to_code(config): rhs = App.init_log(config.get(CONF_BAUD_RATE)) log = Pvariable(config[CONF_ID], rhs) if CONF_TX_BUFFER_SIZE in config: add(log.set_tx_buffer_size(config[CONF_TX_BUFFER_SIZE])) if CONF_LEVEL in config: add(log.set_global_log_level(LOG_LEVELS[config[CONF_LEVEL]])) for tag, level in config.get(CONF_LOGS, {}).items(): add(log.set_log_level(tag, LOG_LEVELS[level]))
def to_code(config): for pin in gpio_output_pin_expression(config[CONF_PIN]): yield rhs = App.make_remote_transmitter_component(pin) transmitter = Pvariable(config[CONF_ID], rhs) if CONF_CARRIER_DUTY_PERCENT in config: add(transmitter.set_carrier_duty_percent(config[CONF_CARRIER_DUTY_PERCENT])) setup_component(transmitter, config)