]> git.basschouten.com Git - openhab-addons.git/blob
8d4f06e40dafef9a052327681707428f797e79df
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.ecobee.internal.function;
14
15 import java.util.Date;
16
17 import javax.measure.quantity.Temperature;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.ecobee.internal.enums.FanMode;
22 import org.openhab.core.library.types.QuantityType;
23 import org.openhab.core.library.unit.ImperialUnits;
24
25 /**
26  * The create vacation function creates a vacation event on the thermostat. If the
27  * start/end date/times are not provided for the vacation event, the vacation event
28  * will begin immediately and last 14 days. If both the coolHoldTemp and heatHoldTemp
29  * parameters provided to this function have the same value, and the Thermostat is
30  * in auto mode, then the two values will be adjusted during processing to be
31  * separated by the value stored in Thermostat.Settings#heatCoolMinDelta.
32  *
33  * @author John Cocula - Initial contribution
34  * @author Mark Hilbush - Adapt for OH2/3
35  */
36 @NonNullByDefault
37 public final class CreateVacationFunction extends AbstractFunction {
38
39     public CreateVacationFunction(@Nullable String name, @Nullable QuantityType<Temperature> coolHoldTemp,
40             @Nullable QuantityType<Temperature> heatHoldTemp, @Nullable Date startDateTime, @Nullable Date endDateTime,
41             @Nullable FanMode fan, @Nullable Integer fanMinOnTime) {
42         super("createVacation");
43
44         if (name == null || coolHoldTemp == null || heatHoldTemp == null) {
45             throw new IllegalArgumentException("name, coolHoldTemp and heatHoldTemp arguments are required.");
46         }
47         params.put("name", name);
48
49         QuantityType<Temperature> convertedCoolHoldTemp = coolHoldTemp.toUnit(ImperialUnits.FAHRENHEIT);
50         QuantityType<Temperature> convertedHeatHoldTemp = heatHoldTemp.toUnit(ImperialUnits.FAHRENHEIT);
51         if (convertedCoolHoldTemp == null || convertedHeatHoldTemp == null) {
52             throw new IllegalArgumentException("coolHoldTemp or heatHoldTemp are not proper QuantityTypes");
53         }
54         params.put("coolHoldTemp", Integer.valueOf(convertedCoolHoldTemp.intValue()));
55         params.put("heatHoldTemp", Integer.valueOf(convertedHeatHoldTemp.intValue()));
56
57         if (startDateTime != null) {
58             params.put("startDate", YMD.format(startDateTime));
59             params.put("startTime", HMS.format(startDateTime));
60         }
61         if (endDateTime != null) {
62             params.put("endDate", YMD.format(endDateTime));
63             params.put("endTime", HMS.format(endDateTime));
64         }
65         if (fan != null) {
66             params.put("fan", fan);
67         }
68         if (fanMinOnTime != null) {
69             // doc says String not Integer for fanMinOnTime parameter (@watou)
70             params.put("fanMinOnTime", fanMinOnTime.toString());
71         }
72     }
73 }