]> git.basschouten.com Git - openhab-addons.git/blob
38c27442ddafd1ee2144914a692ee450adf6d440
[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.digitalstrom.internal.lib.structure.impl;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
19 import org.openhab.binding.digitalstrom.internal.lib.structure.Apartment;
20 import org.openhab.binding.digitalstrom.internal.lib.structure.Zone;
21
22 import com.google.gson.JsonArray;
23 import com.google.gson.JsonObject;
24
25 /**
26  * The {@link JSONApartmentImpl} is the implementation of the {@link Apartment}.
27  *
28  * @author Alexander Betker - Initial contribution
29  * @author Michael Ochel - change from SimpleJSON to GSON
30  * @author Matthias Siegele - change from SimpleJSON to GSON
31  */
32 public class JSONApartmentImpl implements Apartment {
33
34     private Map<Integer, Zone> zoneMap = new HashMap<>();
35
36     /**
37      * Creates a new {@link JSONApartmentImpl} through the {@link JsonObject}.
38      *
39      * @param jObject of the server response, must not be null
40      */
41     public JSONApartmentImpl(JsonObject jObject) {
42         if (jObject.get(JSONApiResponseKeysEnum.ZONES.getKey()) instanceof JsonArray) {
43             JsonArray zones = (JsonArray) jObject.get(JSONApiResponseKeysEnum.ZONES.getKey());
44             for (int i = 0; i < zones.size(); i++) {
45                 if (zones.get(i) instanceof JsonObject) {
46                     Zone zone = new JSONZoneImpl((JsonObject) zones.get(i));
47                     zoneMap.put(zone.getZoneId(), zone);
48                 }
49             }
50         }
51     }
52
53     @Override
54     public Map<Integer, Zone> getZoneMap() {
55         return zoneMap;
56     }
57 }