Exemplo n.º 1
0
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
        yield cg.register_component(trigger, conf)
        yield cg.register_parented(trigger, var)
        cg.add(trigger.set_sunrise(False))
        cg.add(trigger.set_elevation(conf[CONF_ELEVATION]))
        yield automation.build_automation(trigger, [], conf)


@automation.register_condition(
    "sun.is_above_horizon",
    SunCondition,
    cv.Schema({
        cv.GenerateID():
        cv.use_id(Sun),
        cv.Optional(CONF_ELEVATION, default=DEFAULT_ELEVATION):
        cv.templatable(elevation),
    }),
)
def sun_above_horizon_to_code(config, condition_id, template_arg, args):
    var = cg.new_Pvariable(condition_id, template_arg)
    yield cg.register_parented(var, config[CONF_ID])
    templ = yield cg.templatable(config[CONF_ELEVATION], args, cg.double)
    cg.add(var.set_elevation(templ))
    cg.add(var.set_above(True))
    yield var


@automation.register_condition(
    "sun.is_below_horizon",
    SunCondition,
    cv.Schema({
Exemplo n.º 2
0
    cg.add(var.set_resolution(config[CONF_RESOLUTION]))
    if CONF_MIN_VALUE in config:
        cg.add(var.set_min_value(config[CONF_MIN_VALUE]))
    if CONF_MAX_VALUE in config:
        cg.add(var.set_max_value(config[CONF_MAX_VALUE]))

    for conf in config.get(CONF_ON_CLOCKWISE, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        await automation.build_automation(trigger, [], conf)
    for conf in config.get(CONF_ON_ANTICLOCKWISE, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        await automation.build_automation(trigger, [], conf)


@automation.register_action(
    "sensor.rotary_encoder.set_value",
    RotaryEncoderSetValueAction,
    cv.Schema(
        {
            cv.Required(CONF_ID): cv.use_id(sensor.Sensor),
            cv.Required(CONF_VALUE): cv.templatable(cv.int_),
        }
    ),
)
async def sensor_template_publish_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)
    template_ = await cg.templatable(config[CONF_VALUE], args, int)
    cg.add(var.set_value(template_))
    return var
Exemplo n.º 3
0
            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",
Exemplo n.º 4
0
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)

    out = yield cg.get_variable(config[CONF_OUTPUT])
    cg.add(var.set_output(out))

    for conf in config.get(CONF_ON_FINISHED_PLAYBACK, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        yield automation.build_automation(trigger, [], conf)


@automation.register_action('rtttl.play', PlayAction, cv.maybe_simple_value({
    cv.GenerateID(CONF_ID): cv.use_id(Rtttl),
    cv.Required(CONF_RTTTL): cv.templatable(cv.string)
}, key=CONF_RTTTL))
def rtttl_play_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_RTTTL], args, cg.std_string)
    cg.add(var.set_value(template_))
    yield var


@automation.register_action('rtttl.stop', StopAction, cv.Schema({
    cv.GenerateID(): cv.use_id(Rtttl),
}))
def rtttl_stop_to_code(config, action_id, template_arg, args):
    var = cg.new_Pvariable(action_id, template_arg)
    yield cg.register_parented(var, config[CONF_ID])
Exemplo n.º 5
0
    return MEMORY_ADDRESSES[value]


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)


@automation.register_action(
    "extraflame.write",
    ExtraflameWriteAction,
    cv.Schema({
        cv.GenerateID(): cv.use_id(ExtraflameHub),
        cv.Required(CONF_MEMORY): is_memory_address,
        cv.Required(CONF_ADDRESS): cv.templatable(cv.hex_uint8_t),
        cv.Required(CONF_VALUE): cv.templatable(cv.hex_uint8_t),
    }),
)
async def extraflame_write_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_ADDRESS], args, cg.uint8)
    cg.add(var.set_address(template_))
    template_ = await cg.templatable(config[CONF_VALUE], args, cg.uint8)
    cg.add(var.set_value(template_))
    cg.add(var.set_memory(get_memory_address(config[CONF_MEMORY])))
    return var

Exemplo n.º 6
0
    cv.positive_time_period_milliseconds,
}).add_extra(validate_framework).extend(cv.COMPONENT_SCHEMA))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    cg.add(var.set_timeout(config[CONF_TIMEOUT]))
    cg.add(var.set_useragent(config[CONF_USERAGENT]))
    yield cg.register_component(var, config)


