]> git.basschouten.com Git - openhab-addons.git/blob
00acdca19ed73ec39bf184858df81d914bd831e3
[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.GetProductLimitation;
17 import org.openhab.binding.velux.internal.things.VeluxProductPosition;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * The {@link VeluxBridgeGetLimitation} represents a complete set of transactions
23  * for retrieval of the limitation of an actuator defined on the <B>Velux</B> bridge.
24  * <P>
25  * It therefore provides the methods
26  * <UL>
27  * <LI>{@link VeluxBridgeGetLimitation#getMinimumLimitation} for querying the lower limitation of an actuator,</LI>
28  * <LI>{@link VeluxBridgeGetLimitation#getMaximumLimitation} for querying the high limitation of an actuator.</LI>
29  * </UL>
30  *
31  * Any parameters are controlled by {@link org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration}.
32  *
33  * @see VeluxBridgeProvider
34  *
35  * @author Guenther Schreiner - Initial contribution
36  */
37 @NonNullByDefault
38 public class VeluxBridgeGetLimitation {
39     private final Logger logger = LoggerFactory.getLogger(VeluxBridgeGetLimitation.class);
40
41     // Private Objects
42
43     private VeluxProductPosition limitationResult = VeluxProductPosition.UNKNOWN;
44
45     // Class access methods
46
47     /**
48      * Login into bridge, instruct the bridge to pass a command towards an actuator based
49      * on a well-prepared environment of a {@link VeluxBridgeProvider}.
50      *
51      * @param bridge Initialized Velux bridge handler.
52      * @param nodeId Number of Actuator to be modified.
53      * @return true if successful, and false otherwise.
54      */
55     public boolean getMinimumLimitation(VeluxBridge bridge, int nodeId) {
56         logger.trace("getMinimumLimitation(nodeId={}) called.", nodeId);
57
58         boolean success = false;
59         GetProductLimitation bcp = bridge.bridgeAPI().getProductLimitation();
60         if (bcp != null) {
61             bcp.setActuatorIdAndLimitationType(nodeId, true);
62             if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
63                 success = true;
64                 limitationResult = new VeluxProductPosition(bcp.getLimitation());
65             }
66         }
67         logger.debug("getMinimumLimitation() finished {}.", (success ? "successfully" : "with failure"));
68         return success;
69     }
70
71     /**
72      * Login into bridge, instruct the bridge to pass a command towards an actuator based
73      * on a well-prepared environment of a {@link VeluxBridgeProvider}.
74      *
75      * @param bridge Initialized Velux bridge handler.
76      * @param nodeId Number of Actuator to be modified.
77      * @return true if successful, and false otherwise.
78      */
79     public boolean getMaximumLimitation(VeluxBridge bridge, int nodeId) {
80         logger.trace("getMaximumLimitation(nodeId={}) called.", nodeId);
81
82         boolean success = false;
83         GetProductLimitation bcp = bridge.bridgeAPI().getProductLimitation();
84         if (bcp != null) {
85             bcp.setActuatorIdAndLimitationType(nodeId, false);
86             if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
87                 success = true;
88                 limitationResult = new VeluxProductPosition(bcp.getLimitation());
89             }
90         }
91         logger.debug("getMaximumLimitation() finished {}.", (success ? "successfully" : "with failure"));
92         return success;
93     }
94
95     /**
96      * Return the limitation value.
97      *
98      * @return limitationResult of type VeluxProductPosition.
99      */
100     public VeluxProductPosition getLimitation() {
101         return limitationResult;
102     }
103 }