]> git.basschouten.com Git - openhab-addons.git/blob
7b58c0bb6c69be98bd696e5aad2ff4ff617f529e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.bridge.common.RunProductCommand;
17 import org.openhab.binding.velux.internal.things.VeluxProductPosition;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * The {@link VeluxBridgeRunProductCommand} represents a complete set of transactions
23  * for executing a scene defined on the <B>Velux</B> bridge.
24  * <P>
25  * It provides a method {@link VeluxBridgeRunProductCommand#sendCommand} for sending a parameter change command.
26  * Any parameters are controlled by {@link org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration}.
27  *
28  * @see VeluxBridgeProvider
29  *
30  * @author Guenther Schreiner - Initial contribution
31  */
32 @NonNullByDefault
33 public class VeluxBridgeRunProductCommand {
34     private final Logger logger = LoggerFactory.getLogger(VeluxBridgeRunProductCommand.class);
35
36     // Class access methods
37
38     /**
39      * Login into bridge, instruct the bridge to pass a command towards an actuator based
40      * on a well-prepared environment of a {@link VeluxBridgeProvider}.
41      *
42      * @param bridge Initialized Velux bridge handler.
43      * @param nodeId Number of Actuator to be modified.
44      * @param value Target value for Actuator main parameter.
45      * @return true if successful, and false otherwise.
46      */
47     public boolean sendCommand(VeluxBridge bridge, int nodeId, VeluxProductPosition value) {
48         logger.trace("sendCommand(nodeId={},value={}) called.", nodeId, value);
49
50         boolean success = false;
51         RunProductCommand bcp = bridge.bridgeAPI().runProductCommand();
52         if (bcp != null) {
53             int veluxValue = value.getPositionAsVeluxType();
54
55             bcp.setNodeAndMainParameter(nodeId, veluxValue);
56             if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
57                 success = true;
58             }
59         }
60         logger.debug("sendCommand() finished {}.", (success ? "successfully" : "with failure"));
61         return success;
62     }
63 }