HTTP_REQUEST_ACTION_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.use_id(HttpRequestComponent),
    cv.Required(CONF_URL):
    cv.templatable(validate_url),
    cv.Optional(CONF_HEADERS):
    cv.All(cv.Schema({cv.string: cv.templatable(cv.string)})),
    cv.Optional(CONF_VERIFY_SSL, default=True):
    cv.boolean,
    cv.Optional(CONF_ON_RESPONSE):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_id(HttpRequestResponseTrigger)
    }),
}).add_extra(validate_secure_url)
HTTP_REQUEST_GET_ACTION_SCHEMA = automation.maybe_conf(
    CONF_URL,
    HTTP_REQUEST_ACTION_SCHEMA.extend({
        cv.Optional(CONF_METHOD, default="GET"):
        cv.one_of("GET", upper=True),
Exemplo n.º 7
0
            cg.add(trig.set_payload(conf[CONF_PAYLOAD]))
        await cg.register_component(trig, conf)
        await automation.build_automation(trig, [(cg.std_string, "x")], conf)

    for conf in config.get(CONF_ON_JSON_MESSAGE, []):
        trig = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf[CONF_TOPIC],
                                conf[CONF_QOS])
        await automation.build_automation(trig, [(cg.JsonObjectConstRef, "x")],
                                          conf)


MQTT_PUBLISH_ACTION_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.use_id(MQTTClientComponent),
    cv.Required(CONF_TOPIC):
    cv.templatable(cv.publish_topic),
    cv.Required(CONF_PAYLOAD):
    cv.templatable(cv.mqtt_payload),
    cv.Optional(CONF_QOS, default=0):
    cv.templatable(cv.mqtt_qos),
    cv.Optional(CONF_RETAIN, default=False):
    cv.templatable(cv.boolean),
})


@automation.register_action("mqtt.publish", MQTTPublishAction,
                            MQTT_PUBLISH_ACTION_SCHEMA)
async def mqtt_publish_action_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)
    template_ = await cg.templatable(config[CONF_TOPIC], args, cg.std_string)
Exemplo n.º 8
0
        yield mqtt.register_mqtt_component(mqtt_, config)


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


CLIMATE_CONTROL_ACTION_SCHEMA = cv.Schema({
    cv.Required(CONF_ID):
    cv.use_id(Climate),
    cv.Optional(CONF_MODE):
    cv.templatable(validate_climate_mode),
    cv.Optional(CONF_TARGET_TEMPERATURE):
    cv.templatable(cv.temperature),
    cv.Optional(CONF_TARGET_TEMPERATURE_LOW):
    cv.templatable(cv.temperature),
    cv.Optional(CONF_TARGET_TEMPERATURE_HIGH):
    cv.templatable(cv.temperature),
    cv.Optional(CONF_AWAY):
    cv.templatable(cv.boolean),
    cv.Optional(CONF_FAN_MODE):
    cv.templatable(validate_climate_fan_mode),
    cv.Optional(CONF_SWING_MODE):
    cv.templatable(validate_climate_swing_mode),
})

Exemplo n.º 9
0
})
RC_SWITCH_TYPE_D_SCHEMA = cv.Schema({
    cv.Required(CONF_GROUP):
    cv.one_of('a', 'b', 'c', 'd', lower=True),
    cv.Required(CONF_DEVICE):
    cv.int_range(min=1, max=3),
    cv.Required(CONF_STATE):
    cv.boolean,
    cv.Optional(CONF_PROTOCOL, default=1):
    RC_SWITCH_PROTOCOL_SCHEMA,
})
RC_SWITCH_TRANSMITTER = cv.Schema({
    cv.Optional(CONF_REPEAT, default={CONF_TIMES: 5}):
    cv.Schema({
        cv.Required(CONF_TIMES):
        cv.templatable(cv.positive_int),
        cv.Optional(CONF_WAIT_TIME, default='0us'):
        cv.templatable(cv.positive_time_period_microseconds),
    }),
})

