]> git.basschouten.com Git - openhab-addons.git/blob
fadc9f96ba4905889b3fe8d0b477558a6db2561d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.loxone.internal.types;
14
15 import java.lang.reflect.Type;
16 import java.util.Map;
17
18 import org.openhab.binding.loxone.internal.LxServerHandlerApi;
19 import org.openhab.binding.loxone.internal.controls.LxControl;
20 import org.openhab.binding.loxone.internal.controls.LxControl.LxControlConfig;
21
22 import com.google.gson.JsonDeserializationContext;
23 import com.google.gson.JsonElement;
24 import com.google.gson.JsonObject;
25 import com.google.gson.annotations.SerializedName;
26
27 /**
28  * A structure of JSON file http://miniserver/data/LoxAPP3.json used for parsing it with Gson library.
29  *
30  * @author Pawel Pieczul - initial contribution
31  *
32  */
33 public class LxConfig {
34
35     private Map<LxUuid, LxContainer> rooms;
36     @SerializedName("cats")
37     private Map<LxUuid, LxCategory> categories;
38     public Map<LxUuid, LxControl> controls;
39
40     public class LxServerInfo {
41         public String serialNr;
42         public String location;
43         public String roomTitle;
44         public String catTitle;
45         public String msName;
46         public String projectName;
47         public String remoteUrl;
48         public String swVersion;
49         public String macAddress;
50     }
51
52     public LxServerInfo msInfo;
53
54     public void finalize(LxServerHandlerApi thingHandler) {
55         rooms.values().removeIf(o -> (o == null || o.getUuid() == null));
56         categories.values().removeIf(o -> (o == null || o.getUuid() == null));
57         controls.values().removeIf(c -> c == null || c.isSecured());
58         controls.values().forEach(c -> c.initialize(
59                 new LxControlConfig(thingHandler, rooms.get(c.getRoomUuid()), categories.get(c.getCategoryUuid()))));
60     }
61
62     public static <T> T deserializeObject(JsonObject parent, String name, Type type,
63             JsonDeserializationContext context) {
64         JsonElement element = parent.get(name);
65         if (element != null) {
66             return context.deserialize(element, type);
67         }
68         return null;
69     }
70
71     public static String deserializeString(JsonObject parent, String name) {
72         JsonElement element = parent.get(name);
73         if (element != null) {
74             return element.getAsString();
75         }
76         return null;
77     }
78 }