]> git.basschouten.com Git - openhab-addons.git/blob
a4be2efe1d81399bbbaebfaa2f8ea5ea0d6c5e2b
[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.leap.Request;
20 import org.openhab.binding.lutron.internal.protocol.lip.LutronCommandType;
21 import org.openhab.binding.lutron.internal.protocol.lip.LutronOperation;
22 import org.openhab.binding.lutron.internal.protocol.lip.TargetType;
23
24 /**
25  * Lutron GROUP command object
26  *
27  * @author Bob Adair - Initial contribution
28  */
29 @NonNullByDefault
30 public class GroupCommand extends LutronCommandNew {
31     public static final Integer ACTION_GROUPSTATE = 3;
32     public static final Integer STATE_GRP_OCCUPIED = 3;
33     public static final Integer STATE_GRP_UNOCCUPIED = 4;
34     public static final Integer STATE_GRP_UNKNOWN = 255;
35
36     private final Integer action;
37     private final @Nullable Integer state;
38
39     /**
40      * GroupCommand constructor
41      *
42      * @param targetType
43      * @param operation
44      * @param integrationId
45      * @param action
46      * @param state
47      */
48     public GroupCommand(LutronOperation operation, Integer integrationId, Integer action, @Nullable Integer state) {
49         super(TargetType.GROUP, operation, LutronCommandType.GROUP, integrationId);
50         this.action = action;
51         this.state = state;
52     }
53
54     @Override
55     public String lipCommand() {
56         StringBuilder builder = new StringBuilder().append(operation).append(commandType);
57         builder.append(',').append(integrationId);
58         builder.append(',').append(action);
59         if (state != null) {
60             builder.append(',').append(state);
61         }
62
63         return builder.toString();
64     }
65
66     @Override
67     public @Nullable LeapCommand leapCommand(LeapBridgeHandler bridgeHandler, @Nullable Integer leapZone) {
68         if (action.equals(GroupCommand.ACTION_GROUPSTATE)) {
69             // Get status for all occupancy groups because you can't query just one
70             return new LeapCommand(Request.getOccupancyGroupStatus());
71         } else {
72             return null;
73         }
74     }
75
76     @Override
77     public String toString() {
78         return lipCommand();
79     }
80 }