rc_switch_protocols = ns.rc_switch_protocols
RCSwitchData = ns.struct('RCSwitchData')
RCSwitchBase = ns.class_('RCSwitchBase')
RCSwitchTrigger = ns.class_('RCSwitchTrigger', RemoteReceiverTrigger)
RCSwitchDumper = ns.class_('RCSwitchDumper', RemoteTransmitterDumper)
RCSwitchRawAction = ns.class_('RCSwitchRawAction', RemoteTransmitterActionBase)
RCSwitchTypeAAction = ns.class_('RCSwitchTypeAAction',
                                RemoteTransmitterActionBase)
RCSwitchTypeBAction = ns.class_('RCSwitchTypeBAction',
                                RemoteTransmitterActionBase)
Exemplo n.º 10
0
def esp8266_set_frequency_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)
    cg.add(var.set_noiseband(config[CONF_NOISEBAND]))
    cg.add(var.set_positive_output(config[CONF_POSITIVE_OUTPUT]))
    cg.add(var.set_negative_output(config[CONF_NEGATIVE_OUTPUT]))
    yield var


@automation.register_action('climate.pid.set_control_parameters',
                            PIDSetControlParametersAction,
                            automation.maybe_simple_id({
                                cv.Required(CONF_ID):
                                cv.use_id(PIDClimate),
                                cv.Required(CONF_KP):
                                cv.templatable(cv.float_),
                                cv.Optional(CONF_KI, default=0.0):
                                cv.templatable(cv.float_),
                                cv.Optional(CONF_KD, default=0.0):
                                cv.templatable(cv.float_),
                            }))
def set_control_parameters(config, action_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    var = cg.new_Pvariable(action_id, template_arg, paren)

    kp_template_ = yield cg.templatable(config[CONF_KP], args, float)
    cg.add(var.set_kp(kp_template_))

    ki_template_ = yield cg.templatable(config[CONF_KI], args, float)
    cg.add(var.set_ki(ki_template_))
Exemplo n.º 11
0
    for conf in config.get(CONF_ON_MESSAGE, []):
        trig = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf[CONF_TOPIC])
        cg.add(trig.set_qos(conf[CONF_QOS]))
        if CONF_PAYLOAD in conf:
            cg.add(trig.set_payload(conf[CONF_PAYLOAD]))
        yield cg.register_component(trig, conf)
        yield automation.build_automation(trig, [(cg.std_string, 'x')], conf)

    for conf in config.get(CONF_ON_JSON_MESSAGE, []):
        trig = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf[CONF_TOPIC], conf[CONF_QOS])
        yield automation.build_automation(trig, [(cg.JsonObjectConstRef, 'x')], conf)


MQTT_PUBLISH_ACTION_SCHEMA = cv.Schema({
    cv.GenerateID(): cv.use_id(MQTTClientComponent),
    cv.Required(CONF_TOPIC): cv.templatable(cv.publish_topic),
    cv.Required(CONF_PAYLOAD): cv.templatable(cv.mqtt_payload),
    cv.Optional(CONF_QOS, default=0): cv.templatable(cv.mqtt_qos),
    cv.Optional(CONF_RETAIN, default=False): cv.templatable(cv.boolean),
})


@automation.register_action('mqtt.publish', MQTTPublishAction, MQTT_PUBLISH_ACTION_SCHEMA)
def mqtt_publish_action_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_TOPIC], args, cg.std_string)
    cg.add(var.set_topic(template_))

    template_ = yield cg.templatable(config[CONF_PAYLOAD], args, cg.std_string)
    cg.add(var.set_payload(template_))
Exemplo n.º 12
0
async def register_text_sensor(var, config):
    if not CORE.has_id(config[CONF_ID]):
        var = cg.Pvariable(config[CONF_ID], var)
    cg.add(cg.App.register_text_sensor(var))
    await setup_text_sensor_core_(var, config)


@coroutine_with_priority(100.0)
async def to_code(config):
    cg.add_define("USE_TEXT_SENSOR")
    cg.add_global(text_sensor_ns.using)


