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, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_enter_deep_sleep_action(template_arg) type = EnterDeepSleepAction.template(template_arg) yield Pvariable(action_id, rhs, type=type) CONF_DEEP_SLEEP_PREVENT = 'deep_sleep.prevent' DEEP_SLEEP_PREVENT_ACTION_SCHEMA = maybe_simple_id({
def setup_output_platform(obj, config, skip_power_supply=False): CORE.add_job(setup_output_platform_, obj, config, skip_power_supply) def register_output(var, config): output_var = Pvariable(config[CONF_ID], var, has_side_effects=True) CORE.add_job(setup_output_platform_, output_var, config) 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, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_turn_on_action(template_arg) type = TurnOnAction.template(template_arg) yield Pvariable(action_id, rhs, type=type) CONF_OUTPUT_TURN_OFF = 'output.turn_off' OUTPUT_TURN_OFF_ACTION = maybe_simple_id( {vol.Required(CONF_ID): cv.use_variable_id(BinaryOutput)})
add(light_var.add_effects(effects)) setup_mqtt_component(light_var.Pget_mqtt(), config) def setup_light(light_obj, config): light_var = Pvariable(config[CONF_ID], light_obj, has_side_effects=False) CORE.add_job(setup_light_core_, light_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(LightState), 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, 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) action = Pvariable(action_id, rhs, type=type) if CONF_TRANSITION_LENGTH in config: for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32): yield None
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):
has_side_effects=True) CORE.add_job(setup_binary_sensor_core_, binary_sensor_obj, config) def register_binary_sensor(var, config): binary_sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True) add(App.register_binary_sensor(binary_sensor_var)) CORE.add_job(setup_binary_sensor_core_, binary_sensor_var, config) 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), vol.Optional(CONF_FOR): cv.positive_time_period_milliseconds, }) @CONDITION_REGISTRY.register(CONF_BINARY_SENSOR_IS_ON, BINARY_SENSOR_IS_ON_CONDITION_SCHEMA) def binary_sensor_is_on_to_code(config, condition_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_binary_sensor_is_on_condition(template_arg, config.get(CONF_FOR)) type = BinarySensorCondition.template(template_arg) yield Pvariable(condition_id, rhs, type=type)
def setup_cover_core_(cover_var, config): if CONF_INTERNAL in config: add(cover_var.set_internal(config[CONF_INTERNAL])) setup_mqtt_component(cover_var.Pget_mqtt(), config) def setup_cover(cover_obj, config): CORE.add_job(setup_cover_core_, cover_obj, 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(Cover), }) @ACTION_REGISTRY.register(CONF_COVER_OPEN, COVER_OPEN_ACTION_SCHEMA) def cover_open_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_open_action(template_arg) type = OpenAction.template(template_arg) yield Pvariable(action_id, rhs, type=type) CONF_COVER_CLOSE = 'cover.close' COVER_CLOSE_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.use_variable_id(Cover),
if CONF_ROTATION in config: add(display_var.set_rotation(DISPLAY_ROTATIONS[config[CONF_ROTATION]])) if CONF_PAGES in config: pages = [] for conf in config[CONF_PAGES]: for lambda_ in process_lambda(conf[CONF_LAMBDA], [(DisplayBufferRef, 'it')], return_type=void): yield var = Pvariable(conf[CONF_ID], DisplayPage.new(lambda_)) pages.append(var) add(display_var.set_pages(pages)) CONF_DISPLAY_PAGE_SHOW = 'display.page.show' DISPLAY_PAGE_SHOW_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.templatable(cv.use_variable_id(DisplayPage)), }) @ACTION_REGISTRY.register(CONF_DISPLAY_PAGE_SHOW, DISPLAY_PAGE_SHOW_ACTION_SCHEMA) def display_page_show_to_code(config, action_id, template_arg, args): type = DisplayPageShowAction.template(template_arg) action = Pvariable(action_id, type.new(), type=type) if isinstance(config[CONF_ID], core.Lambda): for template_ in templatable(config[CONF_ID], args, DisplayPagePtr): yield None add(action.set_page(template_)) else: for var in get_variable(config[CONF_ID]): yield None add(action.set_page(var))
switch_obj, has_side_effects=True) CORE.add_job(setup_switch_core_, switch_obj, config) def register_switch(var, config): switch_var = Pvariable(config[CONF_ID], var, has_side_effects=True) add(App.register_switch(switch_var)) CORE.add_job(setup_switch_core_, switch_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, 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_SWITCH_TURN_OFF = 'switch.turn_off' SWITCH_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID):