コード例 #1
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)
コード例 #2
0
ファイル: pca9685.py プロジェクト: lanbing8023/esphome-tools
def to_code(config):
    power_supply = None
    if CONF_POWER_SUPPLY in config:
        for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
            yield
    for pca9685 in get_variable(config[CONF_PCA9685_ID]):
        yield
    rhs = pca9685.create_channel(config[CONF_CHANNEL], power_supply)
    out = Pvariable(config[CONF_ID], rhs)
    output.setup_output_platform(out, config, skip_power_supply=True)
コード例 #3
0
ファイル: cwww.py プロジェクト: liuse2ee/esphome-tools-dc1
def to_code(config):
    for cold_white in get_variable(config[CONF_COLD_WHITE]):
        yield
    for warm_white in get_variable(config[CONF_WARM_WHITE]):
        yield
    rhs = App.make_cwww_light(config[CONF_NAME], config[CONF_COLD_WHITE_COLOR_TEMPERATURE],
                              config[CONF_WARM_WHITE_COLOR_TEMPERATURE],
                              cold_white, warm_white)
    light_struct = variable(config[CONF_MAKE_ID], rhs)
    light.setup_light(light_struct.Pstate, config)
    setup_component(light_struct.Pstate, config)
コード例 #4
0
ファイル: rgb.py プロジェクト: lanbing8023/esphome-tools
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)
コード例 #5
0
ファイル: my9231.py プロジェクト: lanbing8023/esphome-tools
def to_code(config):
    power_supply = None
    if CONF_POWER_SUPPLY in config:
        for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
            yield
    my9231 = None
    for my9231 in get_variable(config[CONF_MY9231_ID]):
        yield
    rhs = my9231.create_channel(config[CONF_CHANNEL], power_supply)
    out = Pvariable(config[CONF_ID], rhs)
    output.setup_output_platform(out, config, skip_power_supply=True)
    setup_component(out, config)
コード例 #6
0
ファイル: binary.py プロジェクト: lanbing8023/esphome-tools
def to_code(config):
    for output_ in get_variable(config[CONF_OUTPUT]):
        yield

    rhs = App.make_fan(config[CONF_NAME])
    fan_struct = variable(config[CONF_MAKE_ID], rhs)
    add(fan_struct.Poutput.set_binary(output_))
    if CONF_OSCILLATION_OUTPUT in config:
        for oscillation_output in get_variable(
                config[CONF_OSCILLATION_OUTPUT]):
            yield
        add(fan_struct.Poutput.set_oscillation(oscillation_output))

    fan.setup_fan(fan_struct.Pstate, config)
    setup_component(fan_struct.Poutput, config)
コード例 #7
0
ファイル: binary.py プロジェクト: liuse2ee/esphome-tools-dc1
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)
コード例 #8
0
def to_code(config):
    for hub in get_variable(config[CONF_ESP32_BLE_ID]):
        yield
    rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
    dev = Pvariable(config[CONF_ID], rhs)
    if CONF_TEMPERATURE in config:
        conf = config[CONF_TEMPERATURE]
        sensor.register_sensor(dev.Pmake_temperature_sensor(conf[CONF_NAME]),
                               conf)
    if CONF_MOISTURE in config:
        conf = config[CONF_MOISTURE]
        sensor.register_sensor(dev.Pmake_moisture_sensor(conf[CONF_NAME]),
                               conf)
    if CONF_ILLUMINANCE in config:
        conf = config[CONF_ILLUMINANCE]
        sensor.register_sensor(dev.Pmake_illuminance_sensor(conf[CONF_NAME]),
                               conf)
    if CONF_CONDUCTIVITY in config:
        conf = config[CONF_CONDUCTIVITY]
        sensor.register_sensor(dev.Pmake_conductivity_sensor(conf[CONF_NAME]),
                               conf)
    if CONF_BATTERY_LEVEL in config:
        conf = config[CONF_BATTERY_LEVEL]
        sensor.register_sensor(dev.Pmake_battery_level_sensor(conf[CONF_NAME]),
                               conf)
コード例 #9
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)
コード例 #10
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)
コード例 #11
0
def to_code(config):
    for remote in get_variable(config[CONF_REMOTE_RECEIVER_ID]):
        yield
    rhs = receiver_base(config)
    receiver = Pvariable(config[CONF_RECEIVER_ID], rhs)

    binary_sensor.register_binary_sensor(remote.add_decoder(receiver), config)
コード例 #12
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_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)
コード例 #13
0
def to_code(config):
    for hub in get_variable(config[CONF_ADS1115_ID]):
        yield

    mux = MUX[config[CONF_MULTIPLEXER]]
    gain = GAIN[config[CONF_GAIN]]
    rhs = hub.get_sensor(config[CONF_NAME], mux, gain, config.get(CONF_UPDATE_INTERVAL))
    sensor.register_sensor(rhs, config)
コード例 #14
0
def to_code(config):
    hub = None
    for hub in get_variable(config[CONF_ESP32_TOUCH_ID]):
        yield
    touch_pad = TOUCH_PADS[config[CONF_PIN]]
    rhs = hub.make_touch_pad(config[CONF_NAME], touch_pad,
                             config[CONF_THRESHOLD])
    binary_sensor.register_binary_sensor(rhs, config)
コード例 #15
0
ファイル: output.py プロジェクト: lanbing8023/esphome-tools
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)
コード例 #16
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
    for cold_white in get_variable(config[CONF_COLD_WHITE]):
        yield
    for warm_white in get_variable(config[CONF_WARM_WHITE]):
        yield
    rhs = App.make_rgbww_light(config[CONF_NAME], config[CONF_COLD_WHITE_COLOR_TEMPERATURE],
                               config[CONF_WARM_WHITE_COLOR_TEMPERATURE],
                               red, green, blue, cold_white, warm_white)
    light_struct = variable(config[CONF_MAKE_ID], rhs)
    light.setup_light(light_struct.Pstate, config)
    setup_component(light_struct.Pstate, config)
