]> git.basschouten.com Git - openhab-addons.git/blob
5a1c19e3ce2e2cdaf0d7098526b04513a226f09c
[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 org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.ecobee.internal.dto.thermostat.EventDTO;
20 import org.openhab.binding.ecobee.internal.enums.HoldType;
21
22 /**
23  * The set hold function sets the thermostat into a hold with the specified temperature.
24  * Creates a hold for the specified duration. Note that an event is created regardless
25  * of whether the program is in the same state as the requested state. There is also
26  * support for creating a hold by passing a holdClimateRef request parameter/value pair
27  * to this function (See Event). When an existing and valid Thermostat.Climate#climateRef
28  * value is passed to this function, the coolHoldTemp, heatHoldTemp and fan mode from
29  * that Thermostat.Climate are used in the creation of the hold event. The values from
30  * that Climate will take precedence over any coolHoldTemp, heatHoldTemp, and fan
31  * mode parameters passed into this function separately. To resume from a hold and
32  * return to the program, use the ResumeProgramFunction.
33  *
34  * @author John Cocula - Initial contribution
35  * @author Mark Hilbush - Adapt for OH2/3
36  */
37 @NonNullByDefault
38 public final class SetHoldFunction extends AbstractFunction {
39
40     public SetHoldFunction(@Nullable EventDTO event, @Nullable HoldType holdType, @Nullable Integer holdHours,
41             @Nullable Date startDateTime, @Nullable Date endDateTime) {
42         super("setHold");
43
44         if (event == null) {
45             throw new IllegalArgumentException("event must not be null");
46         }
47         if (holdType == HoldType.HOLD_HOURS && holdHours == null) {
48             throw new IllegalArgumentException("holdHours must be specified when holdType='holdHours'");
49         } else if (holdType == HoldType.DATE_TIME && endDateTime == null) {
50             throw new IllegalArgumentException("endDateTime must be specified when holdType='dateTime'");
51         }
52         if (event.holdClimateRef == null) {
53             if (Boolean.TRUE.equals(event.isTemperatureAbsolute) && Boolean.TRUE.equals(event.isTemperatureRelative)) {
54                 throw new IllegalArgumentException("cannot set both absolute and relative temperatures");
55             }
56             if (Boolean.TRUE.equals(event.isTemperatureAbsolute)
57                     && (event.coolHoldTemp == null || event.heatHoldTemp == null)) {
58                 throw new IllegalArgumentException(
59                         "coolHoldTemp and heatHoldTemp must be specified when 'isTemperatureAbsolute' is true");
60             }
61             if (Boolean.TRUE.equals(event.isTemperatureRelative)
62                     && (event.coolRelativeTemp == null || event.heatRelativeTemp == null)) {
63                 throw new IllegalArgumentException(
64                         "coolRelativeTemp and heatRelativeTemp must be specified when 'isTemperatureRelative' is true");
65             }
66         }
67         // Make parameters from the input event
68         if (event.isOccupied != null) {
69             params.put("isOccupied", event.isOccupied);
70         }
71         if (event.isCoolOff != null) {
72             params.put("isCoolOff", event.isCoolOff);
73         }
74         if (event.isHeatOff != null) {
75             params.put("isHeatOff", event.isHeatOff);
76         }
77         if (event.coolHoldTemp != null) {
78             params.put("coolHoldTemp", event.coolHoldTemp);
79         }
80         if (event.heatHoldTemp != null) {
81             params.put("heatHoldTemp", event.heatHoldTemp);
82         }
83         if (event.fan != null) {
84             params.put("fan", event.fan);
85         }
86         if (event.vent != null) {
87             params.put("vent", event.vent);
88         }
89         if (event.ventilatorMinOnTime != null) {
90             params.put("ventilatorMinOnTime", event.ventilatorMinOnTime);
91         }
92         if (event.isOptional != null) {
93             params.put("isOptional", event.isOptional);
94         }
95         if (event.isTemperatureRelative != null) {
96             params.put("isTemperatureRelative", event.isTemperatureRelative);
97         }
98         if (event.coolRelativeTemp != null) {
99             params.put("coolRelativeTemp", event.coolRelativeTemp);
100         }
101         if (event.heatRelativeTemp != null) {
102             params.put("heatRelativeTemp", event.heatRelativeTemp);
103         }
104         if (event.isTemperatureAbsolute != null) {
105             params.put("isTemperatureAbsolute", event.isTemperatureAbsolute);
106         }
107         if (event.fanMinOnTime != null) {
108             params.put("fanMinOnTime", event.fanMinOnTime);
109         }
110         if (event.holdClimateRef != null) {
111             params.put("holdClimateRef", event.holdClimateRef);
112         }
113
114         // Make parameters from the holdType and hold options
115         if (holdType != null) {
116             params.put("holdType", holdType);
117         }
118         if (holdHours != null) {
119             params.put("holdHours", holdHours);
120         }
121         if (startDateTime != null) {
122             params.put("startDate", YMD.format(startDateTime));
123             params.put("startTime", HMS.format(startDateTime));
124         }
125         if (endDateTime != null) {
126             params.put("endDate", YMD.format(endDateTime));
127             params.put("endTime", HMS.format(endDateTime));
128         }
129     }
130 }