예제 #1
0
        cv.GenerateID(CONF_ID): cv.declare_id(HBridgeFan),
        cv.Required(CONF_PIN_A): cv.use_id(output.FloatOutput),
        cv.Required(CONF_PIN_B): cv.use_id(output.FloatOutput),
        cv.Optional(CONF_DECAY_MODE, default="SLOW"): cv.enum(
            DECAY_MODE_OPTIONS, upper=True
        ),
        cv.Optional(CONF_SPEED_COUNT, default=100): cv.int_range(min=1),
        cv.Optional(CONF_ENABLE_PIN): cv.use_id(output.FloatOutput),
    }
).extend(cv.COMPONENT_SCHEMA)


@automation.register_action(
    "fan.hbridge.brake",
    BrakeAction,
    maybe_simple_id({cv.Required(CONF_ID): cv.use_id(HBridgeFan)}),
)
async def fan_hbridge_brake_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)


async def to_code(config):
    var = cg.new_Pvariable(
        config[CONF_ID],
        config[CONF_SPEED_COUNT],
        config[CONF_DECAY_MODE],
    )
    await fan.register_fan(var, config)
    pin_a_ = await cg.get_variable(config[CONF_PIN_A])
    cg.add(var.set_pin_a(pin_a_))
예제 #2
0
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_binary_sensor(var))
    yield setup_binary_sensor_core_(var, config)


@coroutine
def new_binary_sensor(config):
    var = cg.new_Pvariable(config[CONF_ID], config[CONF_NAME])
    yield register_binary_sensor(var, config)
    yield var


BINARY_SENSOR_CONDITION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID): cv.use_id(BinarySensor),
    cv.Optional(CONF_FOR): cv.invalid("This option has been removed in 1.13, please use the "
                                      "'for' condition instead."),
})


@automation.register_condition('binary_sensor.is_on', BinarySensorCondition,
                               BINARY_SENSOR_CONDITION_SCHEMA)
def binary_sensor_is_on_to_code(config, condition_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(condition_id, template_arg, paren, True)


@automation.register_condition('binary_sensor.is_off', BinarySensorCondition,
                               BINARY_SENSOR_CONDITION_SCHEMA)
def binary_sensor_is_off_to_code(config, condition_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
예제 #3
0
        cg.add(obj.set_power_supply(power_supply_))
    if CONF_MAX_POWER in config:
        cg.add(obj.set_max_power(config[CONF_MAX_POWER]))
    if CONF_MIN_POWER in config:
        cg.add(obj.set_min_power(config[CONF_MIN_POWER]))


@coroutine
def register_output(var, config):
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    yield setup_output_platform_(var, config)


BINARY_OUTPUT_ACTION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID):
    cv.use_id(BinaryOutput),
})


@automation.register_action('output.turn_on', TurnOnAction,
                            BINARY_OUTPUT_ACTION_SCHEMA)
def output_turn_on_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action('output.turn_off', TurnOffAction,
                            BINARY_OUTPUT_ACTION_SCHEMA)
def output_turn_off_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)
예제 #4
0
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_fan(var))
    yield cg.register_component(var, config)
    yield setup_fan_core_(var, config)


@coroutine
def create_fan_state(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield register_fan(var, config)
    yield var


FAN_ACTION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID): cv.use_id(FanState),
})


@automation.register_action('fan.toggle', ToggleAction, FAN_ACTION_SCHEMA)
def fan_toggle_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action('fan.turn_off', TurnOffAction, FAN_ACTION_SCHEMA)
def fan_turn_off_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)

