]> git.basschouten.com Git - openhab-addons.git/blob
9f202f3e07b36d4d3995d10da6e0dad10786f4fa
[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.siemensrds.internal;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 import com.google.gson.Gson;
23 import com.google.gson.annotations.SerializedName;
24
25 /**
26  *
27  * Interface to the Plants List of a particular User
28  *
29  * @author Andrew Fiddian-Green - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public class RdsPlants {
34
35     protected final Logger logger = LoggerFactory.getLogger(RdsPlants.class);
36
37     @SerializedName("items")
38     private @Nullable List<PlantInfo> plants;
39
40     private static final Gson GSON = new Gson();
41
42     @SuppressWarnings("null")
43     @NonNullByDefault
44     public static class PlantInfo {
45
46         @SerializedName("id")
47         private @Nullable String plantId;
48         @SerializedName("isOnline")
49         private boolean online;
50
51         public String getId() throws RdsCloudException {
52             String plantId = this.plantId;
53             if (plantId != null) {
54                 return plantId;
55             }
56             throw new RdsCloudException("plant has no Id");
57         }
58
59         public boolean isOnline() {
60             return online;
61         }
62     }
63
64     /*
65      * public method: parse JSON, and create a class that encapsulates the data
66      */
67     public static @Nullable RdsPlants createFromJson(String json) {
68         return GSON.fromJson(json, RdsPlants.class);
69     }
70
71     /*
72      * public method: return the plant list
73      */
74     public @Nullable List<PlantInfo> getPlants() {
75         return plants;
76     }
77 }