2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ecobee.internal.function;
15 import java.util.Date;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.ecobee.internal.enums.HoldType;
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.
32 * @author John Cocula - Initial contribution
33 * @author Mark Hilbush - Adapt for OH2/3
36 public final class SetOccupiedFunction extends AbstractFunction {
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
42 if (occupied == null) {
43 throw new IllegalArgumentException("occupied state is required.");
45 params.put("occupied", occupied);
47 if (startDateTime != null) {
48 params.put("startDate", YMD.format(startDateTime));
49 params.put("startTime", HMS.format(startDateTime));
51 if (endDateTime != null) {
52 params.put("endDate", YMD.format(endDateTime));
53 params.put("endTime", HMS.format(endDateTime));
56 if (holdType == HoldType.HOLD_HOURS && holdHours == null) {
57 throw new IllegalArgumentException("holdHours must be specified when holdType='holdHours'");
59 if (holdType == HoldType.DATE_TIME && endDateTime == null) {
60 throw new IllegalArgumentException("endDateTime must be specific when holdType='dateTime'");
63 if (holdType != null) {
64 params.put("holdType", holdType);
66 if (holdHours != null) {
67 params.put("holdHours", holdHours);