예제 #5
0
        cg.add(var.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 = cg.StructInitializer(Ext1Wakeup, ('mask', mask),
                                      ('wakeup_mode', conf[CONF_MODE]))
        cg.add(var.set_ext1_wakeup(struct))

    cg.add_define('USE_DEEP_SLEEP')


DEEP_SLEEP_ACTION_SCHEMA = maybe_simple_id({
    cv.GenerateID():
    cv.use_id(DeepSleepComponent),
})


@automation.register_action('deep_sleep.enter', EnterDeepSleepAction,
                            DEEP_SLEEP_ACTION_SCHEMA)
def deep_sleep_enter_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action('deep_sleep.prevent', PreventDeepSleepAction,
                            DEEP_SLEEP_ACTION_SCHEMA)
def deep_sleep_prevent_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)
예제 #6
0
    cg.add(var.set_gains(config[CONF_CURRENT_GAIN], config[CONF_VOLTAGE_GAIN]))
    cg.add(var.set_hpf_enable(config[CONF_CURRENT_HPF], config[CONF_VOLTAGE_HPF]))
    cg.add(var.set_pulse_energy_wh(config[CONF_PULSE_ENERGY]))

    if CONF_VOLTAGE in config:
        conf = config[CONF_VOLTAGE]
        sens = await sensor.new_sensor(conf)
        cg.add(var.set_voltage_sensor(sens))
    if CONF_CURRENT in config:
        conf = config[CONF_CURRENT]
        sens = await sensor.new_sensor(conf)
        cg.add(var.set_current_sensor(sens))
    if CONF_POWER in config:
        conf = config[CONF_POWER]
        sens = await sensor.new_sensor(conf)
        cg.add(var.set_power_sensor(sens))


@automation.register_action(
    "cs5460a.restart",
    CS5460ARestartAction,
    maybe_simple_id(
        {
            cv.Required(CONF_ID): cv.use_id(CS5460AComponent),
        }
    ),
)
async def restart_action_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)
예제 #7
0
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_fan(var))
    yield cg.register_component(var, config)
    yield setup_fan_core_(var, config)


@coroutine
def create_fan_state(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield register_fan(var, config)
    yield var


FAN_ACTION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID): cv.use_id(FanState),
})


@automation.register_action('fan.toggle', ToggleAction, FAN_ACTION_SCHEMA)
def fan_toggle_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action('fan.turn_off', TurnOffAction, FAN_ACTION_SCHEMA)
def fan_turn_off_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)

예제 #8
0
    
    if CONF_DIR_PIN in config:
        dir_pin = await cg.gpio_pin_expression(config[CONF_DIR_PIN])
        cg.add(var.set_dir_pin(dir_pin))
    
    cg.add(var.set_driver_address(config[CONF_DRIVER_ADDRESS]))
    cg.add(var.set_stall_threshold(config[CONF_STALL_THRESHOLD]))
    cg.add(var.set_microsteps(config[CONF_MICROSTEPS]))
    cg.add(var.set_rms_current(config[CONF_RMS_CURRENT]))

    if CONF_COVER in config:
        config_cover = config[CONF_COVER]
        cover_var = cg.new_Pvariable(config_cover[CONF_ID])
        await cg.register_component(cover_var, config_cover)
        await cover.register_cover(cover_var, config_cover)

        cg.add(cover_var.set_stepper(var))

@automation.register_action(
    "stepper.calibrate",
    CalibrateAction,
    automation.maybe_simple_id(
        {
            cv.Required(CONF_ID): cv.use_id(TMC2209),
        }
    ) ,
)
async def stepper_calibrate_to_code(config, action_id, template_arg, args):
    parent = await cg.get_variable(config[CONF_ID])
    var = cg.new_Pvariable(action_id, template_arg, parent)
    return var
예제 #9
0
            page = await cg.get_variable(conf[CONF_TO])
            cg.add(trigger.set_to(page))
        await automation.build_automation(trigger, [(DisplayPagePtr, "from"),
                                                    (DisplayPagePtr, "to")],
                                          conf)


async def register_display(var, config):
    await setup_display_core_(var, config)


@automation.register_action(
    "display.page.show",
    DisplayPageShowAction,
    maybe_simple_id({
        cv.Required(CONF_ID):
        cv.templatable(cv.use_id(DisplayPage)),
    }),
)
async def display_page_show_to_code(config, action_id, template_arg, args):
    var = cg.new_Pvariable(action_id, template_arg)
    if isinstance(config[CONF_ID], core.Lambda):
        template_ = await cg.templatable(config[CONF_ID], args, DisplayPagePtr)
        cg.add(var.set_page(template_))
    else:
        paren = await cg.get_variable(config[CONF_ID])
        cg.add(var.set_page(paren))
    return var


