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