]> git.basschouten.com Git - openhab-addons.git/blob
9dd89eead748dfc4123bfd30fb6a15f85311ada3
[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.slip;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.bridge.common.SetHouseStatusMonitor;
17 import org.openhab.binding.velux.internal.bridge.slip.utils.KLF200Response;
18 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
19 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
20 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Protocol specific bridge communication supported by the Velux bridge:
26  * <B>Modify HouseStatusMonitor</B>
27  * <P>
28  * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
29  * itself.
30  * <P>
31  * As 3rd level class it defines informations how to send query and receive answer through the
32  * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
33  * as described by the interface {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
34  * SlipBridgeCommunicationProtocol}.
35  * <P>
36  * Methods in addition to the mentioned interface:
37  * <UL>
38  * <LI>{@link #serviceActivation} to define the new service activation state.</LI>
39  * </UL>
40  *
41  * @see SetHouseStatusMonitor
42  * @see SlipBridgeCommunicationProtocol
43  *
44  * @author Guenther Schreiner - Initial contribution.
45  */
46 @NonNullByDefault
47 class SCsetHouseStatusMonitor extends SetHouseStatusMonitor implements SlipBridgeCommunicationProtocol {
48     private final Logger logger = LoggerFactory.getLogger(SCsetHouseStatusMonitor.class);
49
50     private static final String DESCRIPTION = "Modify HouseStatusMonitor";
51
52     /*
53      * ===========================================================
54      * Message Content Parameters
55      */
56
57     private boolean activateService = false;
58
59     /*
60      * ===========================================================
61      * Message Objects
62      */
63
64     private byte[] requestData = new byte[0];
65
66     /*
67      * ===========================================================
68      * Result Objects
69      */
70
71     private boolean success = false;
72     private boolean finished = false;
73
74     /*
75      * ===========================================================
76      * Methods required for interface {@link BridgeCommunicationProtocol}.
77      */
78
79     @Override
80     public String name() {
81         return DESCRIPTION;
82     }
83
84     @Override
85     public CommandNumber getRequestCommand() {
86         Command command = activateService ? Command.GW_HOUSE_STATUS_MONITOR_ENABLE_REQ
87                 : Command.GW_HOUSE_STATUS_MONITOR_DISABLE_REQ;
88         success = false;
89         finished = false;
90         logger.debug("getRequestCommand() returns {} ({}).", command.name(), command.getCommand());
91         return command.getCommand();
92     }
93
94     @Override
95     public byte[] getRequestDataAsArrayOfBytes() {
96         logger.debug("getRequestDataAsArrayOfBytes() data is {}.", new Packet(requestData).toString());
97         return requestData;
98     }
99
100     @Override
101     public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
102         KLF200Response.introLogging(logger, responseCommand, thisResponseData);
103         success = false;
104         finished = true;
105         switch (Command.get(responseCommand)) {
106             case GW_HOUSE_STATUS_MONITOR_ENABLE_CFM:
107                 logger.trace("setResponse(): service enable confirmed by bridge.");
108                 // returned enabled: successful if enable requested
109                 success = activateService;
110                 break;
111             case GW_HOUSE_STATUS_MONITOR_DISABLE_CFM:
112                 logger.trace("setResponse(): service disable confirmed by bridge.");
113                 // returned disabled: successful if disable requested
114                 success = !activateService;
115                 break;
116
117             default:
118                 KLF200Response.errorLogging(logger, responseCommand);
119         }
120         KLF200Response.outroLogging(logger, success, finished);
121     }
122
123     @Override
124     public boolean isCommunicationFinished() {
125         return finished;
126     }
127
128     @Override
129     public boolean isCommunicationSuccessful() {
130         return success;
131     }
132
133     /*
134      * ===========================================================
135      * Methods in addition to the interface {@link BridgeCommunicationProtocol}
136      * and the abstract class {@link SetHouseStatusMonitor}
137      */
138
139     @Override
140     public SetHouseStatusMonitor serviceActivation(boolean enableService) {
141         this.activateService = enableService;
142         return this;
143     }
144 }