@automation.register_action(
    "display.page.show_next",
예제 #10
0
    var = cg.new_Pvariable(action_id, template_arg)
    await cg.register_parented(var, config[CONF_ID])

    template_ = await cg.templatable(config[CONF_START], args, cg.uint8)
    cg.add(var.set_start(template_))
    template_ = await cg.templatable(config[CONF_END], args, cg.uint8)
    cg.add(var.set_end(template_))
    cg.add(var.set_memory(get_memory_address(config[CONF_MEMORY])))

    for conf in config.get(CONF_ON_DUMP_FINISH, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
        cg.add(var.register_finish_trigger(trigger))
        await automation.build_automation(trigger, [(cg.std_string, "data")],
                                          conf)

    return var


@automation.register_condition("extraflame.is_dumping",
                               ExtraflameIsDumpingCondition,
                               maybe_simple_id({
                                   cv.GenerateID():
                                   cv.use_id(ExtraflameHub),
                               }))
async def extraflame_is_dumping_to_code(config, condition_id, template_arg,
                                        args):
    cg.add_define("USE_EXTRAFLAME_DUMP")
    var = cg.new_Pvariable(condition_id, template_arg)
    await cg.register_parented(var, config[CONF_ID])
    return var
예제 #11
0
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend({
    cv.GenerateID(): cv.declare_id(IntegrationSensor),
    cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
    cv.Required(CONF_TIME_UNIT): cv.enum(INTEGRATION_TIMES, lower=True),
    cv.Optional(CONF_INTEGRATION_METHOD, default='trapezoid'):
        cv.enum(INTEGRATION_METHODS, lower=True),
    cv.Optional(CONF_RESTORE, default=False): cv.boolean,
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])

    yield cg.register_component(var, config)
    yield sensor.register_sensor(var, config)

    sens = yield cg.get_variable(config[CONF_SENSOR])
    cg.add(var.set_sensor(sens))
    cg.add(var.set_time(config[CONF_TIME_ID]))
    cg.add(var.set_method(config[CONF_INTEGRATION_METHOD]))
    cg.add(var.set_restore(config[CONF_RESTORE]))


@automation.register_action('sensor.integration.reset', ResetAction, automation.maybe_simple_id({
    cv.Required(CONF_ID): cv.use_id(IntegrationSensor),
}))
def sensor_integration_reset_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)
예제 #12
0
    for key, funcName in SENSOR_MAP.items():
        if key in config:
            sens = await sensor.new_sensor(config[key])
            cg.add(getattr(var, funcName)(sens))

    if CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE in config:
        sens = await cg.get_variable(config[CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE])
        cg.add(var.set_ambient_pressure_source(sens))

    cg.add(var.set_measurement_mode(config[CONF_MEASUREMENT_MODE]))


SCD4X_ACTION_SCHEMA = maybe_simple_id(
    {
        cv.GenerateID(): cv.use_id(SCD4XComponent),
        cv.Required(CONF_VALUE): cv.templatable(cv.positive_int),
    }
)


@automation.register_action(
    "scd4x.perform_forced_calibration",
    PerformForcedCalibrationAction,
    SCD4X_ACTION_SCHEMA,
)
async def scd4x_frc_to_code(config, action_id, template_arg, args):
    var = cg.new_Pvariable(action_id, template_arg)
    await cg.register_parented(var, config[CONF_ID])
    template_ = await cg.templatable(config[CONF_VALUE], args, cg.uint16)
    cg.add(var.set_value(template_))
    return var
예제 #13
0
    if CONF_MQTT_ID in config:
        mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
        yield mqtt.register_mqtt_component(mqtt_, config)


@coroutine
def register_switch(var, config):
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_switch(var))
    yield setup_switch_core_(var, config)


