def range_condition_to_code(config, condition_id, arg_type, template_arg): for conditions in build_conditions(config, arg_type): 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], arg_type, float_): yield condition.set_min(template_) if CONF_BELOW in config: for template_ in templatable(config[CONF_BELOW], arg_type, float_): yield condition.set_max(template_) yield condition
def fan_turn_on_to_code(config, action_id, arg_type, template_arg): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_turn_on_action(template_arg) type = TurnOnAction.template(arg_type) action = Pvariable(action_id, rhs, type=type) if CONF_OSCILLATING in config: for template_ in templatable(config[CONF_OSCILLATING], arg_type, bool_): yield None add(action.set_oscillating(template_)) if CONF_SPEED in config: for template_ in templatable(config[CONF_SPEED], arg_type, FanSpeed): yield None add(action.set_speed(template_)) yield action
def delay_action_to_code(config, action_id, arg_type, template_arg): 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, arg_type, uint32): yield add(action.set_delay(template_)) yield action
def setup_sensor_core_(sensor_var, mqtt_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: filters = None 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_automation(trigger, float_, 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_automation(trigger, float_, 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_automation(trigger, float_, conf) if CONF_EXPIRE_AFTER in config: if config[CONF_EXPIRE_AFTER] is None: add(mqtt_var.disable_expire_after()) else: add(mqtt_var.set_expire_after(config[CONF_EXPIRE_AFTER])) setup_mqtt_component(mqtt_var, config)
def stepper_set_target_to_code(config, action_id, arg_type, template_arg): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_set_target_action(template_arg) type = SetTargetAction.template(arg_type) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TARGET], arg_type, int32): yield None add(action.set_target(template_)) yield action
def stepper_report_position_to_code(config, action_id, arg_type, template_arg): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_report_position_action(template_arg) type = ReportPositionAction.template(arg_type) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_POSITION], arg_type, int32): yield None add(action.set_target(template_)) yield action
def light_turn_on_to_code(config, action_id, arg_type, template_arg): 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], arg_type, uint32): yield None add(action.set_transition_length(template_)) if CONF_FLASH_LENGTH in config: for template_ in templatable(config[CONF_FLASH_LENGTH], arg_type, uint32): yield None add(action.set_flash_length(template_)) if CONF_BRIGHTNESS in config: for template_ in templatable(config[CONF_BRIGHTNESS], arg_type, float_): yield None add(action.set_brightness(template_)) if CONF_RED in config: for template_ in templatable(config[CONF_RED], arg_type, float_): yield None add(action.set_red(template_)) if CONF_GREEN in config: for template_ in templatable(config[CONF_GREEN], arg_type, float_): yield None add(action.set_green(template_)) if CONF_BLUE in config: for template_ in templatable(config[CONF_BLUE], arg_type, float_): yield None add(action.set_blue(template_)) if CONF_WHITE in config: for template_ in templatable(config[CONF_WHITE], arg_type, float_): yield None add(action.set_white(template_)) if CONF_COLOR_TEMPERATURE in config: for template_ in templatable(config[CONF_COLOR_TEMPERATURE], arg_type, float_): yield None add(action.set_color_temperature(template_)) if CONF_EFFECT in config: for template_ in templatable(config[CONF_EFFECT], arg_type, std_string): yield None add(action.set_effect(template_)) yield action
def mqtt_publish_action_to_code(config, action_id, arg_type, template_arg): rhs = App.Pget_mqtt_client().Pmake_publish_action(template_arg) type = MQTTPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TOPIC], arg_type, std_string): yield None add(action.set_topic(template_)) for template_ in templatable(config[CONF_PAYLOAD], arg_type, std_string): yield None add(action.set_payload(template_)) if CONF_QOS in config: for template_ in templatable(config[CONF_QOS], arg_type, uint8): yield add(action.set_qos(template_)) if CONF_RETAIN in config: for template_ in templatable(config[CONF_RETAIN], arg_type, bool_): yield None add(action.set_retain(template_)) yield action
def light_turn_off_to_code(config, action_id, arg_type, template_arg): 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], arg_type, uint32): yield None add(action.set_transition_length(template_)) yield action
def mqtt_publish_json_action_to_code(config, action_id, arg_type, template_arg): rhs = App.Pget_mqtt_client().Pmake_publish_json_action(template_arg) type = MQTTPublishJsonAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TOPIC], arg_type, std_string): yield None add(action.set_topic(template_)) for lambda_ in process_lambda(config[CONF_PAYLOAD], [(arg_type, 'x'), (JsonObjectRef, 'root')]): 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