def range_condition_to_code(config, condition_id, template_arg, args): for conditions in build_conditions(config, template_arg, args): yield rhs = RangeCondition.new(template_arg, conditions) type = RangeCondition.template(template_arg) condition = Pvariable(condition_id, rhs, type=type) if CONF_ABOVE in config: for template_ in templatable(config[CONF_ABOVE], args, float_): yield condition.set_min(template_) if CONF_BELOW in config: for template_ in templatable(config[CONF_BELOW], args, float_): yield condition.set_max(template_) yield condition
def fan_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) action = Pvariable(action_id, rhs, type=type) if CONF_OSCILLATING in config: for template_ in templatable(config[CONF_OSCILLATING], args, bool_): yield None add(action.set_oscillating(template_)) if CONF_SPEED in config: for template_ in templatable(config[CONF_SPEED], args, FanSpeed): yield None if isinstance(template_, string_types): template_ = FAN_SPEEDS[template_] add(action.set_speed(template_)) yield action
def delay_action_to_code(config, action_id, template_arg, args): rhs = App.register_component(DelayAction.new(template_arg)) type = DelayAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config, args, uint32): yield add(action.set_delay(template_)) yield action
def setup_sensor_core_(sensor_var, config): if CONF_INTERNAL in config: add(sensor_var.set_internal(config[CONF_INTERNAL])) if CONF_UNIT_OF_MEASUREMENT in config: add( sensor_var.set_unit_of_measurement( config[CONF_UNIT_OF_MEASUREMENT])) if CONF_ICON in config: add(sensor_var.set_icon(config[CONF_ICON])) if CONF_ACCURACY_DECIMALS in config: add(sensor_var.set_accuracy_decimals(config[CONF_ACCURACY_DECIMALS])) if CONF_FILTERS in config: for filters in setup_filters(config[CONF_FILTERS]): yield add(sensor_var.set_filters(filters)) for conf in config.get(CONF_ON_VALUE, []): rhs = sensor_var.make_state_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automations(trigger, [(float_, 'x')], conf) for conf in config.get(CONF_ON_RAW_VALUE, []): rhs = sensor_var.make_raw_state_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automations(trigger, [(float_, 'x')], conf) for conf in config.get(CONF_ON_VALUE_RANGE, []): rhs = sensor_var.make_value_range_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) add(App.register_component(trigger)) if CONF_ABOVE in conf: for template_ in templatable(conf[CONF_ABOVE], float_, float_): yield add(trigger.set_min(template_)) if CONF_BELOW in conf: for template_ in templatable(conf[CONF_BELOW], float_, float_): yield add(trigger.set_max(template_)) automation.build_automations(trigger, [(float_, 'x')], conf) mqtt_ = sensor_var.Pget_mqtt() if CONF_EXPIRE_AFTER in config: if config[CONF_EXPIRE_AFTER] is None: add(mqtt_.disable_expire_after()) else: add(mqtt_.set_expire_after(config[CONF_EXPIRE_AFTER])) setup_mqtt_component(mqtt_, config)
def sensor_template_publish_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_sensor_publish_action(template_arg) type = SensorPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_STATE], args, float_): yield None add(action.set_state(template_)) yield action
def servo_write_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = ServoWriteAction.new(template_arg, var) type = ServoWriteAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_LEVEL], args, float_): yield None add(action.set_value(template_)) yield action
def output_set_level_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_set_level_action(template_arg) type = SetLevelAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_LEVEL], args, float_): yield None add(action.set_level(template_)) yield action
def stepper_set_target_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_set_target_action(template_arg) type = SetTargetAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TARGET], args, int32): yield None add(action.set_target(template_)) yield action
def stepper_report_position_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_report_position_action(template_arg) type = ReportPositionAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_POSITION], args, int32): yield None add(action.set_position(template_)) yield action
def light_turn_off_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_turn_off_action(template_arg) type = TurnOffAction.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(action.set_transition_length(template_)) yield action
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)) yield action
def light_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) 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(action.set_transition_length(template_)) if CONF_FLASH_LENGTH in config: for template_ in templatable(config[CONF_FLASH_LENGTH], args, uint32): yield None add(action.set_flash_length(template_)) if CONF_BRIGHTNESS in config: for template_ in templatable(config[CONF_BRIGHTNESS], args, float_): yield None add(action.set_brightness(template_)) if CONF_RED in config: for template_ in templatable(config[CONF_RED], args, float_): yield None add(action.set_red(template_)) if CONF_GREEN in config: for template_ in templatable(config[CONF_GREEN], args, float_): yield None add(action.set_green(template_)) if CONF_BLUE in config: for template_ in templatable(config[CONF_BLUE], args, float_): yield None add(action.set_blue(template_)) if CONF_WHITE in config: for template_ in templatable(config[CONF_WHITE], args, float_): yield None add(action.set_white(template_)) if CONF_COLOR_TEMPERATURE in config: for template_ in templatable(config[CONF_COLOR_TEMPERATURE], args, float_): yield None add(action.set_color_temperature(template_)) if CONF_EFFECT in config: for template_ in templatable(config[CONF_EFFECT], args, std_string): yield None add(action.set_effect(template_)) yield action
def mqtt_publish_action_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_publish_action(template_arg) type = MQTTPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TOPIC], args, std_string): yield None add(action.set_topic(template_)) for template_ in templatable(config[CONF_PAYLOAD], args, std_string): yield None add(action.set_payload(template_)) if CONF_QOS in config: for template_ in templatable(config[CONF_QOS], args, uint8): yield add(action.set_qos(template_)) if CONF_RETAIN in config: for template_ in templatable(config[CONF_RETAIN], args, bool_): yield None add(action.set_retain(template_)) yield action
def cover_template_publish_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_cover_publish_action(template_arg) type = CoverPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) state = config[CONF_STATE] if isinstance(state, string_types): template_ = cover.COVER_STATES[state] else: for template_ in templatable(state, args, cover.CoverState): yield None add(action.set_state(template_)) yield action
def mqtt_publish_json_action_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_publish_json_action(template_arg) type = MQTTPublishJsonAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TOPIC], args, std_string): yield None add(action.set_topic(template_)) args_ = args + [(JsonObjectRef, 'root')] for lambda_ in process_lambda(config[CONF_PAYLOAD], args_, return_type=void): yield None add(action.set_payload(lambda_)) if CONF_QOS in config: add(action.set_qos(config[CONF_QOS])) if CONF_RETAIN in config: add(action.set_retain(config[CONF_RETAIN])) yield action