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 javax.measure.quantity.Temperature;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.ecobee.internal.enums.FanMode;
22 import org.openhab.core.library.types.QuantityType;
23 import org.openhab.core.library.unit.ImperialUnits;
26 * The create vacation function creates a vacation event on the thermostat. If the
27 * start/end date/times are not provided for the vacation event, the vacation event
28 * will begin immediately and last 14 days. If both the coolHoldTemp and heatHoldTemp
29 * parameters provided to this function have the same value, and the Thermostat is
30 * in auto mode, then the two values will be adjusted during processing to be
31 * separated by the value stored in Thermostat.Settings#heatCoolMinDelta.
33 * @author John Cocula - Initial contribution
34 * @author Mark Hilbush - Adapt for OH2/3
37 public final class CreateVacationFunction extends AbstractFunction {
39 public CreateVacationFunction(@Nullable String name, @Nullable QuantityType<Temperature> coolHoldTemp,
40 @Nullable QuantityType<Temperature> heatHoldTemp, @Nullable Date startDateTime, @Nullable Date endDateTime,
41 @Nullable FanMode fan, @Nullable Integer fanMinOnTime) {
42 super("createVacation");
44 if (name == null || coolHoldTemp == null || heatHoldTemp == null) {
45 throw new IllegalArgumentException("name, coolHoldTemp and heatHoldTemp arguments are required.");
47 params.put("name", name);
49 QuantityType<Temperature> convertedCoolHoldTemp = coolHoldTemp.toUnit(ImperialUnits.FAHRENHEIT);
50 QuantityType<Temperature> convertedHeatHoldTemp = heatHoldTemp.toUnit(ImperialUnits.FAHRENHEIT);
51 if (convertedCoolHoldTemp == null || convertedHeatHoldTemp == null) {
52 throw new IllegalArgumentException("coolHoldTemp or heatHoldTemp are not proper QuantityTypes");
54 params.put("coolHoldTemp", Integer.valueOf(convertedCoolHoldTemp.intValue()));
55 params.put("heatHoldTemp", Integer.valueOf(convertedHeatHoldTemp.intValue()));
57 if (startDateTime != null) {
58 params.put("startDate", YMD.format(startDateTime));
59 params.put("startTime", HMS.format(startDateTime));
61 if (endDateTime != null) {
62 params.put("endDate", YMD.format(endDateTime));
63 params.put("endTime", HMS.format(endDateTime));
66 params.put("fan", fan);
68 if (fanMinOnTime != null) {
69 // doc says String not Integer for fanMinOnTime parameter (@watou)
70 params.put("fanMinOnTime", fanMinOnTime.toString());