@automation.register_condition(
    "text_sensor.state",
    TextSensorStateCondition,
    cv.Schema(
        {
            cv.Required(CONF_ID): cv.use_id(TextSensor),
            cv.Required(CONF_STATE): cv.templatable(cv.string_strict),
        }
    ),
)
async def text_sensor_state_to_code(config, condition_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    var = cg.new_Pvariable(condition_id, template_arg, paren)
    templ = await cg.templatable(config[CONF_STATE], args, cg.std_string)
    cg.add(var.set_state(templ))
    return var
Exemplo n.º 13
0
    condition = await build_condition(config, template_arg, args)
    return cg.new_Pvariable(condition_id, template_arg, condition)


@register_condition("lambda", LambdaCondition, cv.returning_lambda)
async def lambda_condition_to_code(config, condition_id, template_arg, args):
    lambda_ = await cg.process_lambda(config, args, return_type=bool)
    return cg.new_Pvariable(condition_id, template_arg, lambda_)


@register_condition(
    "for",
    ForCondition,
    cv.Schema({
        cv.Required(CONF_TIME):
        cv.templatable(cv.positive_time_period_milliseconds),
        cv.Required(CONF_CONDITION):
        validate_potentially_and_condition,
    }).extend(cv.COMPONENT_SCHEMA),
)
async def for_condition_to_code(config, condition_id, template_arg, args):
    condition = await build_condition(config[CONF_CONDITION],
                                      cg.TemplateArguments(), [])
    var = cg.new_Pvariable(condition_id, template_arg, condition)
    await cg.register_component(var, config)
    templ = await cg.templatable(config[CONF_TIME], args, cg.uint32)
    cg.add(var.set_time(templ))
    return var


@register_action("delay", DelayAction,
Exemplo n.º 14
0
BeeperOffAction = midea_ac_ns.class_("BeeperOffAction", automation.Action)
PowerOnAction = midea_ac_ns.class_("PowerOnAction", automation.Action)
PowerOffAction = midea_ac_ns.class_("PowerOffAction", automation.Action)

MIDEA_ACTION_BASE_SCHEMA = cv.Schema(
    {
        cv.GenerateID(CONF_ID): cv.use_id(AirConditioner),
    }
)

# FollowMe action
MIDEA_FOLLOW_ME_MIN = 0
MIDEA_FOLLOW_ME_MAX = 37
MIDEA_FOLLOW_ME_SCHEMA = cv.Schema(
    {
        cv.Required(CONF_TEMPERATURE): cv.templatable(cv.temperature),
        cv.Optional(CONF_BEEPER, default=False): cv.templatable(cv.boolean),
    }
)


@register_action("follow_me", FollowMeAction, MIDEA_FOLLOW_ME_SCHEMA)
async def follow_me_to_code(var, config, args):
    template_ = await cg.templatable(config[CONF_BEEPER], args, cg.bool_)
    cg.add(var.set_beeper(template_))
    template_ = await cg.templatable(config[CONF_TEMPERATURE], args, cg.float_)
    cg.add(var.set_temperature(template_))


# Toggle Display action
@register_action(
Exemplo n.º 15
0
@coroutine
def register_canbus(var, config):
    if not CORE.has_id(config[CONF_ID]):
        var = cg.new_Pvariable(config[CONF_ID], var)
    yield setup_canbus_core_(var, config)


# Actions
@automation.register_action(
    CONF_CANBUS_SEND, canbus_ns.class_('CanbusSendAction', automation.Action),
    cv.maybe_simple_value(
        {
            cv.GenerateID(CONF_CANBUS_ID): cv.use_id(CanbusComponent),
            cv.Optional(CONF_CAN_ID): cv.int_range(min=0, max=0x1fffffff),
            cv.Optional(CONF_USE_EXTENDED_ID, default=False): cv.boolean,
            cv.Required(CONF_DATA): cv.templatable(validate_raw_data),
        },
        key=CONF_DATA))
def canbus_action_to_code(config, action_id, template_arg, args):
    validate_id(config[CONF_CAN_ID], config[CONF_USE_EXTENDED_ID])
    var = cg.new_Pvariable(action_id, template_arg)
    yield cg.register_parented(var, config[CONF_CANBUS_ID])

    if CONF_CAN_ID in config:
        can_id = yield cg.templatable(config[CONF_CAN_ID], args, cg.uint32)
        cg.add(var.set_can_id(can_id))

    use_extended_id = yield cg.templatable(config[CONF_USE_EXTENDED_ID], args,
                                           cg.uint32)
    cg.add(var.set_use_extended_id(use_extended_id))
Exemplo n.º 16
0
    cv.Optional(CONF_FREQUENCY, default='1kHz'):
    validate_frequency,
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield output.register_output(var, config)

    pin = yield cg.gpio_pin_expression(config[CONF_PIN])
    cg.add(var.set_pin(pin))

    cg.add(var.set_frequency(config[CONF_FREQUENCY]))


@automation.register_action('output.esp8266_pwm.set_frequency',
                            SetFrequencyAction,
                            cv.Schema({
                                cv.Required(CONF_ID):
                                cv.use_id(ESP8266PWM),
                                cv.Required(CONF_FREQUENCY):
                                cv.templatable(validate_frequency),
                            }))
def esp8266_set_frequency_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_FREQUENCY], args, float)
    cg.add(var.set_frequency(template_))
    yield var
Exemplo n.º 17
0
        cv.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA,
    }
)
RC_SWITCH_TYPE_D_SCHEMA = cv.Schema(
    {
        cv.Required(CONF_GROUP): cv.one_of("a", "b", "c", "d", lower=True),
        cv.Required(CONF_DEVICE): cv.int_range(min=1, max=3),
        cv.Required(CONF_STATE): cv.boolean,
        cv.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA,
    }
)
RC_SWITCH_TRANSMITTER = cv.Schema(
    {
        cv.Optional(CONF_REPEAT, default={CONF_TIMES: 5}): cv.Schema(
            {
                cv.Required(CONF_TIMES): cv.templatable(cv.positive_int),
                cv.Optional(CONF_WAIT_TIME, default="0us"): cv.templatable(
                    cv.positive_time_period_microseconds
                ),
            }
        ),
    }
)

