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;
20 import org.openhab.binding.ecobee.internal.enums.PlugState;
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.
27 * @author John Cocula - Initial contribution
28 * @author Mark Hilbush - Adapt for OH2/3
31 public final class ControlPlugFunction extends AbstractFunction {
33 public ControlPlugFunction(@Nullable String plugName, @Nullable PlugState plugState, @Nullable Date startDateTime,
34 @Nullable Date endDateTime, @Nullable HoldType holdType, @Nullable Integer holdHours) {
37 if (plugName == null || plugState == null) {
38 throw new IllegalArgumentException("plugName and plugState arguments are required.");
40 if (holdType == HoldType.DATE_TIME && endDateTime == null) {
41 throw new IllegalArgumentException("End date/time is required for dateTime hold type.");
43 if (holdType == HoldType.HOLD_HOURS && holdHours == null) {
44 throw new IllegalArgumentException("holdHours must be specified when using holdHours hold type.");
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));
52 if (endDateTime != null) {
53 params.put("endDate", YMD.format(endDateTime));
54 params.put("endTime", HMS.format(endDateTime));
56 if (holdType != null) {
57 params.put("holdType", holdType);
59 if (holdHours != null) {
60 params.put("holdHours", holdHours);