]> git.basschouten.com Git - openhab-addons.git/blob
77331a808f173abfa0d5897d24edc235e2f85297
[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.lutron.internal.protocol;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.lutron.internal.handler.LeapBridgeHandler;
18 import org.openhab.binding.lutron.internal.protocol.leap.LeapCommand;
19 import org.openhab.binding.lutron.internal.protocol.lip.LutronCommandType;
20 import org.openhab.binding.lutron.internal.protocol.lip.LutronOperation;
21 import org.openhab.binding.lutron.internal.protocol.lip.TargetType;
22
23 /**
24  * Lutron TIMECLOCK command object
25  *
26  * @author Bob Adair - Initial contribution
27  */
28 @NonNullByDefault
29 public class TimeclockCommand extends LutronCommandNew {
30     public static final Integer ACTION_CLOCKMODE = 1;
31     public static final Integer ACTION_SUNRISE = 2;
32     public static final Integer ACTION_SUNSET = 3;
33     public static final Integer ACTION_EXECEVENT = 5;
34     public static final Integer ACTION_SETEVENT = 6;
35     public static final Integer EVENT_ENABLE = 1;
36     public static final Integer EVENT_DISABLE = 2;
37
38     private final Integer action;
39     private final @Nullable Object parameter;
40     private final @Nullable Boolean enable;
41
42     /**
43      * TimeclockCommand constructor
44      *
45      * @param targetType
46      * @param operation
47      * @param integrationId
48      * @param action
49      * @param parameter
50      * @param enable true = enable, false = disable
51      */
52     public TimeclockCommand(LutronOperation operation, Integer integrationId, Integer action,
53             @Nullable Object parameter, @Nullable Boolean enable) {
54         super(TargetType.TIMECLOCK, operation, LutronCommandType.TIMECLOCK, integrationId);
55         this.action = action;
56         this.parameter = parameter;
57         this.enable = enable;
58     }
59
60     @Override
61     public String lipCommand() {
62         StringBuilder builder = new StringBuilder().append(operation).append(commandType);
63         builder.append(',').append(integrationId);
64         builder.append(',').append(action);
65         if (parameter != null) {
66             builder.append(',').append(parameter);
67         }
68         if (enable != null) {
69             builder.append(',');
70             builder.append((enable) ? '1' : '2');
71         }
72
73         return builder.toString();
74     }
75
76     @Override
77     public @Nullable LeapCommand leapCommand(LeapBridgeHandler bridgeHandler, @Nullable Integer leapZone) {
78         return null;
79     }
80
81     @Override
82     public String toString() {
83         return lipCommand();
84     }
85 }