rc_switch_protocols = ns.RC_SWITCH_PROTOCOLS
RCSwitchData = ns.struct("RCSwitchData")
RCSwitchBase = ns.class_("RCSwitchBase")
RCSwitchTrigger = ns.class_("RCSwitchTrigger", RemoteReceiverTrigger)
RCSwitchDumper = ns.class_("RCSwitchDumper", RemoteTransmitterDumper)
RCSwitchRawAction = ns.class_("RCSwitchRawAction", RemoteTransmitterActionBase)
RCSwitchTypeAAction = ns.class_("RCSwitchTypeAAction", RemoteTransmitterActionBase)
Exemplo n.º 18
0
        await automation.build_automation(trigger, [(cg.uint16, "finger_id")],
                                          conf)

    for conf in config.get(CONF_ON_ENROLLMENT_FAILED, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        await automation.build_automation(trigger, [(cg.uint16, "finger_id")],
                                          conf)


@automation.register_action(
    "fingerprint_grow.enroll",
    EnrollmentAction,
    cv.maybe_simple_value(
        {
            cv.GenerateID(): cv.use_id(FingerprintGrowComponent),
            cv.Required(CONF_FINGER_ID): cv.templatable(cv.uint16_t),
            cv.Optional(CONF_NUM_SCANS): cv.templatable(cv.uint8_t),
        },
        key=CONF_FINGER_ID,
    ),
)
async def fingerprint_grow_enroll_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_FINGER_ID], args, cg.uint16)
    cg.add(var.set_finger_id(template_))
    if CONF_NUM_SCANS in config:
        template_ = await cg.templatable(config[CONF_NUM_SCANS], args,
                                         cg.uint8)
Exemplo n.º 19
0
BeeperOnAction = midea_ns.class_("BeeperOnAction", automation.Action)
BeeperOffAction = midea_ns.class_("BeeperOffAction", automation.Action)
PowerOnAction = midea_ns.class_("PowerOnAction", automation.Action)
PowerOffAction = midea_ns.class_("PowerOffAction", automation.Action)

MIDEA_ACTION_BASE_SCHEMA = cv.Schema({
    cv.GenerateID(CONF_ID):
    cv.use_id(AirConditioner),
})

# FollowMe action
MIDEA_FOLLOW_ME_MIN = 0
MIDEA_FOLLOW_ME_MAX = 37
MIDEA_FOLLOW_ME_SCHEMA = cv.Schema({
    cv.Required(CONF_TEMPERATURE):
    cv.templatable(cv.temperature),
    cv.Optional(CONF_BEEPER, default=False):
    cv.templatable(cv.boolean),
})


@register_action("follow_me", FollowMeAction, MIDEA_FOLLOW_ME_SCHEMA)
async def follow_me_to_code(var, config, args):
    template_ = await cg.templatable(config[CONF_BEEPER], args, cg.bool_)
    cg.add(var.set_beeper(template_))
    template_ = await cg.templatable(config[CONF_TEMPERATURE], args, cg.float_)
    cg.add(var.set_temperature(template_))


