]> git.basschouten.com Git - openhab-addons.git/blob
a1b6952cf78e7249ca7196c57df0056201749c43
[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.SetHouseStatusMonitor;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * The {@link VeluxBridgeSetHouseStatusMonitor} represents a complete set of transactions
22  * for modifying the service state of the <B>House Status Monitor</B> on the <B>Velux</B> bridge.
23  * <P>
24  * The HSM is responsible for continuous updates towards the communication initiator
25  * about any changes of actuator states.
26  * <P>
27  * It therefore provides a method {@link VeluxBridgeSetHouseStatusMonitor#modifyHSM} for modifying the HSM settings.
28  * Any parameters are controlled by {@link org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration}.
29  *
30  * @see VeluxBridgeProvider
31  *
32  * @author Guenther Schreiner - Initial contribution
33  */
34 @NonNullByDefault
35 public class VeluxBridgeSetHouseStatusMonitor {
36     private final Logger logger = LoggerFactory.getLogger(VeluxBridgeSetHouseStatusMonitor.class);
37
38     // Class access methods
39
40     /**
41      * Login into bridge, modify HSM and logout from bridge based
42      * on a well-prepared environment of a {@link VeluxBridgeProvider}.
43      *
44      * @param bridge Initialized Velux bridge handler.
45      * @param enableService Flag whether the HSM should be activated.
46      * @return true if successful or false otherwise.
47      */
48     public boolean modifyHSM(VeluxBridge bridge, boolean enableService) {
49         logger.trace("modifyHSM({}) called.", enableService);
50
51         boolean success = false;
52         SetHouseStatusMonitor bcp = bridge.bridgeAPI().setHouseStatusMonitor();
53         if (bcp != null) {
54             bcp.serviceActivation(enableService);
55             if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
56                 success = true;
57             }
58         }
59         logger.debug("modifyHSM() finished {}.", (success ? "successfully" : "with failure"));
60         return success;
61     }
62 }