]> git.basschouten.com Git - openhab-addons.git/blob
da0e1a20b5b34eccecc95fead1cd5f78519b272f
[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.devices.deviceparameters.impl;
14
15 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
16 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.DeviceConfig;
17
18 import com.google.gson.JsonObject;
19
20 /**
21  * The {@link JSONDeviceConfigImpl} is the implementation of the {@link DeviceConfig}.
22  *
23  * @author Alexander Betker - Initial contribution
24  * @author Michael Ochel - change from SimpleJSON to GSON
25  * @author Matthias Siegele - change from SimpleJSON to GSON
26  */
27 public class JSONDeviceConfigImpl implements DeviceConfig {
28
29     private int clazz = -1;
30     private int index = -1;
31     private int value = -1;
32
33     /**
34      * Creates a new {@link JSONDeviceConfigImpl}.
35      *
36      * @param object must not be null
37      */
38     public JSONDeviceConfigImpl(JsonObject object) {
39         if (object.get(JSONApiResponseKeysEnum.CLASS.getKey()) != null) {
40             clazz = object.get(JSONApiResponseKeysEnum.CLASS.getKey()).getAsInt();
41         }
42         if (object.get(JSONApiResponseKeysEnum.INDEX.getKey()) != null) {
43             index = object.get(JSONApiResponseKeysEnum.INDEX.getKey()).getAsInt();
44         }
45         if (object.get(JSONApiResponseKeysEnum.VALUE.getKey()) != null) {
46             value = object.get(JSONApiResponseKeysEnum.VALUE.getKey()).getAsInt();
47         }
48     }
49
50     @Override
51     public int getConfigurationClass() {
52         return clazz;
53     }
54
55     @Override
56     public int getIndex() {
57         return index;
58     }
59
60     @Override
61     public int getValue() {
62         return value;
63     }
64
65     @Override
66     public String toString() {
67         return "class: " + this.clazz + ", " + "index: " + this.index + ", " + "value: " + this.value;
68     }
69 }