SWITCH_ACTION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID): cv.use_id(Switch),
})


@automation.register_action('switch.toggle', ToggleAction, SWITCH_ACTION_SCHEMA)
@automation.register_action('switch.turn_off', TurnOffAction, SWITCH_ACTION_SCHEMA)
@automation.register_action('switch.turn_on', TurnOnAction, SWITCH_ACTION_SCHEMA)
def switch_toggle_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_condition('switch.is_on', SwitchCondition, SWITCH_ACTION_SCHEMA)
def switch_is_on_to_code(config, condition_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(condition_id, template_arg, paren, True)
예제 #14
0
        ),
        cv.Optional(CONF_ON_PLAY): automation.validate_automation(
            {
                cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PlayTrigger),
            }
        ),
        cv.Optional(CONF_ON_PAUSE): automation.validate_automation(
            {
                cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PauseTrigger),
            }
        ),
    }
)


MEDIA_PLAYER_ACTION_SCHEMA = maybe_simple_id({cv.GenerateID(): cv.use_id(MediaPlayer)})


@automation.register_action(
    "media_player.play_media",
    PlayMediaAction,
    cv.maybe_simple_value(
        {
            cv.GenerateID(): cv.use_id(MediaPlayer),
            cv.Required(CONF_MEDIA_URL): cv.templatable(cv.url),
        },
        key=CONF_MEDIA_URL,
    ),
)
async def media_player_play_media_action(config, action_id, template_arg, args):
    var = cg.new_Pvariable(action_id, template_arg)
예제 #15
0
async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)

    clk_pin = await cg.gpio_pin_expression(config[CONF_CLK_PIN])
    cg.add(var.set_clk_pin(clk_pin))
    dio_pin = await cg.gpio_pin_expression(config[CONF_DIO_PIN])
    cg.add(var.set_dio_pin(dio_pin))

    # https://platformio.org/lib/show/6865/TM1651
    cg.add_library("freekode/TM1651", "1.0.1")


BINARY_OUTPUT_ACTION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID):
    cv.use_id(TM1651Display),
})


@automation.register_action("tm1651.turn_on", TurnOnAction,
                            BINARY_OUTPUT_ACTION_SCHEMA)
async def output_turn_on_to_code(config, action_id, template_arg, args):
    var = cg.new_Pvariable(action_id, template_arg)
    await cg.register_parented(var, config[CONF_ID])
    return var


@automation.register_action("tm1651.turn_off", TurnOffAction,
                            BINARY_OUTPUT_ACTION_SCHEMA)
async def output_turn_off_to_code(config, action_id, template_arg, args):
    var = cg.new_Pvariable(action_id, template_arg)
예제 #16
0
    LightState,
    LightControlAction,
    AddressableLightState,
    AddressableSet,
    LightIsOnCondition,
    LightIsOffCondition,
)


@automation.register_action(
    "light.toggle",
    ToggleAction,
    automation.maybe_simple_id(
        {
            cv.Required(CONF_ID): cv.use_id(LightState),
            cv.Optional(CONF_TRANSITION_LENGTH): cv.templatable(
                cv.positive_time_period_milliseconds
            ),
        }
    ),
)
def light_toggle_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    var = cg.new_Pvariable(action_id, template_arg, paren)
    if CONF_TRANSITION_LENGTH in config:
        template_ = yield cg.templatable(
            config[CONF_TRANSITION_LENGTH], args, cg.uint32
        )
        cg.add(var.set_transition_length(template_))
    yield var

예제 #17
0
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_fan(var))
    yield cg.register_component(var, config)
    yield setup_fan_core_(var, config)


@coroutine
def create_fan_state(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield register_fan(var, config)
    yield var


FAN_ACTION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID): cv.use_id(FanState),
})


@automation.register_action("fan.toggle", ToggleAction, FAN_ACTION_SCHEMA)
def fan_toggle_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action("fan.turn_off", TurnOffAction, FAN_ACTION_SCHEMA)
def fan_turn_off_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)

