2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.loxone.internal.types;
15 import java.lang.reflect.Type;
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;
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;
28 * A structure of JSON file http://miniserver/data/LoxAPP3.json used for parsing it with Gson library.
30 * @author Pawel Pieczul - initial contribution
33 public class LxConfig {
35 private Map<LxUuid, LxContainer> rooms;
36 @SerializedName("cats")
37 private Map<LxUuid, LxCategory> categories;
38 public Map<LxUuid, LxControl> controls;
40 public class LxServerInfo {
41 public String serialNr;
42 public String location;
43 public String roomTitle;
44 public String catTitle;
46 public String projectName;
47 public String remoteUrl;
48 public String swVersion;
49 public String macAddress;
52 public LxServerInfo msInfo;
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()))));
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);
71 public static String deserializeString(JsonObject parent, String name) {
72 JsonElement element = parent.get(name);
73 if (element != null) {
74 return element.getAsString();