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_LAMBDA in config: for lambda_ in process_lambda(config[CONF_LAMBDA], [(bool_, 'x')], return_type=optional.template(bool_)): yield None yield LambdaFilter.new(lambda_)
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): 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): 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): 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_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_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, config) setup_component(fast_led, 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_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_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_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 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(seconds)) minutes = conf.get(CONF_MINUTES, [x for x in range(0, 60)]) add(trigger.add_minutes(minutes)) hours = conf.get(CONF_HOURS, [x for x in range(0, 24)]) add(trigger.add_hours(hours)) days_of_month = conf.get(CONF_DAYS_OF_MONTH, [x for x in range(1, 32)]) add(trigger.add_days_of_month(days_of_month)) months = conf.get(CONF_MONTHS, [x for x in range(1, 13)]) add(trigger.add_months(months)) days_of_week = conf.get(CONF_DAYS_OF_WEEK, [x for x in range(1, 8)]) add(trigger.add_days_of_week(days_of_week)) automation.build_automations(trigger, [], conf)
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): from PIL import Image path = CORE.relative_path(config[CONF_FILE]) try: image = Image.open(path) except Exception as e: raise core.pi4homeError(u"Could not load image file {}: {}".format(path, e)) if CONF_RESIZE in config: image.thumbnail(config[CONF_RESIZE]) image = image.convert('1', dither=Image.NONE) width, height = image.size if width > 500 or height > 500: _LOGGER.warning("The image you requested is very big. Please consider using the resize " "parameter") width8 = ((width + 7) // 8) * 8 data = [0 for _ in range(height * width8 // 8)] for y in range(height): for x in range(width): if image.getpixel((x, y)): continue pos = x + y * width8 data[pos // 8] |= 0x80 >> (pos % 8) rhs = safe_exp([HexInt(x) for x in data]) prog_arr = progmem_array(config[CONF_RAW_DATA_ID], rhs) rhs = App.make_image(prog_arr, width, height) Pvariable(config[CONF_ID], rhs)
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_automations(trigger, [], conf)
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): 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 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.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): 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 wait_until_action_to_code(config, action_id, template_arg, args): for conditions in build_conditions(config[CONF_CONDITION], template_arg, args): yield None rhs = WaitUntilAction.new(template_arg, conditions) type = WaitUntilAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) add(App.register_component(action)) yield action
def delay_action_to_code(config, action_id, template_arg, args): 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, args, uint32): yield add(action.set_delay(template_)) yield action
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): 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_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): 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_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_dht12_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) dht = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(dht.Pget_temperature_sensor(), config[CONF_TEMPERATURE]) sensor.setup_sensor(dht.Pget_humidity_sensor(), config[CONF_HUMIDITY]) setup_component(dht, 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)