2 * Copyright (c) 2010-2020 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.velux.internal.things;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.VeluxBindingConstants;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * <B>Velux</B> scene representation.
23 * Combined set of information with references towards multiple Velux product states.
25 * Methods in handle this type of information:
27 * <LI>{@link #VeluxScene(String, int, boolean, VeluxProductState[])} to create a new scene.</LI>
28 * <LI>{@link #VeluxScene(VeluxScene)} to duplicate a scene.</LI>
29 * <LI>{@link #getName} to retrieve the name of this scene.</LI>
30 * <LI>{@link #getBridgeSceneIndex()} to retrieve the index of this scene.</LI>
31 * <LI>{@link #toString()} to retrieve a human-readable description of this scene.</LI>
34 * @see VeluxProductState
36 * @author Guenther Schreiner - initial contribution.
39 public class VeluxScene {
40 private final Logger logger = LoggerFactory.getLogger(VeluxScene.class);
44 public static final VeluxScene UNKNOWN = new VeluxScene();
49 public static class SceneName {
51 private static final SceneName UNKNOWN = new SceneName(VeluxBindingConstants.UNKNOWN);
56 public String toString() {
60 public SceneName(String name) {
64 public boolean equals(SceneName anotherName) {
65 return this.name.equals(anotherName.toString());
70 public static class SceneBridgeIndex {
72 private static final SceneBridgeIndex UNKNOWN = new SceneBridgeIndex(0);
77 public String toString() {
78 return String.valueOf(id);
85 private SceneBridgeIndex(int id) {
92 private SceneName name;
93 private SceneBridgeIndex bridgeSceneIndex;
94 private boolean silent;
95 private VeluxProductState[] productStates;
102 * just for the dummy VeluxProduct.
104 private VeluxScene() {
105 logger.trace("VeluxScene() created.");
106 this.name = SceneName.UNKNOWN;
107 this.bridgeSceneIndex = SceneBridgeIndex.UNKNOWN;
109 this.productStates = new VeluxProductState[0];
112 public VeluxScene(String name, int sceneBridgeIndex, boolean silentOperation, VeluxProductState[] actions) {
113 this.name = new SceneName(name);
114 this.bridgeSceneIndex = new SceneBridgeIndex(sceneBridgeIndex);
115 this.silent = silentOperation;
116 this.productStates = actions;
119 public VeluxScene(VeluxScene scene) {
120 this.name = new SceneName(scene.name.toString());
121 this.bridgeSceneIndex = new SceneBridgeIndex(scene.bridgeSceneIndex.toInt());
122 this.silent = scene.silent;
123 this.productStates = scene.productStates;
125 // Class access methods
127 public SceneName getName() {
131 public SceneBridgeIndex getBridgeSceneIndex() {
132 return this.bridgeSceneIndex;
136 public String toString() {
137 return String.format("Scene \"%s\" (index %d) with %ssilent mode and %d actions", this.name,
138 this.bridgeSceneIndex.toInt(), this.silent ? "" : "non-", this.productStates.length);