コード例 #17
0
ファイル: uart.py プロジェクト: liuse2ee/esphome-tools-dc1
def to_code(config):
    for uart_ in get_variable(config[CONF_UART_ID]):
        yield
    data = config[CONF_DATA]
    if isinstance(data, str):
        data = [HexInt(ord(x)) for x in data]
    rhs = App.make_uart_switch(uart_, config[CONF_NAME], data)
    var = Pvariable(config[CONF_ID], rhs)
    switch.setup_switch(var, config)
コード例 #18
0
def text_sensor_template_publish_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_text_sensor_publish_action(template_arg)
    type = TextSensorPublishAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_STATE], args, std_string):
        yield None
    add(action.set_state(template_))
    yield action
コード例 #19
0
def switch_template_publish_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_switch_publish_action(template_arg)
    type = SwitchPublishAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_STATE], args, bool_):
        yield None
    add(action.set_state(template_))
    yield action
コード例 #20
0
ファイル: max6675.py プロジェクト: liuse2ee/esphome-tools-dc1
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)
コード例 #21
0
def stepper_set_target_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_set_target_action(template_arg)
    type = SetTargetAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_TARGET], args, int32):
        yield None
    add(action.set_target(template_))
    yield action
コード例 #22
0
ファイル: __init__.py プロジェクト: lanbing8023/esphome-tools
def setup_output_platform_(obj, config, skip_power_supply=False):
    if CONF_INVERTED in config:
        add(obj.set_inverted(config[CONF_INVERTED]))
    if not skip_power_supply and CONF_POWER_SUPPLY in config:
        power_supply = None
        for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
            yield
        add(obj.set_power_supply(power_supply))
    if CONF_MAX_POWER in config:
        add(obj.set_max_power(config[CONF_MAX_POWER]))
コード例 #23
0
def stepper_report_position_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_report_position_action(template_arg)
    type = ReportPositionAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_POSITION], args, int32):
        yield None
    add(action.set_position(template_))
    yield action
コード例 #24
0
ファイル: __init__.py プロジェクト: lanbing8023/esphome-tools
def output_set_level_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_set_level_action(template_arg)
    type = SetLevelAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_LEVEL], arg_type, float_):
        yield None
    add(action.set_level(template_))
    yield action
コード例 #25
0
def sensor_template_publish_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_sensor_publish_action(template_arg)
    type = SensorPublishAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_STATE], arg_type, float_):
        yield None
    add(action.set_state(template_))
    yield action
コード例 #26
0
ファイル: servo.py プロジェクト: liuse2ee/esphome-tools-dc1
def servo_write_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = ServoWriteAction.new(template_arg, var)
    type = ServoWriteAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_LEVEL], args, float_):
        yield None
    add(action.set_value(template_))
    yield action
コード例 #27
0
def to_code(config):
    for hub in get_variable(config[CONF_DALLAS_ID]):
        yield
    if CONF_ADDRESS in config:
        address = HexIntLiteral(config[CONF_ADDRESS])
        rhs = hub.Pget_sensor_by_address(config[CONF_NAME], address,
                                         config.get(CONF_RESOLUTION))
    else:
        rhs = hub.Pget_sensor_by_index(config[CONF_NAME], config[CONF_INDEX],
                                       config.get(CONF_RESOLUTION))
    sensor.register_sensor(rhs, config)
コード例 #28
0
ファイル: partition.py プロジェクト: yancheng278/esphome
def to_code(config):
    segments = []
    for conf in config[CONF_SEGMENTS]:
        for var in get_variable(conf[CONF_ID]):
            yield
        segments.append(
            AddressableSegment(var, conf[CONF_FROM],
                               conf[CONF_TO] - conf[CONF_FROM] + 1))

    rhs = App.make_partition_light(config[CONF_NAME], segments)
    make = variable(config[CONF_MAKE_ID], rhs)
    light.setup_light(make.Pstate, config)
コード例 #29
0
def display_page_show_to_code(config, action_id, template_arg, args):
    type = DisplayPageShowAction.template(template_arg)
    action = Pvariable(action_id, type.new(), type=type)
    if isinstance(config[CONF_ID], core.Lambda):
        for template_ in templatable(config[CONF_ID], args, DisplayPagePtr):
            yield None
        add(action.set_page(template_))
    else:
        for var in get_variable(config[CONF_ID]):
            yield None
        add(action.set_page(var))
    yield action
コード例 #30
0
ファイル: speed.py プロジェクト: liuse2ee/esphome-tools-dc1
def to_code(config):
    for output_ in get_variable(config[CONF_OUTPUT]):
        yield
    rhs = App.make_fan(config[CONF_NAME])
    fan_struct = variable(config[CONF_MAKE_ID], rhs)
    if CONF_SPEED in config:
        speeds = config[CONF_SPEED]
        add(
            fan_struct.Poutput.set_speed(output_, speeds[CONF_LOW],
                                         speeds[CONF_MEDIUM],
                                         speeds[CONF_HIGH]))
    else:
        add(fan_struct.Poutput.set_speed(output_))

    if CONF_OSCILLATION_OUTPUT in config:
        for oscillation_output in get_variable(
                config[CONF_OSCILLATION_OUTPUT]):
            yield
        add(fan_struct.Poutput.set_oscillation(oscillation_output))

    fan.setup_fan(fan_struct.Pstate, config)