]> git.basschouten.com Git - openhab-addons.git/blob
351121e45b045756b1404db3b9ee1075b5a5e76c
[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.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     public class Channel {
50         public boolean isRetrieved = false;
51         public StringType firmwareVersion = new StringType(VeluxBindingConstants.UNKNOWN);
52     }
53
54     private Channel channel;
55
56     // Constructor methods
57
58     /**
59      * Constructor.
60      * <P>
61      * Initializes the internal data structure {@link #channel} of Velux firmware information,
62      * which is publicly accessible via the method {@link #getChannel()}.
63      */
64     public VeluxBridgeGetFirmware() {
65         logger.trace("VeluxBridgeGetFirmware(constructor) called.");
66         channel = new Channel();
67     }
68
69     // Class access methods
70
71     /**
72      * Provide access to the internal structure of actuators/products.
73      *
74      * @return {@link Channel} describing the overall actuator situation.
75      */
76     public Channel getChannel() {
77         return channel;
78     }
79
80     /**
81      * Complete workflow for retrieving the firmware version, consisting of Login into bridge, querying the firmware
82      * version and logout from bridge based on a well-prepared environment of a {@link VeluxBridgeProvider}, where the
83      * results are stored in {@link VeluxBridgeGetFirmware#channel}.
84      *
85      * @param bridge Initialized Velux bridge handler.
86      * @return <b>channel</b> of type {@link VeluxBridgeGetFirmware.Channel} describing the overall result of this
87      *         interaction.
88      */
89     public Channel retrieve(VeluxBridge bridge) {
90         logger.trace("retrieve() called.");
91
92         GetFirmware bcp = bridge.bridgeAPI().getFirmware();
93         if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
94             this.channel.firmwareVersion = new StringType(bcp.getFirmware().getfirmwareVersion());
95             this.channel.isRetrieved = true;
96             logger.trace("retrieve() found successfully firmware {}.", this.channel.firmwareVersion);
97         } else {
98             this.channel.isRetrieved = false;
99             logger.trace("retrieve() finished with failure.");
100         }
101         return channel;
102     }
103 }