]> git.basschouten.com Git - openhab-addons.git/blob
f555f776f3db6678816133e48cc237a60286a145
[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.enums.HoldType;
20
21 /**
22  * The set occupied function may only be used by EMS thermostats. The function switches a
23  * thermostat from occupied mode to unoccupied, or vice versa. If used on a Smart thermostat,
24  * the function will throw an error. Switch occupancy events are treated as Holds.
25  * There may only be one Switch Occupancy at one time, and the new event will replace any previous event.
26  * Note that an occupancy event is created regardless what the program on the thermostat is set
27  * to. For example, if the program is currently unoccupied and you set occupied=false, an
28  * occupancy event will be created using the heat/cool settings of the unoccupied program
29  * climate. If your intent is to go back to the program and remove the occupancy event,
30  * use ResumeProgramFunction instead.
31  *
32  * @author John Cocula - Initial contribution
33  * @author Mark Hilbush - Adapt for OH2/3
34  */
35 @NonNullByDefault
36 public final class SetOccupiedFunction extends AbstractFunction {
37
38     public SetOccupiedFunction(@Nullable Boolean occupied, @Nullable Date startDateTime, @Nullable Date endDateTime,
39             @Nullable HoldType holdType, @Nullable Integer holdHours) {
40         super("setOccupied"); // not in doc; assuming
41
42         if (occupied == null) {
43             throw new IllegalArgumentException("occupied state is required.");
44         }
45         params.put("occupied", occupied);
46
47         if (startDateTime != null) {
48             params.put("startDate", YMD.format(startDateTime));
49             params.put("startTime", HMS.format(startDateTime));
50         }
51         if (endDateTime != null) {
52             params.put("endDate", YMD.format(endDateTime));
53             params.put("endTime", HMS.format(endDateTime));
54         }
55
56         if (holdType == HoldType.HOLD_HOURS && holdHours == null) {
57             throw new IllegalArgumentException("holdHours must be specified when holdType='holdHours'");
58         }
59         if (holdType == HoldType.DATE_TIME && endDateTime == null) {
60             throw new IllegalArgumentException("endDateTime must be specific when holdType='dateTime'");
61         }
62
63         if (holdType != null) {
64             params.put("holdType", holdType);
65         }
66         if (holdHours != null) {
67             params.put("holdHours", holdHours);
68         }
69     }
70 }