]> git.basschouten.com Git - openhab-addons.git/blob
c8370d00c17acd31a227cf65335c6a18d20a4b56
[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.io.hueemulation.internal.dto;
14
15 import java.util.Collections;
16 import java.util.Map;
17 import java.util.TreeMap;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
22  * Hue data store object. Contains all lights, configuration, user whitelist etc.
23  * Is used as a data store but also as API DTO.
24  *
25  * @author Dan Cunningham - Initial contribution
26  * @author David Graeff - Add groups,scenes,rules,sensors,resourcelinks and config entries
27  *
28  */
29 @NonNullByDefault
30 public class HueDataStore {
31     public HueAuthorizedConfig config = new HueAuthorizedConfig();
32     public TreeMap<String, HueLightEntry> lights = new TreeMap<>();
33     public TreeMap<String, HueGroupEntry> groups = new TreeMap<>();
34     public Map<String, HueSceneEntry> scenes = new TreeMap<>();
35     public Map<String, HueRuleEntry> rules = new TreeMap<>();
36     public Map<String, HueSensorEntry> sensors = new TreeMap<>();
37     public Map<String, HueScheduleEntry> schedules = new TreeMap<>();
38     public Map<Integer, Dummy> resourcelinks = Collections.emptyMap();
39     public Map<String, HueCapability> capabilities = new TreeMap<>();
40
41     public HueDataStore() {
42         resetGroupsAndLights();
43         capabilities.put("lights", new HueCapability());
44         capabilities.put("groups", new HueCapability());
45         capabilities.put("scenes", new HueCapability());
46         capabilities.put("rules", new HueCapability());
47         capabilities.put("sensors", new HueCapability());
48         capabilities.put("schedules", new HueCapability());
49         capabilities.put("resourcelinks", new HueCapability());
50     }
51
52     public void resetGroupsAndLights() {
53         groups.clear();
54         lights.clear();
55         // There must be a group 0 all the time!
56         groups.put("0", new HueGroupEntry("All lights", null, null));
57     }
58
59     public void resetSensors() {
60         sensors.clear();
61     }
62
63     public static class Dummy {
64     }
65
66     /**
67      * Return a unique group id.
68      */
69     public String nextGroupID() {
70         int nextId = groups.size();
71         while (true) {
72             String id = "hueemulation" + String.valueOf(nextId);
73             if (!groups.containsKey(id)) {
74                 return id;
75             }
76             ++nextId;
77         }
78     }
79 }