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)) bme280 = Pvariable(config[CONF_ID], rhs) 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(), config[CONF_TEMPERATURE]) sensor.setup_sensor(bme280.Pget_pressure_sensor(), config[CONF_PRESSURE]) sensor.setup_sensor(bme280.Pget_humidity_sensor(), config[CONF_HUMIDITY]) setup_component(bme280, 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_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, config) setup_component(fast_led, config)
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): rhs = App.init_api_server() api = Pvariable(config[CONF_ID], rhs) if config[CONF_PORT] != 6053: add(api.set_port(config[CONF_PORT])) if config.get(CONF_PASSWORD): add(api.set_password(config[CONF_PASSWORD])) if CONF_REBOOT_TIMEOUT in config: add(api.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_])) func = api.make_user_service_trigger.template(*template_args) rhs = func(conf[CONF_SERVICE], service_type_args) type_ = UserService.template(*template_args) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs, type=type_) automation.build_automations(trigger, func_args, conf) setup_component(api, config)
def to_code(config): rhs = App.make_template_switch(config[CONF_NAME]) template = Pvariable(config[CONF_ID], rhs) switch.setup_switch(template, 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_automations(template.get_turn_off_trigger(), [], config[CONF_TURN_OFF_ACTION]) if CONF_TURN_ON_ACTION in config: automation.build_automations(template.get_turn_on_trigger(), [], config[CONF_TURN_ON_ACTION]) if CONF_OPTIMISTIC in config: add(template.set_optimistic(config[CONF_OPTIMISTIC])) if CONF_ASSUMED_STATE in config: add(template.set_assumed_state(config[CONF_ASSUMED_STATE])) 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_tcs34725(config.get(CONF_UPDATE_INTERVAL)) tcs = Pvariable(config[CONF_ID], rhs) if CONF_ADDRESS in config: add(tcs.set_address(config[CONF_ADDRESS])) if CONF_INTEGRATION_TIME in config: add( tcs.set_integration_time( TCS34725_INTEGRATION_TIMES[config[CONF_INTEGRATION_TIME]])) if CONF_GAIN in config: add(tcs.set_gain(TCS34725_GAINS[config[CONF_GAIN]])) if CONF_RED_CHANNEL in config: conf = config[CONF_RED_CHANNEL] sensor.register_sensor(tcs.Pmake_red_sensor(conf[CONF_NAME]), conf) if CONF_GREEN_CHANNEL in config: conf = config[CONF_GREEN_CHANNEL] sensor.register_sensor(tcs.Pmake_green_sensor(conf[CONF_NAME]), conf) if CONF_BLUE_CHANNEL in config: conf = config[CONF_BLUE_CHANNEL] sensor.register_sensor(tcs.Pmake_blue_sensor(conf[CONF_NAME]), conf) if CONF_CLEAR_CHANNEL in config: conf = config[CONF_CLEAR_CHANNEL] sensor.register_sensor(tcs.Pmake_clear_sensor(conf[CONF_NAME]), conf) if CONF_ILLUMINANCE in config: conf = config[CONF_ILLUMINANCE] sensor.register_sensor(tcs.Pmake_illuminance_sensor(conf[CONF_NAME]), conf) if CONF_COLOR_TEMPERATURE in config: conf = config[CONF_COLOR_TEMPERATURE] sensor.register_sensor( tcs.Pmake_color_temperature_sensor(conf[CONF_NAME]), conf) setup_component(tcs, 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_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 to_code(config): rhs = App.make_ina3221(config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) ina = Pvariable(config[CONF_ID], rhs) for i, channel in enumerate( [CONF_CHANNEL_1, CONF_CHANNEL_2, CONF_CHANNEL_3]): if channel not in config: continue conf = config[channel] if CONF_SHUNT_RESISTANCE in conf: add(ina.set_shunt_resistance(i, conf[CONF_SHUNT_RESISTANCE])) if CONF_BUS_VOLTAGE in conf: c = conf[CONF_BUS_VOLTAGE] sensor.register_sensor( ina.Pmake_bus_voltage_sensor(i, c[CONF_NAME]), c) if CONF_SHUNT_VOLTAGE in conf: c = conf[CONF_SHUNT_VOLTAGE] sensor.register_sensor( ina.Pmake_shunt_voltage_sensor(i, c[CONF_NAME]), c) if CONF_CURRENT in conf: c = conf[CONF_CURRENT] sensor.register_sensor(ina.Pmake_current_sensor(i, c[CONF_NAME]), c) if CONF_POWER in conf: c = conf[CONF_POWER] sensor.register_sensor(ina.Pmake_power_sensor(i, c[CONF_NAME]), c) setup_component(ina, 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 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): 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_wifi_signal_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) wifi = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(wifi, config) setup_component(wifi, 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 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): 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_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_template_cover(config[CONF_NAME]) var = Pvariable(config[CONF_ID], rhs) cover.setup_cover(var, config) setup_component(var, config) if CONF_LAMBDA in config: for template_ in process_lambda(config[CONF_LAMBDA], [], return_type=optional.template( cover.CoverState)): yield add(var.set_state_lambda(template_)) if CONF_OPEN_ACTION in config: automation.build_automations(var.get_open_trigger(), [], config[CONF_OPEN_ACTION]) if CONF_CLOSE_ACTION in config: automation.build_automations(var.get_close_trigger(), [], config[CONF_CLOSE_ACTION]) if CONF_STOP_ACTION in config: automation.build_automations(var.get_stop_trigger(), [], config[CONF_STOP_ACTION]) if CONF_OPTIMISTIC in config: add(var.set_optimistic(config[CONF_OPTIMISTIC])) if CONF_ASSUMED_STATE in config: add(var.set_assumed_state(config[CONF_ASSUMED_STATE]))
def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_binary_light(config[CONF_NAME], output_) light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config) setup_component(light_struct.Pstate, 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): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_output_switch(config[CONF_NAME], output_) switch_ = Pvariable(config[CONF_ID], rhs) switch.setup_switch(switch_, config) setup_component(switch, config)
def to_code(config): rhs = App.make_bh1750_sensor(config[CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) bh1750 = Pvariable(config[CONF_ID], rhs) if CONF_RESOLUTION in config: add(bh1750.set_resolution(BH1750_RESOLUTIONS[config[CONF_RESOLUTION]])) sensor.setup_sensor(bh1750, config) setup_component(bh1750, config)
def to_code(config): for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_duty_cycle_sensor(config[CONF_NAME], pin, config.get(CONF_UPDATE_INTERVAL)) duty = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(duty, config) setup_component(duty, 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): pin = None for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin) gpio = Pvariable(config[CONF_ID], rhs) binary_sensor.setup_binary_sensor(gpio, config) setup_component(gpio, 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 to_code(config): rhs = App.make_mqtt_subscribe_sensor(config[CONF_NAME], config[CONF_TOPIC]) subs = Pvariable(config[CONF_ID], rhs) if CONF_QOS in config: add(subs.set_qos(config[CONF_QOS])) sensor.setup_sensor(subs, config) setup_component(subs, config)
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_htu21d_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) htu21d = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(htu21d.Pget_temperature_sensor(), config[CONF_TEMPERATURE]) sensor.setup_sensor(htu21d.Pget_humidity_sensor(), config[CONF_HUMIDITY]) setup_component(htu21d, 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 rhs = App.make_max6675_sensor(config[CONF_NAME], spi_, cs, config.get(CONF_UPDATE_INTERVAL)) max6675 = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(max6675, config) setup_component(max6675, config)
def to_code(config): for time_ in get_variable(config[CONF_TIME_ID]): yield for sens in get_variable(config[CONF_POWER_ID]): yield rhs = App.make_total_daily_energy_sensor(config[CONF_NAME], time_, sens) total_energy = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(total_energy, config) setup_component(total_energy, config)