# Toggle Display action
@register_action(
Exemplo n.º 20
0
    for conf in config.get(CONF_ON_SMS_RECEIVED, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        await automation.build_automation(
            trigger, [(cg.std_string, "message"), (cg.std_string, "sender")], conf
        )


def validate(config, item_config):
    uart.validate_device("sim800l", config, item_config, baud_rate=9600)


SIM800L_SEND_SMS_SCHEMA = cv.Schema(
    {
        cv.GenerateID(): cv.use_id(Sim800LComponent),
        cv.Required(CONF_RECIPIENT): cv.templatable(cv.string_strict),
        cv.Required(CONF_MESSAGE): cv.templatable(cv.string),
    }
)


@automation.register_action(
    "sim800l.send_sms", Sim800LSendSmsAction, SIM800L_SEND_SMS_SCHEMA
)
async def sim800l_send_sms_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)
    template_ = await cg.templatable(config[CONF_RECIPIENT], args, cg.std_string)
    cg.add(var.set_recipient(template_))
    template_ = await cg.templatable(config[CONF_MESSAGE], args, cg.std_string)
    cg.add(var.set_message(template_))
Exemplo n.º 21
0
        cg.add(stepper_var.set_max_speed(config[CONF_MAX_SPEED]))


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


@automation.register_action('stepper.set_target', SetTargetAction,
                            cv.Schema({
                                cv.Required(CONF_ID):
                                cv.use_id(Stepper),
                                cv.Required(CONF_TARGET):
                                cv.templatable(cv.int_),
                            }))
def stepper_set_target_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_TARGET], args, cg.int32)
    cg.add(var.set_target(template_))
    yield var


@automation.register_action('stepper.report_position', ReportPositionAction,
                            cv.Schema({
                                cv.Required(CONF_ID):
                                cv.use_id(Stepper),
                                cv.Required(CONF_POSITION):
                                cv.templatable(cv.int_),
Exemplo n.º 22
0
            }
        ),
    }
)


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)
    await cg.register_parented(var, config[CONF_ID])
    media_url = await cg.templatable(config[CONF_MEDIA_URL], args, cg.std_string)
    cg.add(var.set_media_url(media_url))
    return var


@automation.register_action("media_player.play", PlayAction, MEDIA_PLAYER_ACTION_SCHEMA)
@automation.register_action(
    "media_player.toggle", ToggleAction, MEDIA_PLAYER_ACTION_SCHEMA
        yield mqtt.register_mqtt_component(mqtt_, config)


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


@coroutine_with_priority(100.0)
def to_code(config):
    cg.add_define('USE_TEXT_SENSOR')
    cg.add_global(text_sensor_ns.using)


@automation.register_condition('text_sensor.state', TextSensorStateCondition,
                               cv.Schema({
                                   cv.Required(CONF_ID):
                                   cv.use_id(TextSensor),
                                   cv.Required(CONF_STATE):
                                   cv.templatable(cv.string_strict),
                               }))
def text_sensor_state_to_code(config, condition_id, template_arg, args):
    paren = yield cg.get_variable(config[CONF_ID])
    var = cg.new_Pvariable(condition_id, template_arg, paren)
    templ = yield cg.templatable(config[CONF_STATE], args, cg.std_string)
    cg.add(var.set_state(templ))
    yield var
Exemplo n.º 24
0

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

    if CONF_LAMBDA in config:
        template_ = await cg.process_lambda(
            config[CONF_LAMBDA], [], return_type=cg.optional.template(bool)
        )
        cg.add(var.set_template(template_))


@automation.register_action(
    "binary_sensor.template.publish",
    binary_sensor.BinarySensorPublishAction,
    cv.Schema(
        {
            cv.Required(CONF_ID): cv.use_id(binary_sensor.BinarySensor),
            cv.Required(CONF_STATE): cv.templatable(cv.boolean),
        }
    ),
)
async def binary_sensor_template_publish_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)
    template_ = await cg.templatable(config[CONF_STATE], args, bool)
    cg.add(var.set_state(template_))
    return var
