]> git.basschouten.com Git - openhab-addons.git/blob
84351934ec70f7fb0fff94de24773c4a5edc5b8d
[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.climate.jsonresponsecontainer;
14
15 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
16
17 import com.google.gson.JsonObject;
18
19 /**
20  * The {@link BaseZoneIdentifier} is a base implementation of the {@link ZoneIdentifier}.
21  *
22  * @author Michael Ochel - Initial contribution
23  * @author Matthias Siegele - Initial contribution
24  */
25 public abstract class BaseZoneIdentifier implements ZoneIdentifier {
26
27     protected Integer zoneID;
28     protected String zoneName;
29
30     /**
31      * Creates a new {@link BaseZoneIdentifier} with a zone id and zone name.
32      *
33      * @param zoneID must not be null
34      * @param zoneName can be null
35      */
36     public BaseZoneIdentifier(Integer zoneID, String zoneName) {
37         this.zoneID = zoneID;
38         this.zoneName = zoneName;
39     }
40
41     /**
42      * Creates a new {@link BaseZoneIdentifier} through the {@link JsonObject} of the response of a digitalSTROM-API
43      * apartment call.
44      *
45      * @param jObject must not be null
46      */
47     public BaseZoneIdentifier(JsonObject jObject) {
48         if (jObject.get(JSONApiResponseKeysEnum.ID.getKey()) != null) {
49             this.zoneID = jObject.get(JSONApiResponseKeysEnum.ID.getKey()).getAsInt();
50         }
51         if (jObject.get(JSONApiResponseKeysEnum.NAME.getKey()) != null) {
52             this.zoneName = jObject.get(JSONApiResponseKeysEnum.NAME.getKey()).getAsString();
53         }
54     }
55
56     @Override
57     public Integer getZoneID() {
58         return zoneID;
59     }
60
61     @Override
62     public String getZoneName() {
63         return zoneName;
64     }
65 }