예제 #18
0

@automation.register_action(
    "servo.write",
    ServoWriteAction,
    cv.Schema({
        cv.Required(CONF_ID):
        cv.use_id(Servo),
        cv.Required(CONF_LEVEL):
        cv.templatable(cv.possibly_negative_percentage),
    }),
)
def servo_write_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    var = cg.new_Pvariable(action_id, template_arg, paren)
    template_ = yield cg.templatable(config[CONF_LEVEL], args, float)
    cg.add(var.set_value(template_))
    yield var


@automation.register_action(
    "servo.detach",
    ServoDetachAction,
    maybe_simple_id({
        cv.Required(CONF_ID): cv.use_id(Servo),
    }),
)
def servo_detach_to_code(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    yield cg.new_Pvariable(action_id, template_arg, paren)
예제 #19
0
파일: climate.py 프로젝트: krahabb/esphome
    cg.add(var.set_kd(params[CONF_KD]))
    if CONF_MIN_INTEGRAL in params:
        cg.add(var.set_min_integral(params[CONF_MIN_INTEGRAL]))
    if CONF_MAX_INTEGRAL in params:
        cg.add(var.set_max_integral(params[CONF_MAX_INTEGRAL]))

    cg.add(
        var.set_default_target_temperature(
            config[CONF_DEFAULT_TARGET_TEMPERATURE]))


@automation.register_action(
    "climate.pid.reset_integral_term",
    PIDResetIntegralTermAction,
    automation.maybe_simple_id({
        cv.Required(CONF_ID): cv.use_id(PIDClimate),
    }),
)
async def pid_reset_integral_term(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action(
    "climate.pid.autotune",
    PIDAutotuneAction,
    automation.maybe_simple_id({
        cv.Required(CONF_ID):
        cv.use_id(PIDClimate),
        cv.Optional(CONF_NOISEBAND, default=0.25):
        cv.float_,
예제 #20
0
파일: sensor.py 프로젝트: warthog9/esphome
    cv.Optional(CONF_RESTORE, default=False):
    cv.boolean,
}).extend(cv.COMPONENT_SCHEMA)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])

    await cg.register_component(var, config)
    await sensor.register_sensor(var, config)

    sens = await cg.get_variable(config[CONF_SENSOR])
    cg.add(var.set_sensor(sens))
    cg.add(var.set_time(config[CONF_TIME_UNIT]))
    cg.add(var.set_method(config[CONF_INTEGRATION_METHOD]))
    cg.add(var.set_restore(config[CONF_RESTORE]))


@automation.register_action(
    "sensor.integration.reset",
    ResetAction,
    automation.maybe_simple_id({
        cv.Required(CONF_ID):
        cv.use_id(IntegrationSensor),
    }),
)
async def sensor_integration_reset_to_code(config, action_id, template_arg,
                                           args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)
예제 #21
0
        mask = 0
        for pin in conf[CONF_PINS]:
            mask |= 1 << pin[CONF_NUMBER]
        struct = cg.StructInitializer(Ext1Wakeup, ("mask", mask),
                                      ("wakeup_mode", conf[CONF_MODE]))
        cg.add(var.set_ext1_wakeup(struct))

    if CONF_TOUCH_WAKEUP in config:
        cg.add(var.set_touch_wakeup(config[CONF_TOUCH_WAKEUP]))

    cg.add_define("USE_DEEP_SLEEP")


DEEP_SLEEP_ENTER_SCHEMA = automation.maybe_simple_id({
    cv.GenerateID():
    cv.use_id(DeepSleepComponent),
    cv.Optional(CONF_SLEEP_DURATION):
    cv.templatable(cv.positive_time_period_milliseconds),
})

DEEP_SLEEP_PREVENT_SCHEMA = automation.maybe_simple_id({
    cv.GenerateID():
    cv.use_id(DeepSleepComponent),
})


@automation.register_action("deep_sleep.enter", EnterDeepSleepAction,
                            DEEP_SLEEP_ENTER_SCHEMA)
async def deep_sleep_enter_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    var = cg.new_Pvariable(action_id, template_arg, paren)
    if CONF_SLEEP_DURATION in config:
예제 #22
0
                    config[CONF_TILT_STATE_TOPIC]))
        if CONF_TILT_COMMAND_TOPIC in config:
            cg.add(
                mqtt_.set_custom_tilt_command_topic(
                    config[CONF_TILT_COMMAND_TOPIC]))


