]> git.basschouten.com Git - openhab-addons.git/blob
2a8d526165c5c3766d8de7e44af0bd857d874079
[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.climate.constants.ControlModes;
16 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
17
18 import com.google.gson.JsonObject;
19
20 /**
21  * The {@link BaseTemperatureControl} is a base implementation for temperature controls status and configurations. For
22  * that it extends the {@link BaseZoneIdentifier}.
23  *
24  * @author Michael Ochel - Initial contribution
25  * @author Matthias Siegele - Initial contribution
26  */
27 public abstract class BaseTemperatureControl extends BaseZoneIdentifier {
28
29     protected String controlDSUID;
30     protected Short controlMode;
31
32     /**
33      * Creates a new {@link BaseTemperatureControl} through the {@link JsonObject} which will be returned by a zone
34      * call.<br>
35      * Because zone calls do not include a zoneID or zoneName in the json response, the zoneID and zoneName have to
36      * be handed over the constructor.
37      *
38      * @param jObject must not be null
39      * @param zoneID must not be null
40      * @param zoneName can be null
41      */
42     public BaseTemperatureControl(JsonObject jObject, Integer zoneID, String zoneName) {
43         super(zoneID, zoneName);
44         init(jObject);
45     }
46
47     /**
48      * Creates a new {@link BaseTemperatureControl} through the {@link JsonObject} which will be returned by an
49      * apartment call.
50      *
51      * @param jObject must not be null
52      */
53     public BaseTemperatureControl(JsonObject jObject) {
54         super(jObject);
55         init(jObject);
56     }
57
58     private void init(JsonObject jObject) {
59         if (jObject.get(JSONApiResponseKeysEnum.CONTROL_MODE.getKey()) != null) {
60             this.controlMode = jObject.get(JSONApiResponseKeysEnum.CONTROL_MODE.getKey()).getAsShort();
61         }
62         if (jObject.get(JSONApiResponseKeysEnum.CONTROL_DSUID.getKey()) != null) {
63             this.controlDSUID = jObject.get(JSONApiResponseKeysEnum.CONTROL_DSUID.getKey()).getAsString();
64         }
65     }
66
67     /**
68      * Returns the dSUID of the control sensor for heating of the zone.
69      *
70      * @return the controlDSUID
71      */
72     public String getControlDSUID() {
73         return controlDSUID;
74     }
75
76     /**
77      * Returns controlMode for heating of the zone.
78      *
79      * @return the controlMode
80      */
81     public Short getControlMode() {
82         return controlMode;
83     }
84
85     /**
86      * Returns true, if heating for this zone is not set off (set {@link ControlModes} = {@link ControlModes#OFF}),
87      * otherwise false.
88      *
89      * @return true, if the set {@link ControlModes} is not {@link ControlModes#OFF}
90      */
91     public Boolean isNotSetOff() {
92         return !ControlModes.OFF.getID().equals(controlMode);
93     }
94 }