]> git.basschouten.com Git - openhab-addons.git/blob
3f084f5eaca5454624af10a2b1c386be79f13468
[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.structure.devices.deviceparameters.impl;
14
15 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
16
17 import com.google.gson.JsonObject;
18
19 /**
20  * The {@link DeviceBinaryInput} contains all information of a device binary input, e.g. binary input type id (see
21  * {@link org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum},
22  * state and so on.
23  *
24  * @author Michael Ochel - Initial contribution
25  * @author Matthias Siegele - Initial contribution
26  *
27  */
28 public class DeviceBinaryInput {
29
30     private final Short targetGroupType;
31     private final Short targetGroup;
32     private final Short inputType;
33     private final Short inputId;
34     private Short stateValue;
35
36     /**
37      * Creates a new
38      * {@link org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum}
39      * through the {@link JsonObject} of the binary inputs at json response
40      * from digitalSTROM JSON-API or property-tree. Will be automatically added to a
41      * {@link org.openhab.binding.digitalstrom.internal.lib.structure.devices.impl.DeviceImpl}, if binary
42      * inputs exists.
43      *
44      * @param jsonObject must not be null
45      */
46     public DeviceBinaryInput(JsonObject jsonObject) {
47         if (jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP_TYPE.getKey()) != null) {
48             targetGroupType = jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP_TYPE.getKey()).getAsShort();
49         } else {
50             targetGroupType = null;
51         }
52         if (jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP.getKey()) != null) {
53             targetGroup = jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP.getKey()).getAsShort();
54         } else {
55             targetGroup = null;
56         }
57         if (jsonObject.get(JSONApiResponseKeysEnum.INPUT_TYPE.getKey()) != null) {
58             inputType = jsonObject.get(JSONApiResponseKeysEnum.INPUT_TYPE.getKey()).getAsShort();
59         } else {
60             inputType = null;
61         }
62         if (jsonObject.get(JSONApiResponseKeysEnum.INPUT_ID.getKey()) != null) {
63             inputId = jsonObject.get(JSONApiResponseKeysEnum.INPUT_ID.getKey()).getAsShort();
64         } else {
65             inputId = null;
66         }
67         if (jsonObject.get(JSONApiResponseKeysEnum.STATE_VALUE.getKey()) != null) {
68             stateValue = jsonObject.get(JSONApiResponseKeysEnum.STATE_VALUE.getKey()).getAsShort();
69         }
70         if (stateValue == null && jsonObject.get(JSONApiResponseKeysEnum.STATE.getKey()) != null) {
71             stateValue = jsonObject.get(JSONApiResponseKeysEnum.STATE.getKey()).getAsShort();
72         } else {
73             stateValue = null;
74         }
75     }
76
77     /**
78      * Returns the current state of this {@link DeviceBinaryInput}.
79      *
80      * @return the state
81      */
82     public Short getState() {
83         return stateValue;
84     }
85
86     /**
87      * Sets the state of this {@link DeviceBinaryInput}.
88      *
89      * @param state the state to set
90      */
91     public void setState(Short state) {
92         this.stateValue = state;
93     }
94
95     /**
96      * Returns the target group type id of this {@link DeviceBinaryInput}.
97      *
98      * @return the targetGroupType
99      */
100     public Short getTargetGroupType() {
101         return targetGroupType;
102     }
103
104     /**
105      * Returns the target group id of this {@link DeviceBinaryInput}.
106      *
107      * @return the targetGroup
108      */
109     public Short getTargetGroup() {
110         return targetGroup;
111     }
112
113     /**
114      * Returns the input type id of this {@link DeviceBinaryInput}. Available input types see
115      * {@link org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum}.
116      *
117      * @return the inputType
118      */
119     public Short getInputType() {
120         return inputType;
121     }
122
123     /**
124      * Returns the input id of this {@link DeviceBinaryInput}.
125      *
126      * @return the inputId
127      */
128     public Short getInputId() {
129         return inputId;
130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see java.lang.Object#hashCode()
136      */
137     @Override
138     public int hashCode() {
139         final int prime = 31;
140         int result = 1;
141         result = prime * result + ((inputType == null) ? 0 : inputType.hashCode());
142         return result;
143     }
144
145     /*
146      * (non-Javadoc)
147      *
148      * @see java.lang.Object#equals(java.lang.Object)
149      */
150     @Override
151     public boolean equals(Object obj) {
152         if (this == obj) {
153             return true;
154         }
155         if (obj == null) {
156             return false;
157         }
158         if (!(obj instanceof DeviceBinaryInput)) {
159             return false;
160         }
161         DeviceBinaryInput other = (DeviceBinaryInput) obj;
162         if (inputType == null) {
163             if (other.inputType != null) {
164                 return false;
165             }
166         } else if (!inputType.equals(other.inputType)) {
167             return false;
168         }
169         return true;
170     }
171
172     /*
173      * (non-Javadoc)
174      *
175      * @see java.lang.Object#toString()
176      */
177     @Override
178     public String toString() {
179         return "DeviceBinaryInput [targetGroupType=" + targetGroupType + ", targetGroup=" + targetGroup + ", inputType="
180                 + inputType + ", inputId=" + inputId + ", state=" + stateValue + "]";
181     }
182 }