]> git.basschouten.com Git - openhab-addons.git/blob
09ab0015aed319df1a5dfc519d5dd1b98f934685
[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.opengarage.internal.api;
14
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 import com.google.gson.JsonObject;
19 import com.google.gson.JsonParser;
20
21 /**
22  * Class for holding the set of parameters used to read the controller variables.
23  *
24  * @author Paul Smedley - Initial Contribution
25  *
26  */
27 public class ControllerVariables {
28     private static Logger LOGGER = LoggerFactory.getLogger(ControllerVariables.class);
29
30     public int dist;
31     public int door;
32     public int vehicle;
33     public int rcnt;
34     public int fwv;
35     public String name;
36     public String mac;
37     public String cid;
38     public int rssi;
39
40     private ControllerVariables() {
41     }
42
43     public static ControllerVariables parse(String response) {
44         LOGGER.debug("Parsing string: \"{}\"", response);
45         /* parse json string */
46         JsonObject jsonObject = JsonParser.parseString(response).getAsJsonObject();
47         ControllerVariables info = new ControllerVariables();
48         info.dist = jsonObject.get("dist").getAsInt();
49         info.door = jsonObject.get("door").getAsInt();
50         info.vehicle = jsonObject.get("vehicle").getAsInt();
51         info.rcnt = jsonObject.get("rcnt").getAsInt();
52         info.fwv = jsonObject.get("fwv").getAsInt();
53         info.name = jsonObject.get("name").getAsString();
54         info.mac = jsonObject.get("mac").getAsString();
55         info.cid = jsonObject.get("cid").getAsString();
56         info.rssi = jsonObject.get("rssi").getAsInt();
57         return info;
58     }
59 }