Exemplo n.º 1
0
                         has_side_effects=False)
    setup_switch_core_(switch_var, mqtt_var, config)


def register_switch(var, config):
    switch_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
    rhs = App.register_switch(switch_var)
    mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
    setup_switch_core_(switch_var, mqtt_var, config)


BUILD_FLAGS = '-DUSE_SWITCH'

CONF_SWITCH_TOGGLE = 'switch.toggle'
SWITCH_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(Switch),
})


@ACTION_REGISTRY.register(CONF_SWITCH_TOGGLE, SWITCH_TOGGLE_ACTION_SCHEMA)
def switch_toggle_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_toggle_action(template_arg)
    type = ToggleAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_SWITCH_TURN_OFF = 'switch.turn_off'
SWITCH_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
Exemplo n.º 2
0
    setup_mqtt_component(mqtt_var, config)


def setup_light(light_obj, mqtt_obj, config):
    light_var = Pvariable(config[CONF_ID], light_obj, has_side_effects=False)
    mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
    add_job(setup_light_core_, light_var, mqtt_var, config)


BUILD_FLAGS = '-DUSE_LIGHT'


CONF_LIGHT_TOGGLE = 'light.toggle'
LIGHT_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID): cv.use_variable_id(None),
    vol.Optional(CONF_TRANSITION_LENGTH): cv.templatable(cv.positive_time_period_milliseconds),
})


@ACTION_REGISTRY.register(CONF_LIGHT_TOGGLE, LIGHT_TOGGLE_ACTION_SCHEMA)
def light_toggle_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_toggle_action(template_arg)
    type = ToggleAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    if CONF_TRANSITION_LENGTH in config:
        for template_ in templatable(config[CONF_TRANSITION_LENGTH], arg_type, uint32):
            yield None
        add(action.set_transition_length(template_))
Exemplo n.º 3
0
        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)


BUILD_FLAGS = '-DUSE_DEEP_SLEEP'

CONF_DEEP_SLEEP_ENTER = 'deep_sleep.enter'
DEEP_SLEEP_ENTER_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(DeepSleepComponent),
})


@ACTION_REGISTRY.register(CONF_DEEP_SLEEP_ENTER,
                          DEEP_SLEEP_ENTER_ACTION_SCHEMA)
def deep_sleep_enter_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_enter_deep_sleep_action(template_arg)
    type = EnterDeepSleepAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_DEEP_SLEEP_PREVENT = 'deep_sleep.prevent'
Exemplo n.º 4
0
CONFIG_SCHEMA = automation.validate_automation({
    vol.Required(CONF_ID):
    cv.declare_variable_id(Script),
})


def to_code(config):
    for conf in config:
        trigger = Pvariable(conf[CONF_ID], Script.new())
        automation.build_automation(trigger, NoArg, conf)


CONF_SCRIPT_EXECUTE = 'script.execute'
SCRIPT_EXECUTE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(Script),
})


@ACTION_REGISTRY.register(CONF_SCRIPT_EXECUTE, SCRIPT_EXECUTE_ACTION_SCHEMA)
def script_execute_action_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_execute_action(template_arg)
    type = ScriptExecuteAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_SCRIPT_STOP = 'script.stop'
SCRIPT_STOP_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
Exemplo n.º 5
0
    setup_mqtt_component(mqtt_var, config)


def setup_fan(fan_obj, mqtt_obj, config):
    fan_var = Pvariable(config[CONF_ID], fan_obj, has_side_effects=False)
    mqtt_var = Pvariable(config[CONF_MQTT_ID],
                         mqtt_obj,
                         has_side_effects=False)
    setup_fan_core_(fan_var, mqtt_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(None),
})


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


CONF_FAN_TURN_OFF = 'fan.turn_off'
FAN_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
Exemplo n.º 6
0
            yield
        add(obj.set_power_supply(power_supply))
    if CONF_MAX_POWER in config:
        add(obj.set_max_power(config[CONF_MAX_POWER]))


def setup_output_platform(obj, config, skip_power_supply=False):
    for _ in setup_output_platform_(obj, config, skip_power_supply):
        yield


BUILD_FLAGS = '-DUSE_OUTPUT'

CONF_OUTPUT_TURN_ON = 'output.turn_on'
OUTPUT_TURN_OFF_ACTION = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(None),
})


@ACTION_REGISTRY.register(CONF_OUTPUT_TURN_ON, OUTPUT_TURN_OFF_ACTION)
def output_turn_on_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_turn_off_action(template_arg)
    type = TurnOffAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_OUTPUT_TURN_OFF = 'output.turn_off'
OUTPUT_TURN_ON_ACTION = maybe_simple_id(
Exemplo n.º 7
0
    if CONF_INTERNAL in config:
        add(cover_var.set_internal(config[CONF_INTERNAL]))
    setup_mqtt_component(mqtt_var, config)


def setup_cover(cover_obj, mqtt_obj, config):
    cover_var = Pvariable(config[CONF_ID], cover_obj, has_side_effects=False)
    mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
    setup_cover_core_(cover_var, mqtt_var, config)


BUILD_FLAGS = '-DUSE_COVER'

CONF_COVER_OPEN = 'cover.open'
COVER_OPEN_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID): cv.use_variable_id(None),
})


@ACTION_REGISTRY.register(CONF_COVER_OPEN, COVER_OPEN_ACTION_SCHEMA)
def cover_open_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_open_action(template_arg)
    type = OpenAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_COVER_CLOSE = 'cover.close'
COVER_CLOSE_ACTION_SCHEMA = maybe_simple_id({
Exemplo n.º 8
0
    if CONF_SPEED_COMMAND_TOPIC in config:
        add(mqtt_var.set_custom_speed_command_topic(config[CONF_SPEED_COMMAND_TOPIC]))
    setup_mqtt_component(mqtt_var, config)


def setup_fan(fan_obj, mqtt_obj, config):
    fan_var = Pvariable(config[CONF_ID], fan_obj, has_side_effects=False)
    mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
    setup_fan_core_(fan_var, mqtt_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, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_toggle_action(template_arg)
    type = ToggleAction.template(arg_type)
    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): cv.use_variable_id(FanState),
Exemplo n.º 9
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({
Exemplo n.º 10
0
        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]))


def setup_output_platform(obj, config, skip_power_supply=False):
    add_job(setup_output_platform_, obj, config, skip_power_supply)


BUILD_FLAGS = '-DUSE_OUTPUT'

CONF_OUTPUT_TURN_ON = 'output.turn_on'
OUTPUT_TURN_ON_ACTION = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(BinaryOutput),
})


@ACTION_REGISTRY.register(CONF_OUTPUT_TURN_ON, OUTPUT_TURN_ON_ACTION)
def output_turn_on_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_turn_on_action(template_arg)
    type = TurnOnAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_OUTPUT_TURN_OFF = 'output.turn_off'
OUTPUT_TURN_OFF_ACTION = maybe_simple_id(