Ejemplo n.º 1
0
    paren = await cg.get_variable(config[CONF_ID])
    return cg.new_Pvariable(action_id, template_arg, paren)


@automation.register_action("cover.toggle", ToggleAction, COVER_ACTION_SCHEMA)
def cover_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)


COVER_CONTROL_ACTION_SCHEMA = cv.Schema({
    cv.Required(CONF_ID):
    cv.use_id(Cover),
    cv.Optional(CONF_STOP):
    cv.templatable(cv.boolean),
    cv.Exclusive(CONF_STATE, "pos"):
    cv.templatable(validate_cover_state),
    cv.Exclusive(CONF_POSITION, "pos"):
    cv.templatable(cv.percentage),
    cv.Optional(CONF_TILT):
    cv.templatable(cv.percentage),
})


@automation.register_action("cover.control", ControlAction,
                            COVER_CONTROL_ACTION_SCHEMA)
async def cover_control_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_STOP in config:
        template_ = await cg.templatable(config[CONF_STOP], args, bool)
Ejemplo n.º 2
0
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


LIGHT_CONTROL_ACTION_SCHEMA = cv.Schema(
    {
        cv.Required(CONF_ID): cv.use_id(LightState),
        cv.Optional(CONF_STATE): cv.templatable(cv.boolean),
        cv.Exclusive(CONF_TRANSITION_LENGTH, "transformer"): cv.templatable(
            cv.positive_time_period_milliseconds
        ),
        cv.Exclusive(CONF_FLASH_LENGTH, "transformer"): cv.templatable(
            cv.positive_time_period_milliseconds
        ),
        cv.Exclusive(CONF_EFFECT, "transformer"): cv.templatable(cv.string),
        cv.Optional(CONF_BRIGHTNESS): cv.templatable(cv.percentage),
        cv.Optional(CONF_RED): cv.templatable(cv.percentage),
        cv.Optional(CONF_GREEN): cv.templatable(cv.percentage),
        cv.Optional(CONF_BLUE): cv.templatable(cv.percentage),
        cv.Optional(CONF_WHITE): cv.templatable(cv.percentage),
        cv.Optional(CONF_COLOR_TEMPERATURE): cv.templatable(cv.color_temperature),
    }
)
LIGHT_TURN_OFF_ACTION_SCHEMA = automation.maybe_simple_id(
Ejemplo n.º 3
0

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.Exclusive(CONF_FAN_MODE, "fan_mode"):
    cv.templatable(validate_climate_fan_mode),
    cv.Exclusive(CONF_CUSTOM_FAN_MODE, "fan_mode"):
    cv.string_strict,
    cv.Exclusive(CONF_PRESET, "preset"):
    cv.templatable(validate_climate_preset),
    cv.Exclusive(CONF_CUSTOM_PRESET, "preset"):
    cv.string_strict,
    cv.Optional(CONF_SWING_MODE):
    cv.templatable(validate_climate_swing_mode),
})


@automation.register_action("climate.control", ControlAction,
                            CLIMATE_CONTROL_ACTION_SCHEMA)
