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;
16 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.DeviceSceneSpec;
17 import org.openhab.binding.digitalstrom.internal.lib.structure.scene.constants.Scene;
18 import org.openhab.binding.digitalstrom.internal.lib.structure.scene.constants.SceneEnum;
20 import com.google.gson.JsonObject;
23 * The {@link JSONDeviceSceneSpecImpl} is the implementation of the {@link DeviceSceneSpec}.
25 * @author Alexander Betker - Initial contribution
26 * @author Michael Ochel - change from SimpleJSON to GSON, add constructor JSONDeviceSceneSpecImpl(Short sceneID) and
27 * JSONDeviceSceneSpecImpl(String sceneName)
28 * @author Matthias Siegele - change from SimpleJSON to GSON, add constructor JSONDeviceSceneSpecImpl(Short sceneID) and
29 * JSONDeviceSceneSpecImpl(String sceneName)
31 public class JSONDeviceSceneSpecImpl implements DeviceSceneSpec {
34 private boolean dontcare = false;
35 private boolean localPrio = false;
36 private boolean specialMode = false;
37 private boolean flashMode = false;
40 * Creates a new {@link JSONDeviceSceneSpecImpl} through the digitalSTROM json response as {@link JsonObject}.
42 * @param jObject must not be null
44 public JSONDeviceSceneSpecImpl(JsonObject jObject) {
45 if (jObject.get(JSONApiResponseKeysEnum.SCENE_ID.getKey()) != null) {
47 val = jObject.get(JSONApiResponseKeysEnum.SCENE_ID.getKey()).getAsShort();
50 this.scene = SceneEnum.getScene(val);
53 if (jObject.get(JSONApiResponseKeysEnum.DONT_CARE.getKey()) != null) {
54 this.dontcare = jObject.get(JSONApiResponseKeysEnum.DONT_CARE.getKey()).getAsBoolean();
56 if (jObject.get(JSONApiResponseKeysEnum.LOCAL_PRIO.getKey()) != null) {
57 this.localPrio = jObject.get(JSONApiResponseKeysEnum.LOCAL_PRIO.getKey()).getAsBoolean();
59 if (jObject.get(JSONApiResponseKeysEnum.SPECIAL_MODE.getKey()) != null) {
60 this.specialMode = jObject.get(JSONApiResponseKeysEnum.SPECIAL_MODE.getKey()).getAsBoolean();
62 if (jObject.get(JSONApiResponseKeysEnum.FLASH_MODE.getKey()) != null) {
63 this.flashMode = jObject.get(JSONApiResponseKeysEnum.FLASH_MODE.getKey()).getAsBoolean();
68 * Creates a new {@link JSONDeviceSceneSpecImpl} through the given sceneID.
70 * @param sceneID must not be null
72 public JSONDeviceSceneSpecImpl(Short sceneID) {
73 this.scene = SceneEnum.getScene(sceneID);
77 * Creates a new {@link JSONDeviceSceneSpecImpl} through the given sceneName.
79 * @param sceneName must not be null
81 public JSONDeviceSceneSpecImpl(String sceneName) {
83 this.scene = SceneEnum.valueOf(sceneName);
84 } catch (IllegalArgumentException e) {
90 public Scene getScene() {
95 public boolean isDontCare() {
100 public synchronized void setDontcare(boolean dontcare) {
101 this.dontcare = dontcare;
105 public boolean isLocalPrio() {
110 public synchronized void setLocalPrio(boolean localPrio) {
111 this.localPrio = localPrio;
115 public boolean isSpecialMode() {
120 public synchronized void setSpecialMode(boolean specialMode) {
121 this.specialMode = specialMode;
125 public boolean isFlashMode() {
130 public synchronized void setFlashMode(boolean flashMode) {
131 this.flashMode = flashMode;
135 public String toString() {
136 return "Scene: " + this.getScene() + ", dontcare: " + this.isDontCare() + ", localPrio: " + this.isLocalPrio()
137 + ", specialMode: " + this.isSpecialMode() + ", flashMode: " + this.isFlashMode();