]> git.basschouten.com Git - openhab-addons.git/blob
0ea086b392d9c0f3da55e28f10631d149870f35b
[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.velux.internal.things;
14
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;
19
20 /**
21  * <B>Velux</B> scene representation.
22  * <P>
23  * Combined set of information with references towards multiple Velux product states.
24  * <P>
25  * Methods in handle this type of information:
26  * <UL>
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>
32  * </UL>
33  *
34  * @see VeluxProductState
35  *
36  * @author Guenther Schreiner - initial contribution.
37  */
38 @NonNullByDefault
39 public class VeluxScene {
40     private final Logger logger = LoggerFactory.getLogger(VeluxScene.class);
41
42     // Public definition
43
44     public static final VeluxScene UNKNOWN = new VeluxScene();
45
46     // Type definitions
47
48     public static class SceneName {
49
50         private static final SceneName UNKNOWN = new SceneName(VeluxBindingConstants.UNKNOWN);
51
52         private String name;
53
54         @Override
55         public String toString() {
56             return name;
57         }
58
59         public SceneName(String name) {
60             this.name = name;
61         }
62
63         public boolean equals(SceneName anotherName) {
64             return this.name.equals(anotherName.toString());
65         }
66     }
67
68     public static class SceneBridgeIndex {
69
70         private static final SceneBridgeIndex UNKNOWN = new SceneBridgeIndex(0);
71
72         private int id;
73
74         @Override
75         public String toString() {
76             return String.valueOf(id);
77         }
78
79         public int toInt() {
80             return id;
81         }
82
83         private SceneBridgeIndex(int id) {
84             this.id = id;
85         }
86     }
87
88     // Class internal
89
90     private SceneName name;
91     private SceneBridgeIndex bridgeSceneIndex;
92     private boolean silent;
93     private VeluxProductState[] productStates;
94
95     // Constructor
96
97     /**
98      * Constructor
99      *
100      * just for the dummy VeluxProduct.
101      */
102     private VeluxScene() {
103         logger.trace("VeluxScene() created.");
104         this.name = SceneName.UNKNOWN;
105         this.bridgeSceneIndex = SceneBridgeIndex.UNKNOWN;
106         this.silent = false;
107         this.productStates = new VeluxProductState[0];
108     }
109
110     public VeluxScene(String name, int sceneBridgeIndex, boolean silentOperation, VeluxProductState[] actions) {
111         this.name = new SceneName(name);
112         this.bridgeSceneIndex = new SceneBridgeIndex(sceneBridgeIndex);
113         this.silent = silentOperation;
114         this.productStates = actions;
115     }
116
117     public VeluxScene(VeluxScene scene) {
118         this.name = new SceneName(scene.name.toString());
119         this.bridgeSceneIndex = new SceneBridgeIndex(scene.bridgeSceneIndex.toInt());
120         this.silent = scene.silent;
121         this.productStates = scene.productStates;
122     }
123     // Class access methods
124
125     public SceneName getName() {
126         return this.name;
127     }
128
129     public SceneBridgeIndex getBridgeSceneIndex() {
130         return this.bridgeSceneIndex;
131     }
132
133     @Override
134     public String toString() {
135         return String.format("Scene \"%s\" (index %d) with %ssilent mode and %d actions", this.name,
136                 this.bridgeSceneIndex.toInt(), this.silent ? "" : "non-", this.productStates.length);
137     }
138 }