]> git.basschouten.com Git - openhab-addons.git/blob
ed7c7b9ff8f5c21f9f6ce48a35043b4d0af08f18
[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 import org.openhab.binding.ecobee.internal.enums.PlugState;
21
22 /**
23  * Control the on/off state of a plug by setting a hold on the plug. Creates a hold for the on or off state of the plug
24  * for the specified duration. Note that an event is created regardless of whether the program is in the same state as
25  * the requested state.
26  *
27  * @author John Cocula - Initial contribution
28  * @author Mark Hilbush - Adapt for OH2/3
29  */
30 @NonNullByDefault
31 public final class ControlPlugFunction extends AbstractFunction {
32
33     public ControlPlugFunction(@Nullable String plugName, @Nullable PlugState plugState, @Nullable Date startDateTime,
34             @Nullable Date endDateTime, @Nullable HoldType holdType, @Nullable Integer holdHours) {
35         super("controlPlug");
36
37         if (plugName == null || plugState == null) {
38             throw new IllegalArgumentException("plugName and plugState arguments are required.");
39         }
40         if (holdType == HoldType.DATE_TIME && endDateTime == null) {
41             throw new IllegalArgumentException("End date/time is required for dateTime hold type.");
42         }
43         if (holdType == HoldType.HOLD_HOURS && holdHours == null) {
44             throw new IllegalArgumentException("holdHours must be specified when using holdHours hold type.");
45         }
46         params.put("plugName", plugName);
47         params.put("plugState", plugState);
48         if (startDateTime != null) {
49             params.put("startDate", YMD.format(startDateTime));
50             params.put("startTime", HMS.format(startDateTime));
51         }
52         if (endDateTime != null) {
53             params.put("endDate", YMD.format(endDateTime));
54             params.put("endTime", HMS.format(endDateTime));
55         }
56         if (holdType != null) {
57             params.put("holdType", holdType);
58         }
59         if (holdHours != null) {
60             params.put("holdHours", holdHours);
61         }
62     }
63 }