async def register_cover(var, config):
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_cover(var))
    await setup_cover_core_(var, config)


COVER_ACTION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID): cv.use_id(Cover),
})


@automation.register_action("cover.open", OpenAction, COVER_ACTION_SCHEMA)
async def cover_open_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action("cover.close", CloseAction, COVER_ACTION_SCHEMA)
async def cover_close_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)

예제 #23
0
파일: sensor.py 프로젝트: krahabb/esphome
    ),
}).extend(cv.polling_component_schema("60s")).extend(uart.UART_DEVICE_SCHEMA))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await uart.register_uart_device(var, config)

    if CONF_CO2 in config:
        sens = await sensor.new_sensor(config[CONF_CO2])
        cg.add(var.set_co2_sensor(sens))


CALIBRATION_ACTION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID):
    cv.use_id(SenseAirComponent),
})


@automation.register_action(
    "senseair.background_calibration",
    SenseAirBackgroundCalibrationAction,
    CALIBRATION_ACTION_SCHEMA,
)
@automation.register_action(
    "senseair.background_calibration_result",
    SenseAirBackgroundCalibrationResultAction,
    CALIBRATION_ACTION_SCHEMA,
)
@automation.register_action("senseair.abc_enable", SenseAirABCEnableAction,
                            CALIBRATION_ACTION_SCHEMA)
예제 #24
0
        add(
            mqtt_.set_custom_speed_command_topic(
                config[CONF_SPEED_COMMAND_TOPIC]))
    setup_mqtt_component(mqtt_, config)


def setup_fan(fan_obj, config):
    fan_var = Pvariable(config[CONF_ID], fan_obj, has_side_effects=False)
    CORE.add_job(setup_fan_core_, fan_var, config)


BUILD_FLAGS = '-DUSE_FAN'

CONF_FAN_TOGGLE = 'fan.toggle'
FAN_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(FanState),
})


@ACTION_REGISTRY.register(CONF_FAN_TOGGLE, FAN_TOGGLE_ACTION_SCHEMA)
def fan_toggle_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_toggle_action(template_arg)
    type = ToggleAction.template(template_arg)
    yield Pvariable(action_id, rhs, type=type)


CONF_FAN_TURN_OFF = 'fan.turn_off'
FAN_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
예제 #25
0
파일: time.py 프로젝트: krahabb/esphome
    WriteAction,
    cv.Schema({
        cv.GenerateID(): cv.use_id(DS1307Component),
    }),
)
async def ds1307_write_time_to_code(config, action_id, template_arg, args):
    var = cg.new_Pvariable(action_id, template_arg)
    await cg.register_parented(var, config[CONF_ID])
    return var


@automation.register_action(
    "ds1307.read_time",
    ReadAction,
    automation.maybe_simple_id({
        cv.GenerateID(): cv.use_id(DS1307Component),
    }),
)
async def ds1307_read_time_to_code(config, action_id, template_arg, args):
    var = cg.new_Pvariable(action_id, template_arg)
    await cg.register_parented(var, config[CONF_ID])
    return var


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])

    await cg.register_component(var, config)
    await i2c.register_i2c_device(var, config)
    await time.register_time(var, config)
예제 #26
0
파일: __init__.py 프로젝트: krahabb/esphome

async def register_button(var, config):
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_button(var))
    await setup_button_core_(var, config)


async def new_button(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await register_button(var, config)
    return var


BUTTON_PRESS_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID): cv.use_id(Button),
})


@automation.register_action("button.press", PressAction, BUTTON_PRESS_SCHEMA)
async def button_press_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)


