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();
36 public static class ProductBridgeIndex {
39 public static final ProductBridgeIndex UNKNOWN = new ProductBridgeIndex(0);
45 public ProductBridgeIndex(int id) {
49 // Class access methods
55 public String toString() {
56 return Integer.toString(id);
62 private VeluxProductName name;
63 private VeluxProductType typeId;
64 private ProductBridgeIndex bridgeProductIndex;
66 private boolean v2 = false;
67 private int order = 0;
68 private int placement = 0;
69 private int velocity = 0;
70 private int variation = 0;
71 private int powerMode = 0;
72 private String serialNumber = VeluxProductSerialNo.UNKNOWN;
73 private int state = 0;
74 private int currentPosition = 0;
75 private int target = 0;
76 private int remainingTime = 0;
77 private int timeStamp = 0;
84 * just for the dummy VeluxProduct.
86 public VeluxProduct() {
87 logger.trace("VeluxProduct() created.");
88 this.name = VeluxProductName.UNKNOWN;
89 this.typeId = VeluxProductType.UNDEFTYPE;
90 this.bridgeProductIndex = ProductBridgeIndex.UNKNOWN;
96 * @param name This field Name holds the name of the actuator, ex. “Window 1”. This field is 64 bytes
97 * long, formatted as UTF-8 characters.
98 * @param typeId This field indicates the node type, ex. Window, Roller shutter, Light etc.
99 * @param bridgeProductIndex NodeID is an Actuator index in the system table, to get information from. It must be a
100 * value from 0 to 199.
102 public VeluxProduct(VeluxProductName name, VeluxProductType typeId, ProductBridgeIndex bridgeProductIndex) {
103 logger.trace("VeluxProduct(v1,name={}) created.", name.toString());
105 this.typeId = typeId;
106 this.bridgeProductIndex = bridgeProductIndex;
112 * @param name This field Name holds the name of the actuator, ex. “Window 1”. This field is 64 bytes
113 * long, formatted as UTF-8 characters.
114 * @param typeId This field indicates the node type, ex. Window, Roller shutter, Light etc.
115 * @param bridgeProductIndex NodeID is an Actuator index in the system table, to get information from. It must be a
116 * value from 0 to 199.
117 * @param order Order can be used to store a sort order. The sort order is used in client end, when
118 * presenting a list of nodes for the user.
119 * @param placement Placement can be used to store a room group index or house group index number.
120 * @param velocity This field indicates what velocity the node is operation with.
121 * @param variation More detail information like top hung, kip, flat roof or sky light window.
122 * @param powerMode This field indicates the power mode of the node (ALWAYS_ALIVE/LOW_POWER_MODE).
123 * @param serialNumber This field tells the serial number of the node. This field is 8 bytes.
124 * @param state This field indicates the operating state of the node.
125 * @param currentPosition This field indicates the current position of the node.
126 * @param target This field indicates the target position of the current operation.
127 * @param remainingTime This field indicates the remaining time for a node activation in seconds.
128 * @param timeStamp UTC time stamp for last known position.
130 public VeluxProduct(VeluxProductName name, VeluxProductType typeId, ProductBridgeIndex bridgeProductIndex,
131 int order, int placement, int velocity, int variation, int powerMode, String serialNumber, int state,
132 int currentPosition, int target, int remainingTime, int timeStamp) {
133 logger.trace("VeluxProduct(v2,name={}) created.", name.toString());
135 this.typeId = typeId;
136 this.bridgeProductIndex = bridgeProductIndex;
139 this.placement = placement;
140 this.velocity = velocity;
141 this.variation = variation;
142 this.powerMode = powerMode;
143 this.serialNumber = serialNumber;
145 this.currentPosition = currentPosition;
146 this.target = target;
147 this.remainingTime = remainingTime;
148 this.timeStamp = timeStamp;
154 public VeluxProduct clone() {
156 return new VeluxProduct(this.name, this.typeId, this.bridgeProductIndex, this.order, this.placement,
157 this.velocity, this.variation, this.powerMode, this.serialNumber, this.state, this.currentPosition,
158 this.target, this.remainingTime, this.timeStamp);
160 return new VeluxProduct(this.name, this.typeId, this.bridgeProductIndex);
164 // Class access methods
167 * Returns the name of the current product (aka actuator) for convenience as type-specific class.
169 * @return nameOfThisProduct as type {@link VeluxProductName}.
171 public VeluxProductName getProductName() {
176 * Returns the type of the current product (aka actuator) for convenience as type-specific class.
178 * @return typeOfThisProduct as type {@link VeluxProductType}.
180 public VeluxProductType getProductType() {
184 public ProductBridgeIndex getBridgeProductIndex() {
185 return this.bridgeProductIndex;
189 public String toString() {
191 return String.format("Product \"%s\" / %s (bridgeIndex=%d,serial=%s,position=%04X)", this.name, this.typeId,
192 this.bridgeProductIndex.toInt(), this.serialNumber, this.currentPosition);
194 return String.format("Product \"%s\" / %s (bridgeIndex %d)", this.name, this.typeId,
195 this.bridgeProductIndex.toInt());
199 // Class helper methods
201 public String getProductUniqueIndex() {
202 return this.name.toString().concat("#").concat(this.typeId.toString());
205 // Getter and Setter methods
208 * @return <b>v2</b> as type boolean signals the availability of firmware version two (product) details.
210 public boolean isV2() {
215 * @return <b>order</b> as type int describes the user-oriented sort-order.
217 public int getOrder() {
222 * @return <B>placement</B> as type int is used to describe a group index or house group index number.
224 public int getPlacement() {
229 * @return <B>velocity</B> as type int describes what velocity the node is operation with
231 public int getVelocity() {
236 * @return <B>variation</B> as type int describes detail information like top hung, kip, flat roof or sky light
239 public int getVariation() {
244 * @return <B>powerMode</B> as type int is used to show the power mode of the node (ALWAYS_ALIVE/LOW_POWER_MODE).
246 public int getPowerMode() {
251 * @return <B>serialNumber</B> as type String is the serial number of 8 bytes length of the node.
253 public String getSerialNumber() {
258 * @return <B>state</B> as type int is used to operating state of the node.
260 public int getState() {
265 * @param newState Update the operating state of the node.
266 * @return <B>modified</B> as type boolean to signal a real modification.
268 public boolean setState(int newState) {
269 if (this.state == newState) {
272 logger.trace("setState(name={},index={}) state {} replaced by {}.", name.toString(),
273 bridgeProductIndex.toInt(), this.state, newState);
274 this.state = newState;
280 * @return <B>currentPosition</B> as type int signals the current position of the node.
282 public int getCurrentPosition() {
283 return currentPosition;
287 * @param newCurrentPosition Update the current position of the node.
288 * @return <B>modified</B> as boolean to signal a real modification.
290 public boolean setCurrentPosition(int newCurrentPosition) {
291 if (this.currentPosition == newCurrentPosition) {
294 logger.trace("setCurrentPosition(name={},index={}) currentPosition {} replaced by {}.", name.toString(),
295 bridgeProductIndex.toInt(), this.currentPosition, newCurrentPosition);
296 this.currentPosition = newCurrentPosition;
302 * @return <b>target</b> as type int shows the target position of the current operation.
304 public int getTarget() {
309 * @param newTarget Update the target position of the current operation.
310 * @return <b>modified</b> as boolean to signal a real modification.
312 public boolean setTarget(int newTarget) {
313 if (this.target == newTarget) {
316 logger.trace("setCurrentPosition(name={},index={}) target {} replaced by {}.", name.toString(),
317 bridgeProductIndex.toInt(), this.target, newTarget);
318 this.target = newTarget;
324 * @return <b>remainingTime</b> as type int describes the intended remaining time of current operation.
326 public int getRemainingTime() {
327 return remainingTime;
331 * @return <b>timeStamp</b> as type int describes the current time.
333 public int getTimeStamp() {