]> git.basschouten.com Git - openhab-addons.git/blob
f4971ca1c5395153609c3fb2178548aac7619433
[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.bridge;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.VeluxBindingConstants;
17 import org.openhab.binding.velux.internal.bridge.common.GetFirmware;
18 import org.openhab.core.library.types.StringType;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * The {@link VeluxBridgeGetFirmware} represents a complete set of transactions
24  * for retrieving of firmware version string on the <B>Velux</B> bridge.
25  * <P>
26  * It provides the following methods:
27  * <UL>
28  * <LI>{@link #retrieve} for retrieval of information.
29  * <LI>{@link #getChannel} for accessing the retrieved information.
30  * </UL>
31  *
32  * @see VeluxBridgeProvider
33  *
34  * @author Guenther Schreiner - Initial contribution
35  */
36 @NonNullByDefault
37 public class VeluxBridgeGetFirmware {
38     private final Logger logger = LoggerFactory.getLogger(VeluxBridgeGetFirmware.class);
39
40     // Type definitions, class-internal variables
41
42     /**
43      * Bridge information consisting of:
44      * <ul>
45      * <li>isRetrieved (boolean flag),
46      * <li>firmwareVersion (human readable String).
47      * </ul>
48      */
49     @NonNullByDefault
50     public class Channel {
51         public boolean isRetrieved = false;
52         public StringType firmwareVersion = new StringType(VeluxBindingConstants.UNKNOWN);
53     }
54
55     private Channel channel;
56
57     // Constructor methods
58
59     /**
60      * Constructor.
61      * <P>
62      * Initializes the internal data structure {@link #channel} of Velux firmware information,
63      * which is publicly accessible via the method {@link #getChannel()}.
64      */
65     public VeluxBridgeGetFirmware() {
66         logger.trace("VeluxBridgeGetFirmware(constructor) called.");
67         channel = new Channel();
68     }
69
70     // Class access methods
71
72     /**
73      * Provide access to the internal structure of actuators/products.
74      *
75      * @return {@link Channel} describing the overall actuator situation.
76      */
77     public Channel getChannel() {
78         return channel;
79     }
80
81     /**
82      * Complete workflow for retrieving the firmware version, consisting of Login into bridge, querying the firmware
83      * version and logout from bridge based on a well-prepared environment of a {@link VeluxBridgeProvider}, where the
84      * results are stored in {@link VeluxBridgeGetFirmware#channel}.
85      *
86      * @param bridge Initialized Velux bridge handler.
87      * @return <b>channel</b> of type {@link VeluxBridgeGetFirmware.Channel} describing the overall result of this
88      *         interaction.
89      */
90     public Channel retrieve(VeluxBridge bridge) {
91         logger.trace("retrieve() called.");
92
93         GetFirmware bcp = bridge.bridgeAPI().getFirmware();
94         if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
95             this.channel.firmwareVersion = new StringType(bcp.getFirmware().getfirmwareVersion());
96             this.channel.isRetrieved = true;
97             logger.trace("retrieve() found successfully firmware {}.", this.channel.firmwareVersion);
98         } else {
99             this.channel.isRetrieved = false;
100             logger.trace("retrieve() finished with failure.");
101         }
102         return channel;
103     }
104 }