]> git.basschouten.com Git - openhab-addons.git/blob
b7d89c9dd96d111afcf27035641f600b38e39bfe
[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.hue.internal.api.dto.clip1;
14
15 import java.lang.reflect.Type;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.Map;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22
23 import com.google.gson.reflect.TypeToken;
24
25 /**
26  * Detailed group information.
27  *
28  * @author Q42 - Initial contribution
29  * @author Denis Dudnik - moved Jue library source code inside the smarthome Hue binding
30  * @author Laurent Garnier - field state added
31  */
32 @NonNullByDefault
33 public class FullGroup extends Group {
34     public static final Type GSON_TYPE = new TypeToken<Map<String, FullGroup>>() {
35     }.getType();
36
37     private @Nullable State action;
38     private @Nullable List<String> lights;
39     private @Nullable State groupState; // Will not be set by hue API
40
41     FullGroup() {
42         super();
43     }
44
45     /**
46      * Test constructor
47      */
48     public FullGroup(String id, String name, String type, State action, List<String> lights, State state) {
49         super(id, name, type);
50         this.action = action;
51         this.lights = lights;
52         this.groupState = state;
53     }
54
55     /**
56      * Returns the last sent state update to the group.
57      * This does not have to reflect the current state of the group.
58      *
59      * @return last state update
60      */
61     public @Nullable State getAction() {
62         return action;
63     }
64
65     /**
66      * Returns a list of the lights in the group.
67      *
68      * @return lights in the group
69      */
70     public List<String> getLightIds() {
71         List<String> lights = this.lights;
72         return lights != null ? lights : new ArrayList<>();
73     }
74
75     /**
76      * Returns the current state of the group.
77      *
78      * @return current state
79      */
80     public State getState() {
81         State groupState = this.groupState;
82         if (groupState == null) {
83             throw new IllegalStateException("Group state not initialized when requested");
84         }
85         return groupState;
86     }
87
88     public void setState(State state) {
89         this.groupState = state;
90     }
91 }