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.bridge.common.GetDeviceStatus;
17 import org.openhab.binding.velux.internal.bridge.common.RunProductDiscovery;
18 import org.openhab.binding.velux.internal.things.VeluxGwState;
19 import org.openhab.binding.velux.internal.things.VeluxGwState.VeluxGatewaySubState;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The {@link VeluxBridgeDetectProducts} represents a complete set of transactions
25 * for temporary activation of device detection mode on the <B>Velux</B> bridge.
27 * It therefore provides a method:
29 * <LI>{@link VeluxBridgeDetectProducts#detectProducts} for starting the detection.
32 * @see VeluxBridgeProvider
34 * @author Guenther Schreiner - Initial contribution
37 public class VeluxBridgeDetectProducts {
38 private final Logger logger = LoggerFactory.getLogger(VeluxBridgeDetectProducts.class);
40 // Class access methods
43 * Login into bridge, start process to detect (new) products, loop until bridge is idle again and logout from bridge
44 * based on a well-prepared environment of a {@link VeluxBridgeProvider}.
46 * @param bridge Initialized Velux bridge handler.
47 * @return <b>success</b>
48 * of type boolean describing the overall result of this interaction.
50 public boolean detectProducts(VeluxBridge bridge) {
51 logger.trace("detectProducts() called.");
52 boolean success = false;
54 logger.trace("detectProducts() About to activate detection.");
55 RunProductDiscovery bcp1 = bridge.bridgeAPI().runProductDiscovery();
56 if (!(bridge.bridgeCommunicate(bcp1)) || (bcp1.isCommunicationSuccessful())) {
58 logger.trace("detectProducts() About to query detection status.");
59 GetDeviceStatus bcp = bridge.bridgeAPI().getDeviceStatus();
60 if (!(bridge.bridgeCommunicate(bcp)) || (bcp.isCommunicationSuccessful())) {
61 logger.trace("detectProducts() finished with failure.");
64 VeluxGwState deviceStatus = bcp.getState();
65 if (deviceStatus.getSubState() == (byte) VeluxGatewaySubState.GW_SS_P1.getStateValue()) {
66 logger.trace("detectProducts() bridge is still busy.");
67 } else if (deviceStatus.getSubState() == (byte) VeluxGatewaySubState.GW_SS_IDLE.getStateValue()) {
68 logger.trace("detectProducts() bridge is idle again, now.");
72 logger.info("detectProducts() unknown devicestatus ({}) received.", deviceStatus);
76 logger.trace("detectProducts() activate detection finished with failure.");
79 logger.debug("detectProducts() finished {}.", success ? "successfully" : "with failure");