async def climate_control_to_code(config, action_id, template_arg, args):
Ejemplo n.º 4
0
        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),
    }),
)
HTTP_REQUEST_POST_ACTION_SCHEMA = automation.maybe_conf(
    CONF_URL,
    HTTP_REQUEST_ACTION_SCHEMA.extend({
        cv.Optional(CONF_METHOD, default="POST"):
        cv.one_of("POST", upper=True),
        cv.Exclusive(CONF_BODY, "body"):
        cv.templatable(cv.string),
        cv.Exclusive(CONF_JSON, "body"):
        cv.Any(
            cv.lambda_,
            cv.All(cv.Schema({cv.string: cv.templatable(cv.string_strict)})),
        ),
    }),
)
HTTP_REQUEST_SEND_ACTION_SCHEMA = HTTP_REQUEST_ACTION_SCHEMA.extend({
    cv.Required(CONF_METHOD):
    cv.one_of("GET", "POST", "PUT", "DELETE", "PATCH", upper=True),
    cv.Exclusive(CONF_BODY, "body"):
    cv.templatable(cv.string),
    cv.Exclusive(CONF_JSON, "body"):
    cv.Any(
Ejemplo n.º 5
0
from esphome import config_validation as cv
from esphome import codegen as cg
from esphome.const import CONF_BLUE, CONF_GREEN, CONF_ID, CONF_RED, CONF_WHITE

ColorStruct = cg.esphome_ns.struct("Color")

MULTI_CONF = True

CONF_RED_INT = "red_int"
CONF_GREEN_INT = "green_int"
CONF_BLUE_INT = "blue_int"
CONF_WHITE_INT = "white_int"

CONFIG_SCHEMA = cv.Schema({
    cv.Required(CONF_ID): cv.declare_id(ColorStruct),
    cv.Exclusive(CONF_RED, "red"): cv.percentage,
    cv.Exclusive(CONF_RED_INT, "red"): cv.uint8_t,
    cv.Exclusive(CONF_GREEN, "green"): cv.percentage,
    cv.Exclusive(CONF_GREEN_INT, "green"): cv.uint8_t,
    cv.Exclusive(CONF_BLUE, "blue"): cv.percentage,
    cv.Exclusive(CONF_BLUE_INT, "blue"): cv.uint8_t,
    cv.Exclusive(CONF_WHITE, "white"): cv.percentage,
    cv.Exclusive(CONF_WHITE_INT, "white"): cv.uint8_t,
}).extend(cv.COMPONENT_SCHEMA)


async def to_code(config):
    r = 0
    if CONF_RED in config:
        r = int(config[CONF_RED] * 255)
    elif CONF_RED_INT in config:
Ejemplo n.º 6
0
    if m.group(4):
        conf[CONF_REF] = m.group(4)

    # print(conf)
    return BASE_SCHEMA(conf)


BASE_SCHEMA = cv.All(
    cv.Schema({
        cv.Required(CONF_URL):
        cv.url,
        cv.Optional(CONF_USERNAME):
        cv.string,
        cv.Optional(CONF_PASSWORD):
        cv.string,
        cv.Exclusive(CONF_FILE, "files"):
        validate_yaml_filename,
        cv.Exclusive(CONF_FILES, "files"):
        cv.All(
            cv.ensure_list(validate_yaml_filename),
            cv.Length(min=1),
        ),
        cv.Optional(CONF_REF):
        cv.git_ref,
        cv.Optional(CONF_REFRESH, default="1d"):
        cv.All(cv.string, cv.source_refresh),
    }),
    cv.has_at_least_one_key(CONF_FILE, CONF_FILES),
)

CONFIG_SCHEMA = cv.All(
Ejemplo n.º 7
0
TuyaLight = tuya_ns.class_("TuyaLight", light.LightOutput, cg.Component)

CONFIG_SCHEMA = cv.All(
    light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend({
        cv.GenerateID(CONF_OUTPUT_ID):
        cv.declare_id(TuyaLight),
        cv.GenerateID(CONF_TUYA_ID):
        cv.use_id(Tuya),
        cv.Optional(CONF_DIMMER_DATAPOINT):
        cv.uint8_t,
        cv.Optional(CONF_MIN_VALUE_DATAPOINT):
        cv.uint8_t,
        cv.Optional(CONF_SWITCH_DATAPOINT):
        cv.uint8_t,
        cv.Exclusive(CONF_RGB_DATAPOINT, "color"):
        cv.uint8_t,
        cv.Exclusive(CONF_HSV_DATAPOINT, "color"):
        cv.uint8_t,
        cv.Optional(CONF_COLOR_INTERLOCK, default=False):
        cv.boolean,
        cv.Inclusive(CONF_COLOR_TEMPERATURE_DATAPOINT, "color_temperature"):
        cv.uint8_t,
        cv.Optional(CONF_COLOR_TEMPERATURE_INVERT, default=False):
        cv.boolean,
        cv.Optional(CONF_MIN_VALUE):
        cv.int_,
        cv.Optional(CONF_MAX_VALUE):
        cv.int_,
        cv.Optional(CONF_COLOR_TEMPERATURE_MAX_VALUE):
        cv.int_,
Ejemplo n.º 8
0
    cg.add_define("USE_DEEP_SLEEP")


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

DEEP_SLEEP_ENTER_SCHEMA = cv.All(
    automation.maybe_simple_id(
        DEEP_SLEEP_ACTION_SCHEMA.extend(
            cv.Schema(
                {
                    cv.Exclusive(CONF_SLEEP_DURATION, "time"): cv.templatable(
                        cv.positive_time_period_milliseconds
                    ),
                    # Only on ESP32 due to how long the RTC on ESP8266 can stay asleep
                    cv.Exclusive(CONF_UNTIL, "time"): cv.All(
                        cv.only_on_esp32, cv.time_of_day
                    ),
                    cv.Optional(CONF_TIME_ID): cv.use_id(time.RealTimeClock),
                }
            )
        )
    ),
    cv.has_none_or_all_keys(CONF_UNTIL, CONF_TIME_ID),
)

Ejemplo n.º 9
0
    }
).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),
        }
    ),
)
HTTP_REQUEST_POST_ACTION_SCHEMA = automation.maybe_conf(
    CONF_URL,
    HTTP_REQUEST_ACTION_SCHEMA.extend(
        {
            cv.Optional(CONF_METHOD, default="POST"): cv.one_of("POST", upper=True),
            cv.Exclusive(CONF_BODY, "body"): cv.templatable(cv.string),
            cv.Exclusive(CONF_JSON, "body"): cv.Any(
                cv.lambda_,
                cv.All(cv.Schema({cv.string: cv.templatable(cv.string_strict)})),
            ),
        }
    ),
)
HTTP_REQUEST_SEND_ACTION_SCHEMA = HTTP_REQUEST_ACTION_SCHEMA.extend(
    {
        cv.Required(CONF_METHOD): cv.one_of(
            "GET", "POST", "PUT", "DELETE", "PATCH", upper=True
        ),
        cv.Exclusive(CONF_BODY, "body"): cv.templatable(cv.string),
        cv.Exclusive(CONF_JSON, "body"): cv.Any(
            cv.lambda_,
Ejemplo n.º 10
0
    if CONF_TILT_LAMBDA in config:
        tilt_template_ = yield cg.process_lambda(
            config[CONF_TILT_LAMBDA], [],
            return_type=cg.optional.template(float))
        cg.add(var.set_tilt_lambda(tilt_template_))

    cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
    cg.add(var.set_assumed_state(config[CONF_ASSUMED_STATE]))
    cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))


@automation.register_action('cover.template.publish', cover.CoverPublishAction,
                            cv.Schema({
                                cv.Required(CONF_ID):
                                cv.use_id(cover.Cover),
                                cv.Exclusive(CONF_STATE, 'pos'):
                                cv.templatable(cover.validate_cover_state),
                                cv.Exclusive(CONF_POSITION, 'pos'):
                                cv.templatable(cv.zero_to_one_float),
                                cv.Optional(CONF_CURRENT_OPERATION):
                                cv.templatable(cover.validate_cover_operation),
                                cv.Optional(CONF_TILT):
                                cv.templatable(cv.zero_to_one_float),
                            }))
def cover_template_publish_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_STATE in config:
        template_ = yield cg.templatable(config[CONF_STATE], args, float)
        cg.add(var.set_position(template_))
    if CONF_POSITION in config:
Ejemplo n.º 11
0
        CONF_FILE: m.group(3),
    }
    if m.group(4):
        conf[CONF_REF] = m.group(4)

    # print(conf)
    return BASE_SCHEMA(conf)


BASE_SCHEMA = cv.All(
    cv.Schema(
        {
            cv.Required(CONF_URL): cv.url,
            cv.Optional(CONF_USERNAME): cv.string,
            cv.Optional(CONF_PASSWORD): cv.string,
            cv.Exclusive(CONF_FILE, "files"): validate_yaml_filename,
            cv.Exclusive(CONF_FILES, "files"): cv.All(
                cv.ensure_list(validate_yaml_filename),
                cv.Length(min=1),
            ),
            cv.Optional(CONF_REF): cv.git_ref,
            cv.Optional(CONF_REFRESH, default="1d"): cv.All(
                cv.string, cv.source_refresh
            ),
        }
    ),
    cv.has_at_least_one_key(CONF_FILE, CONF_FILES),
)


CONFIG_SCHEMA = cv.All(
Ejemplo n.º 12
0
 cv.Optional(CONF_REVERSE_SWITCH): cv.maybe_simple_value(
     switch.SWITCH_SCHEMA.extend(
         cv.Schema(
             {
                 cv.GenerateID(): cv.declare_id(SprinklerControllerSwitch),
             }
         )
     ),
     key=CONF_NAME,
 ),
 cv.Optional(CONF_MANUAL_SELECTION_DELAY): cv.positive_time_period_seconds,
 cv.Optional(CONF_REPEAT): cv.positive_int,
 cv.Optional(CONF_PUMP_PULSE_DURATION): cv.positive_time_period_milliseconds,
 cv.Optional(CONF_VALVE_PULSE_DURATION): cv.positive_time_period_milliseconds,
 cv.Exclusive(
     CONF_PUMP_START_PUMP_DELAY, "pump_start_xxxx_delay"
 ): cv.positive_time_period_seconds,
 cv.Exclusive(
     CONF_PUMP_STOP_PUMP_DELAY, "pump_stop_xxxx_delay"
 ): cv.positive_time_period_seconds,
 cv.Optional(CONF_PUMP_SWITCH_OFF_DURING_VALVE_OPEN_DELAY): cv.boolean,
 cv.Exclusive(
     CONF_PUMP_START_VALVE_DELAY, "pump_start_xxxx_delay"
 ): cv.positive_time_period_seconds,
 cv.Exclusive(
     CONF_PUMP_STOP_VALVE_DELAY, "pump_stop_xxxx_delay"
 ): cv.positive_time_period_seconds,
 cv.Exclusive(
     CONF_VALVE_OVERLAP, "open_delay/overlap"
 ): cv.positive_time_period_seconds,
 cv.Exclusive(
Ejemplo n.º 13
0
            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 = cv.All(
    automation.maybe_simple_id({
        cv.GenerateID():
        cv.use_id(DeepSleepComponent),
        cv.Exclusive(CONF_SLEEP_DURATION, "time"):
        cv.templatable(cv.positive_time_period_milliseconds),
        # Only on ESP32 due to how long the RTC on ESP8266 can stay asleep
        cv.Exclusive(CONF_UNTIL, "time"):
        cv.All(cv.only_on_esp32, cv.time_of_day),
        cv.Optional(CONF_TIME_ID):
        cv.use_id(time.RealTimeClock),
    }),
    cv.has_none_or_all_keys(CONF_UNTIL, CONF_TIME_ID),
)

DEEP_SLEEP_PREVENT_SCHEMA = automation.maybe_simple_id({
    cv.GenerateID():
    cv.use_id(DeepSleepComponent),
})
Ejemplo n.º 14
0
async 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))
    await 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.Exclusive(CONF_FAN_MODE, "fan_mode"): cv.templatable(
            validate_climate_fan_mode
        ),
        cv.Exclusive(CONF_CUSTOM_FAN_MODE, "fan_mode"): cv.string_strict,
        cv.Exclusive(CONF_PRESET, "preset"): cv.templatable(validate_climate_preset),
        cv.Exclusive(CONF_CUSTOM_PRESET, "preset"): cv.string_strict,
        cv.Optional(CONF_SWING_MODE): cv.templatable(validate_climate_swing_mode),
    }
)


