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.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * <B>Velux</B> product representation.
22 * Combined set of information describing a single Velux product.
24 * @author Guenther Schreiner - initial contribution.
27 public class VeluxProduct {
28 private final Logger logger = LoggerFactory.getLogger(VeluxProduct.class);
32 public static final VeluxProduct UNKNOWN = new VeluxProduct();
37 public static class ProductBridgeIndex {
40 public static final ProductBridgeIndex UNKNOWN = new ProductBridgeIndex(0);
46 public ProductBridgeIndex(int id) {
50 // Class access methods
56 public String toString() {
57 return Integer.toString(id);
63 private VeluxProductName name;
64 private VeluxProductType typeId;
65 private ProductBridgeIndex bridgeProductIndex;
67 private boolean v2 = false;
68 private int order = 0;
69 private int placement = 0;
70 private int velocity = 0;
71 private int variation = 0;
72 private int powerMode = 0;
73 private String serialNumber = VeluxProductSerialNo.UNKNOWN;
74 private int state = 0;
75 private int currentPosition = 0;
76 private int target = 0;
77 private int remainingTime = 0;
78 private int timeStamp = 0;
85 * just for the dummy VeluxProduct.
87 public VeluxProduct() {
88 logger.trace("VeluxProduct() created.");
89 this.name = VeluxProductName.UNKNOWN;
90 this.typeId = VeluxProductType.UNDEFTYPE;
91 this.bridgeProductIndex = ProductBridgeIndex.UNKNOWN;
97 * @param name This field Name holds the name of the actuator, ex. “Window 1”. This field is 64 bytes
98 * long, formatted as UTF-8 characters.
99 * @param typeId This field indicates the node type, ex. Window, Roller shutter, Light etc.
100 * @param bridgeProductIndex NodeID is an Actuator index in the system table, to get information from. It must be a
101 * value from 0 to 199.
103 public VeluxProduct(VeluxProductName name, VeluxProductType typeId, ProductBridgeIndex bridgeProductIndex) {
104 logger.trace("VeluxProduct(v1,name={}) created.", name.toString());
106 this.typeId = typeId;
107 this.bridgeProductIndex = bridgeProductIndex;
113 * @param name This field Name holds the name of the actuator, ex. “Window 1”. This field is 64 bytes
114 * long, formatted as UTF-8 characters.
115 * @param typeId This field indicates the node type, ex. Window, Roller shutter, Light etc.
116 * @param bridgeProductIndex NodeID is an Actuator index in the system table, to get information from. It must be a
117 * value from 0 to 199.
118 * @param order Order can be used to store a sort order. The sort order is used in client end, when
119 * presenting a list of nodes for the user.
120 * @param placement Placement can be used to store a room group index or house group index number.
121 * @param velocity This field indicates what velocity the node is operation with.
122 * @param variation More detail information like top hung, kip, flat roof or sky light window.
123 * @param powerMode This field indicates the power mode of the node (ALWAYS_ALIVE/LOW_POWER_MODE).
124 * @param serialNumber This field tells the serial number of the node. This field is 8 bytes.
125 * @param state This field indicates the operating state of the node.
126 * @param currentPosition This field indicates the current position of the node.
127 * @param target This field indicates the target position of the current operation.
128 * @param remainingTime This field indicates the remaining time for a node activation in seconds.
129 * @param timeStamp UTC time stamp for last known position.
131 public VeluxProduct(VeluxProductName name, VeluxProductType typeId, ProductBridgeIndex bridgeProductIndex,
132 int order, int placement, int velocity, int variation, int powerMode, String serialNumber, int state,
133 int currentPosition, int target, int remainingTime, int timeStamp) {
134 logger.trace("VeluxProduct(v2,name={}) created.", name.toString());
136 this.typeId = typeId;
137 this.bridgeProductIndex = bridgeProductIndex;
140 this.placement = placement;
141 this.velocity = velocity;
142 this.variation = variation;
143 this.powerMode = powerMode;
144 this.serialNumber = serialNumber;
146 this.currentPosition = currentPosition;
147 this.target = target;
148 this.remainingTime = remainingTime;
149 this.timeStamp = timeStamp;
155 public VeluxProduct clone() {
157 return new VeluxProduct(this.name, this.typeId, this.bridgeProductIndex, this.order, this.placement,
158 this.velocity, this.variation, this.powerMode, this.serialNumber, this.state, this.currentPosition,
159 this.target, this.remainingTime, this.timeStamp);
161 return new VeluxProduct(this.name, this.typeId, this.bridgeProductIndex);
165 // Class access methods
168 * Returns the name of the current product (aka actuator) for convenience as type-specific class.
170 * @return nameOfThisProduct as type {@link VeluxProductName}.
172 public VeluxProductName getProductName() {
177 * Returns the type of the current product (aka actuator) for convenience as type-specific class.
179 * @return typeOfThisProduct as type {@link VeluxProductType}.
181 public VeluxProductType getProductType() {
185 public ProductBridgeIndex getBridgeProductIndex() {
186 return this.bridgeProductIndex;
190 public String toString() {
192 return String.format("Product \"%s\" / %s (bridgeIndex=%d,serial=%s,position=%04X)", this.name, this.typeId,
193 this.bridgeProductIndex.toInt(), this.serialNumber, this.currentPosition);
195 return String.format("Product \"%s\" / %s (bridgeIndex %d)", this.name, this.typeId,
196 this.bridgeProductIndex.toInt());
200 // Class helper methods
202 public String getProductUniqueIndex() {
203 return this.name.toString().concat("#").concat(this.typeId.toString());
206 // Getter and Setter methods
209 * @return <b>v2</b> as type boolean signals the availability of firmware version two (product) details.
211 public boolean isV2() {
216 * @return <b>order</b> as type int describes the user-oriented sort-order.
218 public int getOrder() {
223 * @return <B>placement</B> as type int is used to describe a group index or house group index number.
225 public int getPlacement() {
230 * @return <B>velocity</B> as type int describes what velocity the node is operation with
232 public int getVelocity() {
237 * @return <B>variation</B> as type int describes detail information like top hung, kip, flat roof or sky light
240 public int getVariation() {
245 * @return <B>powerMode</B> as type int is used to show the power mode of the node (ALWAYS_ALIVE/LOW_POWER_MODE).
247 public int getPowerMode() {
252 * @return <B>serialNumber</B> as type String is the serial number of 8 bytes length of the node.
254 public String getSerialNumber() {
259 * @return <B>state</B> as type int is used to operating state of the node.
261 public int getState() {
266 * @param newState Update the operating state of the node.
267 * @return <B>modified</B> as type boolean to signal a real modification.
269 public boolean setState(int newState) {
270 if (this.state == newState) {
273 logger.trace("setState(name={},index={}) state {} replaced by {}.", name.toString(),
274 bridgeProductIndex.toInt(), this.state, newState);
275 this.state = newState;
281 * @return <B>currentPosition</B> as type int signals the current position of the node.
283 public int getCurrentPosition() {
284 return currentPosition;
288 * @param newCurrentPosition Update the current position of the node.
289 * @return <B>modified</B> as boolean to signal a real modification.
291 public boolean setCurrentPosition(int newCurrentPosition) {
292 if (this.currentPosition == newCurrentPosition) {
295 logger.trace("setCurrentPosition(name={},index={}) currentPosition {} replaced by {}.", name.toString(),
296 bridgeProductIndex.toInt(), this.currentPosition, newCurrentPosition);
297 this.currentPosition = newCurrentPosition;
303 * @return <b>target</b> as type int shows the target position of the current operation.
305 public int getTarget() {
310 * @param newTarget Update the target position of the current operation.
311 * @return <b>modified</b> as boolean to signal a real modification.
313 public boolean setTarget(int newTarget) {
314 if (this.target == newTarget) {
317 logger.trace("setCurrentPosition(name={},index={}) target {} replaced by {}.", name.toString(),
318 bridgeProductIndex.toInt(), this.target, newTarget);
319 this.target = newTarget;
325 * @return <b>remainingTime</b> as type int describes the intended remaining time of current operation.
327 public int getRemainingTime() {
328 return remainingTime;
332 * @return <b>timeStamp</b> as type int describes the current time.
334 public int getTimeStamp() {