package com.example.iot_controlhost.utils.control.temperature.strategy;

import com.example.iot_controlhost.utils.global.AutoModelSet;
import com.example.iot_controlhost.utils.global.RoomSensor;
import com.example.iot_controlhost.utils.global.RoomSetting;
import com.example.iot_controlhost.utils.global.SpinnerList;
import com.example.iot_controlhost.utils.global.Variable;
import com.example.iot_controlhost.utils.log.MyLog;

/**
 * @Description 节能模式 更宽泛的温度区间 无保温措施
 * @Author DuanKaiji
 * @CreateTime 2023年10月24日 09:36:38
 */
public class SavingControl extends ControlStrategy {
    private static boolean needHeatToTarget = false;
    private static boolean needColdToTarget = false;

    @Override
    public void controlAlgorithm(double curTemperature, double targetTemperature) {
        String autoTemperatureHeat = AutoModelSet.getAutoTemperatureHeat();
        String autoTemperatureCool = AutoModelSet.getAutoTemperatureCool();
        if (curTemperature < targetTemperature - Variable.AUTO_DO_NOTHING_TEMPERATURE_SAVING
                || curTemperature < targetTemperature && needHeatToTarget) {
            MyLog.auto("节能模式：正在升温");
            needHeatToTarget = true;
            if (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[0])) {
                //均不可用
            } else if (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[1])) {
                //地暖
                gear = 5;
            } else if (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[2])) {
                //空调
                temp = 30;
                mode = 0;
            } else if (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[3])) {
                //空调和地暖
                temp = 30;
                mode = 0;
                gear = 5;
            }
        } else if (curTemperature > targetTemperature + Variable.AUTO_DO_NOTHING_TEMPERATURE_SAVING
                || curTemperature > targetTemperature && needColdToTarget) {
            MyLog.auto("节能模式：正在降温");
            needColdToTarget = true;
            if (autoTemperatureCool.equals(SpinnerList.TEMPERATURE_COOL[1])) {
                //空调
                mode = 2;
                temp = 17;
                MyLog.auto("高精度模式：开启空调制冷17度");
            } else {
                //均不可用
                MyLog.auto("高精度模式：理应降温，但降温设备设置为‘均不可用’");
            }
        } else {
            //在正常范围内
            needHeatToTarget = false;
            needColdToTarget = false;
        }
    }
}
