예제 #1
0
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 = variable(MakeHTU21DSensor, config[CONF_MAKE_ID], rhs)
    sensor.setup_sensor(htu21d.Phtu21d.Pget_temperature_sensor(), htu21d.Pmqtt_temperature,
                        config[CONF_TEMPERATURE])
    sensor.setup_sensor(htu21d.Phtu21d.Pget_humidity_sensor(), htu21d.Pmqtt_humidity,
                        config[CONF_HUMIDITY])
예제 #2
0
def to_code(config):
    template_ = None
    for template_ in process_lambda(config[CONF_LAMBDA], [],
                                    return_type=optional.template(float_)):
        yield
    rhs = App.make_template_sensor(config[CONF_NAME], template_,
                                   config.get(CONF_UPDATE_INTERVAL))
    make = variable(config[CONF_MAKE_ID], rhs)
    sensor.setup_sensor(make.Ptemplate_, make.Pmqtt, config)
예제 #3
0
def to_code(config):
    output = get_variable(config[CONF_OUTPUT])
    rhs = App.make_fan(config[CONF_NAME])
    fan_struct = variable('Application::MakeFan', config[CONF_ID], rhs)
    add(fan_struct.Poutput.set_binary(output))
    if CONF_OSCILLATION_OUTPUT in config:
        oscillation_output = get_variable(config[CONF_OSCILLATION_OUTPUT])
        add(fan_struct.Poutput.set_oscillation(oscillation_output))
    fan.setup_mqtt_fan(fan_struct.Pmqtt, config)
예제 #4
0
def delay_action_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    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
예제 #5
0
파일: ota.py 프로젝트: sherrman/esphomeyaml
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())
예제 #6
0
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, {}).iteritems():
        add(log.set_log_level(tag, LOG_LEVELS[level]))
예제 #7
0
def to_code(config):
    for conf in config:
        pin = exp_gpio_output_pin(conf[CONF_PIN])
        rhs = App.make_power_supply(pin)
        psu = Pvariable('PowerSupplyComponent', conf[CONF_ID], rhs)
        if CONF_ENABLE_TIME in conf:
            add(psu.set_enable_time(conf[CONF_ENABLE_TIME]))
        if CONF_KEEP_ON_TIME in conf:
            add(psu.set_keep_on_time(conf[CONF_KEEP_ON_TIME]))
예제 #8
0
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, light_struct.Pmqtt, config)
예제 #9
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)
예제 #10
0
def to_code(config):
    for conf in config:
        rhs = App.make_pca9685_component(conf.get(CONF_FREQUENCY))
        pca9685 = Pvariable(PCA9685_COMPONENT_TYPE, conf[CONF_ID], rhs)
        if CONF_ADDRESS in conf:
            add(pca9685.set_address(HexIntLiteral(conf[CONF_ADDRESS])))
        if CONF_PHASE_BALANCER in conf:
            phase_balancer = RawExpression(u'PCA9685_PhaseBalancer_{}'.format(
                conf[CONF_PHASE_BALANCER]))
            add(pca9685.set_phase_balancer(phase_balancer))
예제 #11
0
def to_code(config):
    rhs = App.make_mqtt_subscribe_sensor(config[CONF_NAME], config[CONF_TOPIC])
    make = variable(config[CONF_MAKE_ID], rhs)
    subs = make.Psensor

    if CONF_QOS in config:
        add(subs.set_qos(config[CONF_QOS]))

    sensor.setup_sensor(subs, make.Pmqtt, config)
    setup_component(subs, config)
예제 #12
0
파일: rgb.py 프로젝트: Landrash/esphomeyaml
def to_code(config):
    red = get_variable(config[CONF_RED])
    green = get_variable(config[CONF_GREEN])
    blue = get_variable(config[CONF_BLUE])
    rhs = App.make_rgb_light(config[CONF_NAME], red, green, blue)
    light_struct = variable('Application::MakeLight', config[CONF_ID], rhs)
    if CONF_GAMMA_CORRECT in config:
        add(light_struct.Poutput.set_gamma_correct(config[CONF_GAMMA_CORRECT]))
    setup_mqtt_component(light_struct.Pmqtt, config)
    light.setup_light_component(light_struct.Pstate, config)
예제 #13
0
파일: ota.py 프로젝트: apeeters/esphome
def to_code(config):
    rhs = App.init_ota()
    ota = Pvariable(config[CONF_ID], rhs)
    if CONF_PASSWORD in config:
        hash_ = hashlib.md5(config[CONF_PASSWORD].encode()).hexdigest()
        add(ota.set_auth_password_hash(hash_))
    if CONF_PORT in config:
        add(ota.set_port(config[CONF_PORT]))
    if config[CONF_SAFE_MODE]:
        add(ota.start_safe_mode())
예제 #14
0
def to_code(config):
    rhs = App.make_adc_sensor(config[CONF_NAME], config[CONF_PIN],
                              config.get(CONF_UPDATE_INTERVAL))
    make = variable('Application::MakeADCSensor', config[CONF_ID], rhs)
    adc = make.Padc
    if CONF_ATTENUATION in config:
        attenuation = ATTENUATION_MODES[config[CONF_ATTENUATION]]
        add(adc.set_attenuation(RawExpression(attenuation)))
    sensor.setup_sensor(adc, config)
    sensor.setup_mqtt_sensor_component(make.Pmqtt, config)
