2 * Copyright (c) 2010-2023 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.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;
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).
49 public class Channel {
50 public boolean isRetrieved = false;
51 public StringType firmwareVersion = new StringType(VeluxBindingConstants.UNKNOWN);
54 private Channel channel;
56 // Constructor methods
61 * Initializes the internal data structure {@link #channel} of Velux firmware information,
62 * which is publicly accessible via the method {@link #getChannel()}.
64 public VeluxBridgeGetFirmware() {
65 logger.trace("VeluxBridgeGetFirmware(constructor) called.");
66 channel = new Channel();
69 // Class access methods
72 * Provide access to the internal structure of actuators/products.
74 * @return {@link Channel} describing the overall actuator situation.
76 public Channel getChannel() {
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}.
85 * @param bridge Initialized Velux bridge handler.
86 * @return <b>channel</b> of type {@link VeluxBridgeGetFirmware.Channel} describing the overall result of this
89 public Channel retrieve(VeluxBridge bridge) {
90 logger.trace("retrieve() called.");
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);
98 this.channel.isRetrieved = false;
99 logger.trace("retrieve() finished with failure.");