]> git.basschouten.com Git - openhab-addons.git/blob
59006725127dcd1207be66f5aaff66dbb283ca1e
[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.impl;
14
15 import java.util.HashMap;
16 import java.util.Map;
17 import java.util.Set;
18
19 import org.openhab.binding.digitalstrom.internal.lib.climate.constants.OperationModes;
20 import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.BaseZoneIdentifier;
21 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
22
23 import com.google.gson.JsonObject;
24
25 /**
26  * The {@link TemperatureControlValues} acts as container for the digitalSTROM json-method
27  * <i>getTemperatureControlValues</i>. So the {@link TemperatureControlValues} contains all temperature
28  * control values information of a zone.
29  *
30  * @author Michael Ochel - Initial contribution
31  * @author Matthias Siegele - Initial contribution
32  */
33 public class TemperatureControlValues extends BaseZoneIdentifier {
34
35     private Map<OperationModes, Float> temperatureControlValues;
36     private String controlDSUID;
37     private Boolean isConfigured;
38
39     /**
40      * Creates a new {@link TemperatureControlValues} through the {@link JsonObject} which will be returned by an
41      * apartment call.
42      *
43      * @param jObject must not be null
44      */
45     public TemperatureControlValues(JsonObject jObject) {
46         super(jObject);
47         init(jObject);
48     }
49
50     /**
51      * Creates a new {@link TemperatureControlValues} through the {@link JsonObject} which will be returned by a zone
52      * call.<br>
53      * Because of zone calls does not include a zoneID or zoneName in the json response, the zoneID and zoneName have to
54      * be handed over the constructor.
55      *
56      * @param jObject must not be null
57      * @param zoneID must not be null
58      * @param zoneName can be null
59      */
60     public TemperatureControlValues(JsonObject jObject, Integer zoneID, String zoneName) {
61         super(zoneID, zoneName);
62         init(jObject);
63     }
64
65     private void init(JsonObject jObject) {
66         if (jObject.get(JSONApiResponseKeysEnum.IS_CONFIGURED.getKey()) != null) {
67             this.isConfigured = jObject.get(JSONApiResponseKeysEnum.IS_CONFIGURED.getKey()).getAsBoolean();
68         }
69         if (isConfigured) {
70             if (jObject.get(JSONApiResponseKeysEnum.CONTROL_DSUID.getKey()) != null) {
71                 this.controlDSUID = jObject.get(JSONApiResponseKeysEnum.CONTROL_DSUID.getKey()).getAsString();
72             }
73             temperatureControlValues = new HashMap<>(OperationModes.values().length);
74             for (OperationModes opMode : OperationModes.values()) {
75                 if (jObject.get(opMode.getKey()) != null) {
76                     temperatureControlValues.put(opMode, jObject.get(opMode.getKey()).getAsFloat());
77                 }
78             }
79         }
80     }
81
82     /**
83      * @see org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl.TemperatureControlStatus#getControlDSUID()
84      * @return the controlDSUID
85      */
86     public String getControlDSUID() {
87         return controlDSUID;
88     }
89
90     /**
91      * @see org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum#IS_CONFIGURED
92      * @return the isConfigured
93      */
94     public Boolean getIsConfigured() {
95         return isConfigured;
96     }
97
98     /**
99      * Returns the set temperature of the given operation mode.
100      *
101      * @param operationMode must not be null
102      * @return temperature of the operation mode
103      */
104     public Float getTemperation(OperationModes operationMode) {
105         return temperatureControlValues.get(operationMode);
106     }
107
108     /**
109      * Returns the available operation modes as {@link Set}.
110      *
111      * @return available operation modes
112      */
113     public Set<OperationModes> getOperationModes() {
114         return temperatureControlValues.keySet();
115     }
116
117     /**
118      * Returns a {@link Map} that maps the available operation modes to the set values.
119      *
120      * @return Map with operation modes and their values
121      */
122     public Map<OperationModes, Float> getTemperatureControlValues() {
123         return temperatureControlValues;
124     }
125
126     /*
127      * (non-Javadoc)
128      *
129      * @see java.lang.Object#toString()
130      */
131     @Override
132     public String toString() {
133         return "TemperatureControlValues [temperatureControlValues=" + temperatureControlValues + ", controlDSUID="
134                 + controlDSUID + ", isConfigured=" + isConfigured + "]";
135     }
136 }