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 org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum},
24 * @author Michael Ochel - Initial contribution
25 * @author Matthias Siegele - Initial contribution
28 public class DeviceBinaryInput {
30 private final Short targetGroupType;
31 private final Short targetGroup;
32 private final Short inputType;
33 private final Short inputId;
34 private Short stateValue;
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
44 * @param jsonObject must not be null
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();
50 targetGroupType = null;
52 if (jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP.getKey()) != null) {
53 targetGroup = jsonObject.get(JSONApiResponseKeysEnum.TARGET_GROUP.getKey()).getAsShort();
57 if (jsonObject.get(JSONApiResponseKeysEnum.INPUT_TYPE.getKey()) != null) {
58 inputType = jsonObject.get(JSONApiResponseKeysEnum.INPUT_TYPE.getKey()).getAsShort();
62 if (jsonObject.get(JSONApiResponseKeysEnum.INPUT_ID.getKey()) != null) {
63 inputId = jsonObject.get(JSONApiResponseKeysEnum.INPUT_ID.getKey()).getAsShort();
67 if (jsonObject.get(JSONApiResponseKeysEnum.STATE_VALUE.getKey()) != null) {
68 stateValue = jsonObject.get(JSONApiResponseKeysEnum.STATE_VALUE.getKey()).getAsShort();
70 if (stateValue == null && jsonObject.get(JSONApiResponseKeysEnum.STATE.getKey()) != null) {
71 stateValue = jsonObject.get(JSONApiResponseKeysEnum.STATE.getKey()).getAsShort();
78 * Returns the current state of this {@link DeviceBinaryInput}.
82 public Short getState() {
87 * Sets the state of this {@link DeviceBinaryInput}.
89 * @param state the state to set
91 public void setState(Short state) {
92 this.stateValue = state;
96 * Returns the target group type id of this {@link DeviceBinaryInput}.
98 * @return the targetGroupType
100 public Short getTargetGroupType() {
101 return targetGroupType;
105 * Returns the target group id of this {@link DeviceBinaryInput}.
107 * @return the targetGroup
109 public Short getTargetGroup() {
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}.
117 * @return the inputType
119 public Short getInputType() {
124 * Returns the input id of this {@link DeviceBinaryInput}.
126 * @return the inputId
128 public Short getInputId() {
135 * @see java.lang.Object#hashCode()
138 public int hashCode() {
139 final int prime = 31;
141 result = prime * result + ((inputType == null) ? 0 : inputType.hashCode());
148 * @see java.lang.Object#equals(java.lang.Object)
151 public boolean equals(Object obj) {
158 if (!(obj instanceof DeviceBinaryInput)) {
161 DeviceBinaryInput other = (DeviceBinaryInput) obj;
162 if (inputType == null) {
163 if (other.inputType != null) {
166 } else if (!inputType.equals(other.inputType)) {
175 * @see java.lang.Object#toString()
178 public String toString() {
179 return "DeviceBinaryInput [targetGroupType=" + targetGroupType + ", targetGroup=" + targetGroup + ", inputType="
180 + inputType + ", inputId=" + inputId + ", state=" + stateValue + "]";