]> git.basschouten.com Git - openhab-addons.git/blob
511045cb5a60bab850af32d6bec0388ff94128c0
[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.bridge.common.RunScene;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * The {@link VeluxBridgeRunScene} represents a complete set of transactions
22  * for executing a scene defined on the <B>Velux</B> bridge.
23  * <P>
24  * It provides a method {@link VeluxBridgeRunScene#execute} for execution of a scene.
25  * Any parameters are controlled by {@link org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration}.
26  *
27  * @see VeluxBridgeProvider
28  *
29  * @author Guenther Schreiner - Initial contribution
30  */
31 @NonNullByDefault
32 public class VeluxBridgeRunScene {
33     private final Logger logger = LoggerFactory.getLogger(VeluxBridgeRunScene.class);
34
35     /**
36      * Login into bridge, execute a scene and logout from bridge based
37      * on a well-prepared environment of a {@link VeluxBridgeProvider}.
38      *
39      * @param bridge Initialized Velux bridge handler.
40      * @param sceneNo Number of scene to be executed.
41      * @return true if successful, and false otherwise.
42      */
43     public boolean execute(VeluxBridge bridge, int sceneNo) {
44         logger.trace("execute({}) called.", sceneNo);
45
46         RunScene bcp = bridge.bridgeAPI().runScene().setSceneId(sceneNo);
47         if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
48             logger.debug("execute() finished successfully.");
49             return true;
50         } else {
51             logger.trace("execute() finished with failure.");
52             return false;
53         }
54     }
55
56     /**
57      * Login into bridge, execute a scene and logout from bridge based
58      * on a well-prepared environment of a {@link VeluxBridgeProvider}.
59      *
60      * @param bridge Initialized Velux bridge handler.
61      * @param sceneNo Number of scene to be executed.
62      * @param velocity integer representing the velocity.
63      * @return true if successful, and false otherwise.
64      */
65     public boolean execute(VeluxBridge bridge, int sceneNo, int velocity) {
66         logger.trace("execute({},{}) called.", sceneNo, velocity);
67
68         RunScene bcp = bridge.bridgeAPI().runScene().setVelocity(velocity).setSceneId(sceneNo);
69         if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
70             logger.debug("execute() finished successfully.");
71             return true;
72         } else {
73             logger.trace("execute() finished with failure.");
74             return false;
75         }
76     }
77 }