]> git.basschouten.com Git - openhab-addons.git/blob
96aa559bcea3b6a69886316eb3f105f4916c3cb8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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     @NonNullByDefault
49     public static class SceneName {
50
51         private static final SceneName UNKNOWN = new SceneName(VeluxBindingConstants.UNKNOWN);
52
53         private String name;
54
55         @Override
56         public String toString() {
57             return name;
58         }
59
60         public SceneName(String name) {
61             this.name = name;
62         }
63
64         public boolean equals(SceneName anotherName) {
65             return this.name.equals(anotherName.toString());
66         }
67     }
68
69     @NonNullByDefault
70     public static class SceneBridgeIndex {
71
72         private static final SceneBridgeIndex UNKNOWN = new SceneBridgeIndex(0);
73
74         private int id;
75
76         @Override
77         public String toString() {
78             return String.valueOf(id);
79         }
80
81         public int toInt() {
82             return id;
83         }
84
85         private SceneBridgeIndex(int id) {
86             this.id = id;
87         }
88     }
89
90     // Class internal
91
92     private SceneName name;
93     private SceneBridgeIndex bridgeSceneIndex;
94     private boolean silent;
95     private VeluxProductState[] productStates;
96
97     // Constructor
98
99     /**
100      * Constructor
101      *
102      * just for the dummy VeluxProduct.
103      */
104     private VeluxScene() {
105         logger.trace("VeluxScene() created.");
106         this.name = SceneName.UNKNOWN;
107         this.bridgeSceneIndex = SceneBridgeIndex.UNKNOWN;
108         this.silent = false;
109         this.productStates = new VeluxProductState[0];
110     }
111
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;
117     }
118
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;
124     }
125     // Class access methods
126
127     public SceneName getName() {
128         return this.name;
129     }
130
131     public SceneBridgeIndex getBridgeSceneIndex() {
132         return this.bridgeSceneIndex;
133     }
134
135     @Override
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);
139     }
140 }