@coroutine_with_priority(100.0)
async def to_code(config):
    cg.add_global(button_ns.using)
    cg.add_define("USE_BUTTON")
예제 #27
0
파일: __init__.py 프로젝트: krahabb/esphome
    OPERATION_BASE_SCHEMA.extend(
        {
            cv.Required(CONF_OPERATION): cv.templatable(
                cv.enum(SELECT_OPERATION_OPTIONS, upper=True)
            ),
            cv.Optional(CONF_CYCLE, default=True): cv.templatable(cv.boolean),
        }
    ),
)
@automation.register_action(
    "select.next",
    SelectOperationAction,
    automation.maybe_simple_id(
        OPERATION_BASE_SCHEMA.extend(
            {
                cv.Optional(CONF_MODE, default="NEXT"): cv.one_of("NEXT", upper=True),
                cv.Optional(CONF_CYCLE, default=True): cv.boolean,
            }
        )
    ),
)
@automation.register_action(
    "select.previous",
    SelectOperationAction,
    automation.maybe_simple_id(
        OPERATION_BASE_SCHEMA.extend(
            {
                cv.Optional(CONF_MODE, default="PREVIOUS"): cv.one_of(
                    "PREVIOUS", upper=True
                ),
                cv.Optional(CONF_CYCLE, default=True): cv.boolean,
            }
예제 #28
0
async def register_binary_sensor(var, config):
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_binary_sensor(var))
    await setup_binary_sensor_core_(var, config)


async def new_binary_sensor(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await register_binary_sensor(var, config)
    return var


BINARY_SENSOR_CONDITION_SCHEMA = maybe_simple_id({
    cv.Required(CONF_ID):
    cv.use_id(BinarySensor),
})


@automation.register_condition("binary_sensor.is_on", BinarySensorCondition,
                               BINARY_SENSOR_CONDITION_SCHEMA)
async def binary_sensor_is_on_to_code(config, condition_id, template_arg,
                                      args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(condition_id, template_arg, paren, True)


@automation.register_condition("binary_sensor.is_off", BinarySensorCondition,
                               BINARY_SENSOR_CONDITION_SCHEMA)
async def binary_sensor_is_off_to_code(config, condition_id, template_arg,
                                       args):
예제 #29
0
            cg.add(trigger.set_max_runs(conf[CONF_MAX_RUNS]))

        if conf[CONF_MODE] == CONF_QUEUED:
            await cg.register_component(trigger, conf)

        triggers.append((trigger, conf))

    for trigger, conf in triggers:
        await automation.build_automation(trigger, [], conf)


@automation.register_action(
    "script.execute",
    ScriptExecuteAction,
    maybe_simple_id({
        cv.Required(CONF_ID): cv.use_id(Script),
    }),
)
async def script_execute_action_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action(
    "script.stop",
    ScriptStopAction,
    maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
)
async def script_stop_action_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)
예제 #30
0
                                 'binary_sensor',
                                 config,
                                 include_state=True,
                                 include_command=False)
    if ret is None:
        return None
    if CONF_DEVICE_CLASS in config:
        ret['device_class'] = config[CONF_DEVICE_CLASS]
    return ret


BUILD_FLAGS = '-DUSE_BINARY_SENSOR'

CONF_BINARY_SENSOR_IS_ON = 'binary_sensor.is_on'
BINARY_SENSOR_IS_ON_CONDITION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(BinarySensor),
})


@CONDITION_REGISTRY.register(CONF_BINARY_SENSOR_IS_ON,
                             BINARY_SENSOR_IS_ON_CONDITION_SCHEMA)
def binary_sensor_is_on_to_code(config, condition_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_binary_sensor_is_on_condition(template_arg)
    type = BinarySensorCondition.template(arg_type)
    yield Pvariable(condition_id, rhs, type=type)


CONF_BINARY_SENSOR_IS_OFF = 'binary_sensor.is_off'
BINARY_SENSOR_IS_OFF_CONDITION_SCHEMA = maybe_simple_id({