Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
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, config)
    setup_component(light_struct.Pstate, config)
Exemple #5
0
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)
Exemple #6
0
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)
Exemple #7
0
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)
Exemple #8
0
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]))
Exemple #9
0
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)
Exemple #10
0
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)
Exemple #11
0
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)
Exemple #12
0
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)
Exemple #13
0
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)
Exemple #14
0
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)
Exemple #15
0
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)
Exemple #16
0
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)
Exemple #17
0
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)
Exemple #18
0
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)
Exemple #19
0
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)
Exemple #20
0
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)
Exemple #21
0
def to_code(config):
    rhs = App.make_sht3xd_sensor(config[CONF_TEMPERATURE][CONF_NAME],
                                 config[CONF_HUMIDITY][CONF_NAME],
                                 config[CONF_ADDRESS],
                                 config.get(CONF_UPDATE_INTERVAL))
    sht3xd = Pvariable(config[CONF_ID], rhs)

    sensor.setup_sensor(sht3xd.Pget_temperature_sensor(), config[CONF_TEMPERATURE])
    sensor.setup_sensor(sht3xd.Pget_humidity_sensor(), config[CONF_HUMIDITY])
    setup_component(sht3xd, config)
Exemple #22
0
def to_code(config):
    rhs = App.make_sntp_component()
    sntp = Pvariable(config[CONF_ID], rhs)
    if CONF_SERVERS in config:
        servers = config[CONF_SERVERS]
        servers += [''] * (3 - len(servers))
        add(sntp.set_servers(*servers))

    time_.setup_time(sntp, config)
    setup_component(sntp, config)
Exemple #23
0
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_max31855_sensor(config[CONF_NAME], spi_, cs,
                                   config.get(CONF_UPDATE_INTERVAL))
    max31855 = Pvariable(config[CONF_ID], rhs)
    sensor.setup_sensor(max31855, config)
    setup_component(max31855, config)
Exemple #24
0
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)
Exemple #25
0
def to_code(config):
    rhs = App.init_uart(config[CONF_BAUD_RATE])
    var = Pvariable(config[CONF_ID], rhs)

    if CONF_TX_PIN in config:
        add(var.set_tx_pin(config[CONF_TX_PIN]))
    if CONF_RX_PIN in config:
        add(var.set_rx_pin(config[CONF_RX_PIN]))

    setup_component(var, config)
Exemple #26
0
def to_code(config):
    frequency = config.get(CONF_FREQUENCY)
    if frequency is None and CONF_BIT_DEPTH in config:
        frequency = 1000
    rhs = App.make_ledc_output(config[CONF_PIN], frequency,
                               config.get(CONF_BIT_DEPTH))
    ledc = Pvariable(config[CONF_ID], rhs)
    if CONF_CHANNEL in config:
        add(ledc.set_channel(config[CONF_CHANNEL]))
    output.setup_output_platform(ledc, config)
    setup_component(ledc, config)
Exemple #27
0
def to_code(config):
    for template_ in process_lambda(
            config[CONF_LAMBDA], [],
            return_type=std_vector.template(ComponentPtr)):
        yield

    rhs = CustomComponentConstructor(template_)
    custom = variable(config[CONF_ID], rhs)
    for i, comp_config in enumerate(config.get(CONF_COMPONENTS, [])):
        comp = Pvariable(comp_config[CONF_ID], custom.get_component(i))
        setup_component(comp, comp_config)
Exemple #28
0
def to_code(config):
    for red in get_variable(config[CONF_RED]):
        yield
    for green in get_variable(config[CONF_GREEN]):
        yield
    for blue in get_variable(config[CONF_BLUE]):
        yield
    rhs = App.make_rgb_light(config[CONF_NAME], red, green, blue)
    light_struct = variable(config[CONF_MAKE_ID], rhs)
    light.setup_light(light_struct.Pstate, config)
    setup_component(light_struct.Pstate, config)
Exemple #29
0
def to_code(config):
    uuid = config[CONF_UUID].hex
    uuid_arr = [RawExpression('0x{}'.format(uuid[i:i + 2])) for i in range(0, len(uuid), 2)]
    rhs = App.make_esp32_ble_beacon(uuid_arr)
    ble = Pvariable(config[CONF_ID], rhs)
    if CONF_MAJOR in config:
        add(ble.set_major(config[CONF_MAJOR]))
    if CONF_MINOR in config:
        add(ble.set_minor(config[CONF_MINOR]))

    setup_component(ble, config)
Exemple #30
0
def to_code(config):
    pin = config[CONF_PIN]
    if pin == 'VCC':
        pin = 0
    rhs = App.make_adc_sensor(config[CONF_NAME], pin,
                              config.get(CONF_UPDATE_INTERVAL))
    adc = Pvariable(config[CONF_ID], rhs)
    if CONF_ATTENUATION in config:
        add(adc.set_attenuation(ATTENUATION_MODES[config[CONF_ATTENUATION]]))
    sensor.setup_sensor(adc, config)
    setup_component(adc, config)