예제 #15
0
def to_code(config):
    rhs = App.make_template_binary_sensor(config[CONF_NAME])
    make = variable(config[CONF_MAKE_ID], rhs)
    binary_sensor.setup_binary_sensor(make.Ptemplate_, make.Pmqtt, config)

    template_ = None
    for template_ in process_lambda(config[CONF_LAMBDA], [],
                                    return_type=optional.template(bool_)):
        yield
    add(make.Ptemplate_.set_template(template_))
예제 #16
0
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_p, 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)

    update_esphomelib_repo(config)
예제 #17
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 = variable(MakeDHT12Sensor, config[CONF_MAKE_ID], rhs)

    sensor.setup_sensor(dht.Pdht.Pget_temperature_sensor(), dht.Pmqtt_temperature,
                        config[CONF_TEMPERATURE])
    sensor.setup_sensor(dht.Pdht.Pget_humidity_sensor(), dht.Pmqtt_humidity,
                        config[CONF_HUMIDITY])
예제 #18
0
def to_code(config):
    rhs = App.make_hdc1080_sensor(config[CONF_TEMPERATURE][CONF_NAME],
                                  config[CONF_HUMIDITY][CONF_NAME],
                                  config.get(CONF_UPDATE_INTERVAL))
    hdc1080 = variable(config[CONF_MAKE_ID], rhs)

    sensor.setup_sensor(hdc1080.Phdc1080.Pget_temperature_sensor(),
                        hdc1080.Pmqtt_temperature, config[CONF_TEMPERATURE])
    sensor.setup_sensor(hdc1080.Phdc1080.Pget_humidity_sensor(),
                        hdc1080.Pmqtt_humidity, config[CONF_HUMIDITY])
예제 #19
0
파일: ledc.py 프로젝트: brandond/esphome
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(LEDCOutputComponent, config[CONF_ID], rhs)
    if CONF_CHANNEL in config:
        add(ledc.set_channel(config[CONF_CHANNEL]))
    output.setup_output_platform(ledc, config)
예제 #20
0
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],
                               ArrayInitializer(*data, multiline=False))
    restart = variable(config[CONF_MAKE_ID], rhs)
    switch.setup_switch(restart.Puart, restart.Pmqtt, config)
예제 #21
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_max6675_sensor(config[CONF_NAME], spi_, cs,
                                  config.get(CONF_UPDATE_INTERVAL))
    make = variable(config[CONF_MAKE_ID], rhs)
    max6675 = make.Pmax6675
    sensor.setup_sensor(max6675, make.Pmqtt, config)
    setup_component(max6675, config)
예제 #22
0
파일: rgb.py 프로젝트: sherrman/esphomeyaml
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, light_struct.Pmqtt, config)
    setup_component(light_struct.Pstate, config)
예제 #23
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 = variable(config[CONF_MAKE_ID], rhs)

    sensor.setup_sensor(sht3xd.Psht3xd.Pget_temperature_sensor(),
                        sht3xd.Pmqtt_temperature, config[CONF_TEMPERATURE])
    sensor.setup_sensor(sht3xd.Psht3xd.Pget_humidity_sensor(),
                        sht3xd.Pmqtt_humidity, config[CONF_HUMIDITY])
예제 #24
0
def register_binary_sensor(var, config):
    binary_sensor_var = Pvariable(BinarySensor,
                                  config[CONF_ID],
                                  var,
                                  has_side_effects=True)
    rhs = App.register_binary_sensor(binary_sensor_var)
    mqtt_var = Pvariable(MQTTBinarySensorComponent,
                         config[CONF_MQTT_ID],
                         rhs,
                         has_side_effects=True)
    setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config)
예제 #25
0
def to_code(config):
    for conf in config:
        pin = None
        for pin in gpio_output_pin_expression(conf[CONF_PIN]):
            yield
        rhs = App.make_power_supply(pin)
        psu = Pvariable(conf[CONF_ID], rhs)
        if CONF_ENABLE_TIME in conf:
            add(psu.set_enable_time(conf[CONF_ENABLE_TIME]))
        if CONF_KEEP_ON_TIME in conf:
            add(psu.set_keep_on_time(conf[CONF_KEEP_ON_TIME]))
예제 #26
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))
    make = variable(config[CONF_MAKE_ID], rhs)
    adc = make.Padc
    if CONF_ATTENUATION in config:
        add(adc.set_attenuation(ATTENUATION_MODES[config[CONF_ATTENUATION]]))
    sensor.setup_sensor(make.Padc, make.Pmqtt, config)
예제 #27
0
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)

    setup_mqtt_component(mqtt_var, config)
예제 #28
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(ArrayInitializer(*uuid_arr, multiline=False))
    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)
예제 #29
0
def to_code(config):
    for conf in config:
        pin = None
        for pin in gpio_output_pin_expression(conf[CONF_PIN]):
            yield
        rhs = App.make_remote_transmitter_component(pin)
        transmitter = Pvariable(conf[CONF_ID], rhs)
        if CONF_CARRIER_DUTY_PERCENT in conf:
            add(
                transmitter.set_carrier_duty_percent(
                    conf[CONF_CARRIER_DUTY_PERCENT]))
예제 #30
0
def to_code(config):
    rhs = App.make_template_text_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
    make = variable(config[CONF_MAKE_ID], rhs)
    template = make.Ptemplate_
    text_sensor.setup_text_sensor(template, make.Pmqtt, config)
    setup_component(template, config)

    for template_ in process_lambda(config[CONF_LAMBDA], [],
                                    return_type=optional.template(std_string)):
        yield
    add(template.set_template(template_))