]> git.basschouten.com Git - openhab-addons.git/blob
8b7b27dafa527aeecce4ad1f7aa1ab85c641dfe6
[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.SetProductLimitation;
17 import org.openhab.binding.velux.internal.things.VeluxProductPosition;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * The {@link VeluxBridgeSetLimitation} represents a complete set of transactions
23  * for modifying 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 VeluxBridgeSetLimitation#setMinimumLimitation} for modifying the lower limitation of an actuator,</LI>
28  * <LI>{@link VeluxBridgeSetLimitation#setMaximumLimitation} for modifying the high limitation of an actuator.</LI>
29  * </UL>
30  * Any parameters are controlled by {@link org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration}.
31  *
32  * @see VeluxBridgeProvider
33  *
34  * @author Guenther Schreiner - Initial contribution
35  */
36 @NonNullByDefault
37 public class VeluxBridgeSetLimitation {
38     private final Logger logger = LoggerFactory.getLogger(VeluxBridgeSetLimitation.class);
39
40     // Class access methods
41
42     /**
43      * Login into bridge, modify the scene parameters and logout from bridge based
44      * on a well-prepared environment of a {@link VeluxBridgeProvider}.
45      *
46      * @param bridge Initialized Velux bridge handler.
47      * @param nodeId Number of Actuator to be modified.
48      * @param limitationMinimum new value for minimum limit.
49      * @return true if successful, and false otherwise.
50      */
51     public boolean setMinimumLimitation(VeluxBridge bridge, int nodeId, VeluxProductPosition limitationMinimum) {
52         logger.trace("setMinimumLimitation(nodeId={}, limitation={}) called.", nodeId, limitationMinimum);
53
54         SetProductLimitation bcp = bridge.bridgeAPI().setProductLimitation();
55         if (bcp == null) {
56             logger.info("setMinimumLimitation(): aborting processing as there is handler available.");
57             return false;
58         }
59         bcp.setActuatorIdAndMinimumLimitation(nodeId, limitationMinimum.getPositionAsVeluxType());
60         if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
61             logger.trace("setMinimumLimitation() finished successfully.");
62             return true;
63         }
64         logger.trace("setMinimumLimitation() finished with failure.");
65         return false;
66     }
67
68     /**
69      * Login into bridge, modify the scene parameters and logout from bridge based
70      * on a well-prepared environment of a {@link VeluxBridgeProvider}.
71      *
72      * @param bridge Initialized Velux bridge handler.
73      * @param nodeId Number of Actuator to be modified.
74      * @param limitationMaximum new value for maximum limit.
75      * @return true if successful, and false otherwise.
76      */
77     public boolean setMaximumLimitation(VeluxBridge bridge, int nodeId, VeluxProductPosition limitationMaximum) {
78         logger.trace("setMaximumLimitation(nodeId={}, limitation={}) called.", nodeId, limitationMaximum);
79
80         SetProductLimitation bcp = bridge.bridgeAPI().setProductLimitation();
81         if (bcp == null) {
82             logger.info("setMaximumLimitation(): aborting processing as there is handler available.");
83             return false;
84         }
85         bcp.setActuatorIdAndMaximumLimitation(nodeId, limitationMaximum.getPositionAsVeluxType());
86         if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
87             logger.trace("setMaximumLimitation() finished successfully.");
88             return true;
89         }
90         logger.trace("setMaximumLimitation() finished with failure.");
91         return false;
92     }
93 }