2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl;
15 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
17 import com.google.gson.JsonObject;
20 * The {@link DeviceBinaryInput} contains all information of a device binary input, e.g. binary input type id (see
21 * {@link DeviceBinarayInputEnum}, state and so on.
23 * @author Michael Ochel - Initial contribution
24 * @author Matthias Siegele - Initial contribution
27 public class DeviceBinaryInput {
29 private final Short targetGroupType;
30 private final Short targetGroup;
31 private final Short inputType;
32 private final Short inputId;
33 private Short stateValue;
36 * Creates a new {@link DeviceBinarayInputEnum} through the {@link JsonObject} of the binary inputs at json response
37 * from digitalSTROM JSON-API or property-tree. Will be automatically added to a {@link DeviceImpl}, if binary
40 * @param jsonObject must not be null
42 public DeviceBinaryInput(JsonObject jsonObject) {
43 if (jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP_TYPE.getKey()) != null) {
44 targetGroupType = jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP_TYPE.getKey()).getAsShort();
46 targetGroupType = null;
48 if (jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP.getKey()) != null) {
49 targetGroup = jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP.getKey()).getAsShort();
53 if (jsonObject.get(JSONApiResponseKeysEnum.INPUT_TYPE.getKey()) != null) {
54 inputType = jsonObject.get(JSONApiResponseKeysEnum.INPUT_TYPE.getKey()).getAsShort();
58 if (jsonObject.get(JSONApiResponseKeysEnum.INPUT_ID.getKey()) != null) {
59 inputId = jsonObject.get(JSONApiResponseKeysEnum.INPUT_ID.getKey()).getAsShort();
63 if (jsonObject.get(JSONApiResponseKeysEnum.STATE_VALUE.getKey()) != null) {
64 stateValue = jsonObject.get(JSONApiResponseKeysEnum.STATE_VALUE.getKey()).getAsShort();
66 if (stateValue == null && jsonObject.get(JSONApiResponseKeysEnum.STATE.getKey()) != null) {
67 stateValue = jsonObject.get(JSONApiResponseKeysEnum.STATE.getKey()).getAsShort();
74 * Returns the current state of this {@link DeviceBinaryInput}.
78 public Short getState() {
83 * Sets the state of this {@link DeviceBinaryInput}.
85 * @param state the state to set
87 public void setState(Short state) {
88 this.stateValue = state;
92 * Returns the target group type id of this {@link DeviceBinaryInput}.
94 * @return the targetGroupType
96 public Short getTargetGroupType() {
97 return targetGroupType;
101 * Returns the target group id of this {@link DeviceBinaryInput}.
103 * @return the targetGroup
105 public Short getTargetGroup() {
110 * Returns the input type id of this {@link DeviceBinaryInput}. Available input types see
111 * {@link DeviceBinarayInputEnum}.
113 * @return the inputType
115 public Short getInputType() {
120 * Returns the input id of this {@link DeviceBinaryInput}.
122 * @return the inputId
124 public Short getInputId() {
131 * @see java.lang.Object#hashCode()
134 public int hashCode() {
135 final int prime = 31;
137 result = prime * result + ((inputType == null) ? 0 : inputType.hashCode());
144 * @see java.lang.Object#equals(java.lang.Object)
147 public boolean equals(Object obj) {
154 if (!(obj instanceof DeviceBinaryInput)) {
157 DeviceBinaryInput other = (DeviceBinaryInput) obj;
158 if (inputType == null) {
159 if (other.inputType != null) {
162 } else if (!inputType.equals(other.inputType)) {
171 * @see java.lang.Object#toString()
174 public String toString() {
175 return "DeviceBinaryInput [targetGroupType=" + targetGroupType + ", targetGroup=" + targetGroup + ", inputType="
176 + inputType + ", inputId=" + inputId + ", state=" + stateValue + "]";