@automation.register_action(
    "climate.control", ControlAction, CLIMATE_CONTROL_ACTION_SCHEMA
)
async def climate_control_to_code(config, action_id, template_arg, args):
    paren = await cg.get_variable(config[CONF_ID])
    cv.All(cv.Schema({cv.string: cv.templatable(cv.string)})),
    cv.Optional(CONF_VERIFY_SSL, default=True):
    cv.boolean,
}).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),
    }))
HTTP_REQUEST_POST_ACTION_SCHEMA = automation.maybe_conf(
    CONF_URL,
    HTTP_REQUEST_ACTION_SCHEMA.extend({
        cv.Optional(CONF_METHOD, default='POST'):
        cv.one_of('POST', upper=True),
        cv.Exclusive(CONF_BODY, 'body'):
        cv.templatable(cv.string),
        cv.Exclusive(CONF_JSON, 'body'):
        cv.Any(
            cv.lambda_,
            cv.All(cv.Schema({cv.string: cv.templatable(cv.string_strict)})),
        ),
    }))
HTTP_REQUEST_SEND_ACTION_SCHEMA = HTTP_REQUEST_ACTION_SCHEMA.extend({
    cv.Required(CONF_METHOD):
    cv.one_of('GET', 'POST', 'PUT', 'DELETE', 'PATCH', upper=True),
    cv.Exclusive(CONF_BODY, 'body'):
    cv.templatable(cv.string),
    cv.Exclusive(CONF_JSON, 'body'):
    cv.Any(
        cv.lambda_,
Ejemplo n.º 16
0
async def light_toggle_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_TRANSITION_LENGTH in config:
        template_ = await cg.templatable(config[CONF_TRANSITION_LENGTH], args,
                                         cg.uint32)
        cg.add(var.set_transition_length(template_))
    return var


LIGHT_CONTROL_ACTION_SCHEMA = cv.Schema({
    cv.Required(CONF_ID):
    cv.use_id(LightState),
    cv.Optional(CONF_STATE):
    cv.templatable(cv.boolean),
    cv.Exclusive(CONF_TRANSITION_LENGTH, "transformer"):
    cv.templatable(cv.positive_time_period_milliseconds),
    cv.Exclusive(CONF_FLASH_LENGTH, "transformer"):
    cv.templatable(cv.positive_time_period_milliseconds),
    cv.Exclusive(CONF_EFFECT, "transformer"):
    cv.templatable(cv.string),
    cv.Optional(CONF_BRIGHTNESS):
    cv.templatable(cv.percentage),
    cv.Optional(CONF_RED):
    cv.templatable(cv.percentage),
    cv.Optional(CONF_GREEN):
    cv.templatable(cv.percentage),
    cv.Optional(CONF_BLUE):
    cv.templatable(cv.percentage),
    cv.Optional(CONF_WHITE):
    cv.templatable(cv.percentage),
Ejemplo n.º 17
0
        cv.Optional(CONF_COMMAND_THROTTLE, default="0ms"):
        cv.positive_time_period_milliseconds,
    }).extend(cv.polling_component_schema("60s")).extend(
        modbus.modbus_device_schema(0x01)))

ModbusItemBaseSchema = cv.Schema(
    {
        cv.GenerateID(CONF_MODBUS_CONTROLLER_ID):
        cv.use_id(ModbusController),
        cv.Optional(CONF_ADDRESS):
        cv.positive_int,
        cv.Optional(CONF_CUSTOM_COMMAND):
        cv.ensure_list(cv.hex_uint8_t),
        cv.Exclusive(
            CONF_OFFSET,
            "offset",
            f"{CONF_OFFSET} and {CONF_BYTE_OFFSET} can't be used together",
        ):
        cv.positive_int,
        cv.Exclusive(
            CONF_BYTE_OFFSET,
            "offset",
            f"{CONF_OFFSET} and {CONF_BYTE_OFFSET} can't be used together",
        ):
        cv.positive_int,
        cv.Optional(CONF_BITMASK, default=0xFFFFFFFF):
        cv.hex_uint32_t,
        cv.Optional(CONF_SKIP_UPDATES, default=0):
        cv.positive_int,
        cv.Optional(CONF_FORCE_NEW_RANGE, default=False):
        cv.boolean,
Ejemplo n.º 18
0
        cg.add(var.set_tilt_lambda(tilt_template_))
    if CONF_POSITION_ACTION in config:
        yield automation.build_automation(var.get_position_trigger(), [(float, 'pos')],
                                          config[CONF_POSITION_ACTION])
        cg.add(var.set_has_position(True))
    else:
        cg.add(var.set_has_position(config[CONF_HAS_POSITION]))
    cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
    cg.add(var.set_assumed_state(config[CONF_ASSUMED_STATE]))
    cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))
    cg.add(var.set_has_position(config[CONF_HAS_POSITION]))


@automation.register_action('cover.template.publish', cover.CoverPublishAction, cv.Schema({
    cv.Required(CONF_ID): cv.use_id(cover.Cover),
    cv.Exclusive(CONF_STATE, 'pos'): cv.templatable(cover.validate_cover_state),
    cv.Exclusive(CONF_POSITION, 'pos'): cv.templatable(cv.zero_to_one_float),
    cv.Optional(CONF_CURRENT_OPERATION): cv.templatable(cover.validate_cover_operation),
    cv.Optional(CONF_TILT): cv.templatable(cv.zero_to_one_float),
}))
def cover_template_publish_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_STATE in config:
        template_ = yield cg.templatable(config[CONF_STATE], args, float)
        cg.add(var.set_position(template_))
    if CONF_POSITION in config:
        template_ = yield cg.templatable(config[CONF_POSITION], args, float)
        cg.add(var.set_position(template_))
    if CONF_TILT in config:
        template_ = yield cg.templatable(config[CONF_TILT], args, float)