]> git.basschouten.com Git - openhab-addons.git/blob
c19f45e9262a49ac64a6cc466579500f310f3d94
[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.unifi.internal.api.dto;
14
15 import com.google.gson.JsonObject;
16
17 /**
18  * The {@link UnfiPortOverride} represents the data model of UniFi port override.
19  * Using plain JsonObject to make sure any data in the object is not lost when writing the data back to the UniFi
20  * device.
21  *
22  * @author Hilbrand Bouwkamp - Initial contribution
23  */
24 public class UnfiPortOverrideJsonObject {
25
26     private static final String PORT_IDX = "port_idx";
27     private static final String PORT_CONF_ID = "port_conf_id";
28     private static final String POE_MODE = "poe_mode";
29
30     private final JsonObject jsonObject;
31
32     public UnfiPortOverrideJsonObject(final JsonObject Object) {
33         this.jsonObject = Object.getAsJsonObject();
34     }
35
36     public JsonObject getJsonObject() {
37         return jsonObject;
38     }
39
40     public static boolean hasPortIdx(final JsonObject jsonObject) {
41         return jsonObject.has(PORT_IDX);
42     }
43
44     public int getPortIdx() {
45         return jsonObject.get(PORT_IDX).getAsInt();
46     }
47
48     public String getPortConfId() {
49         return jsonObject.get(PORT_CONF_ID).getAsString();
50     }
51
52     public String getPoeMode() {
53         return jsonObject.get(POE_MODE).getAsString();
54     }
55
56     public void setPoeMode(final String poeMode) {
57         jsonObject.addProperty(POE_MODE, poeMode);
58     }
59
60     @Override
61     public String toString() {
62         return jsonObject.toString();
63     }
64 }