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.bridge;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.StringType;
17 import org.openhab.binding.velux.internal.VeluxBindingConstants;
18 import org.openhab.binding.velux.internal.bridge.common.GetFirmware;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The {@link VeluxBridgeGetFirmware} represents a complete set of transactions
24 * for retrieving of firmware version string on the <B>Velux</B> bridge.
26 * It provides the following methods:
28 * <LI>{@link #retrieve} for retrieval of information.
29 * <LI>{@link #getChannel} for accessing the retrieved information.
32 * @see VeluxBridgeProvider
34 * @author Guenther Schreiner - Initial contribution
37 public class VeluxBridgeGetFirmware {
38 private final Logger logger = LoggerFactory.getLogger(VeluxBridgeGetFirmware.class);
40 // Type definitions, class-internal variables
43 * Bridge information consisting of:
45 * <li>isRetrieved (boolean flag),
46 * <li>firmwareVersion (human readable String).
50 public class Channel {
51 public boolean isRetrieved = false;
52 public StringType firmwareVersion = new StringType(VeluxBindingConstants.UNKNOWN);
55 private Channel channel;
57 // Constructor methods
62 * Initializes the internal data structure {@link #channel} of Velux firmware information,
63 * which is publicly accessible via the method {@link #getChannel()}.
65 public VeluxBridgeGetFirmware() {
66 logger.trace("VeluxBridgeGetFirmware(constructor) called.");
67 channel = new Channel();
70 // Class access methods
73 * Provide access to the internal structure of actuators/products.
75 * @return {@link Channel} describing the overall actuator situation.
77 public Channel getChannel() {
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}.
86 * @param bridge Initialized Velux bridge handler.
87 * @return <b>channel</b> of type {@link VeluxBridgeGetFirmware.Channel} describing the overall result of this
90 public Channel retrieve(VeluxBridge bridge) {
91 logger.trace("retrieve() called.");
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);
99 this.channel.isRetrieved = false;
100 logger.trace("retrieve() finished with failure.");