Exemplo n.º 25
0
async def to_code(config):
    paren = await cg.get_variable(config[CONF_PIPSOLAR_ID])

    for type, (_, command) in TYPES.items():
        if type in config:
            conf = config[type]
            var = cg.new_Pvariable(conf[CONF_ID])
            await output.register_output(var, conf)
            cg.add(var.set_parent(paren))
            cg.add(var.set_set_command(command))
            if (CONF_POSSIBLE_VALUES) in conf:
                cg.add(var.set_possible_values(conf[CONF_POSSIBLE_VALUES]))


@automation.register_action(
    "output.pipsolar.set_level",
    SetOutputAction,
    cv.Schema(
        {
            cv.Required(CONF_ID): cv.use_id(CONF_ID),
            cv.Required(CONF_VALUE): cv.templatable(cv.positive_float),
        }
    ),
)
def output_pipsolar_set_level_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_VALUE], args, float)
    cg.add(var.set_level(template_))
    yield var
Exemplo n.º 26
0
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        await automation.build_automation(trigger, [(RFBridgeData, "data")],
                                          conf)

    for conf in config.get(CONF_ON_ADVANCED_CODE_RECEIVED, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        await automation.build_automation(trigger,
                                          [(RFBridgeAdvancedData, "data")],
                                          conf)


RFBRIDGE_SEND_CODE_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.use_id(RFBridgeComponent),
    cv.Required(CONF_SYNC):
    cv.templatable(cv.hex_uint16_t),
    cv.Required(CONF_LOW):
    cv.templatable(cv.hex_uint16_t),
    cv.Required(CONF_HIGH):
    cv.templatable(cv.hex_uint16_t),
    cv.Required(CONF_CODE):
    cv.templatable(cv.hex_uint32_t),
})


@automation.register_action("rf_bridge.send_code", RFBridgeSendCodeAction,
                            RFBRIDGE_SEND_CODE_SCHEMA)
async def rf_bridge_send_code_to_code(config, action_id, template_args, args):
    paren = await cg.get_variable(config[CONF_ID])
    var = cg.new_Pvariable(action_id, template_args, paren)
    template_ = await cg.templatable(config[CONF_SYNC], args, cg.uint16)
Exemplo n.º 27
0
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await sensor.register_sensor(var, config)

    pin = await cg.gpio_pin_expression(config[CONF_PIN])
    cg.add(var.set_pin(pin))
    cg.add(var.set_filter_us(config[CONF_INTERNAL_FILTER]))
    cg.add(var.set_timeout_us(config[CONF_TIMEOUT]))

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


@automation.register_action(
    "pulse_meter.set_total_pulses",
    SetTotalPulsesAction,
    cv.Schema(
        {
            cv.Required(CONF_ID): cv.use_id(PulseMeterSensor),
            cv.Required(CONF_VALUE): cv.templatable(cv.uint32_t),
        }
    ),
)
async def set_total_action_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)
    template_ = await cg.templatable(config[CONF_VALUE], args, int)
    cg.add(var.set_total_pulses(template_))
    return var
Exemplo n.º 28
0
    if CONF_LAMBDA in config:
        for template_ in process_lambda(config[CONF_LAMBDA], [],
                                        return_type=optional.template(bool_)):
            yield
        add(var.set_template(template_))


BUILD_FLAGS = '-DUSE_TEMPLATE_BINARY_SENSOR'

CONF_BINARY_SENSOR_TEMPLATE_PUBLISH = 'binary_sensor.template.publish'
BINARY_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA = vol.Schema({
    vol.Required(CONF_ID):
    cv.use_variable_id(binary_sensor.BinarySensor),
    vol.Required(CONF_STATE):
    cv.templatable(cv.boolean),
})


@ACTION_REGISTRY.register(CONF_BINARY_SENSOR_TEMPLATE_PUBLISH,
                          BINARY_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA)
def binary_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_binary_sensor_publish_action(template_arg)
    type = BinarySensorPublishAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_STATE], arg_type, bool_):
        yield None
    add(action.set_state(template_))
Exemplo n.º 29
0
    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

Exemplo n.º 30
0
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)


@automation.register_action(
    "output.set_level",
    SetLevelAction,
    cv.Schema({
        cv.Required(CONF_ID): cv.use_id(FloatOutput),
        cv.Required(CONF_LEVEL): cv.templatable(cv.percentage),
    }),
)
def output_set_level_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_level(template_))
    yield var


def to_code(config):
    cg.add_global(output_ns.using)