]> git.basschouten.com Git - openhab-addons.git/blob
b69c6721d07d527a2a7be361306f144f97762ac2
[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.Logout;
17 import org.openhab.binding.velux.internal.bridge.slip.utils.KLF200Response;
18 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
19 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * Protocol specific bridge communication supported by the Velux bridge:
25  * <B>Retrieve LAN configuration</B>
26  * <P>
27  * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
28  * itself.
29  * <P>
30  * As 3rd level class it defines informations how to send query and receive answer through the
31  * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
32  * as described by the interface {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
33  * SlipBridgeCommunicationProtocol}.
34  * <P>
35  * There are no methods in addition to the mentioned interface.
36  *
37  * @see Logout
38  * @see SlipBridgeCommunicationProtocol
39  *
40  * @author Guenther Schreiner - Initial contribution.
41  */
42 @NonNullByDefault
43 class SClogout extends Logout implements SlipBridgeCommunicationProtocol {
44     private final Logger logger = LoggerFactory.getLogger(SClogout.class);
45
46     private static final String DESCRIPTION = "Deauthenticate / logout";
47     private static final Command COMMAND = Command.GW_OPENHAB_CLOSE;
48
49     /*
50      * ===========================================================
51      * Message Objects
52      */
53
54     private final byte[] emptyPacket = new byte[0];
55
56     /*
57      * ===========================================================
58      * Result Objects
59      */
60
61     private boolean success = false;
62     private boolean finished = false;
63
64     /*
65      * ===========================================================
66      * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
67      */
68
69     @Override
70     public String name() {
71         return DESCRIPTION;
72     }
73
74     @Override
75     public CommandNumber getRequestCommand() {
76         return COMMAND.getCommand();
77     }
78
79     @Override
80     public byte[] getRequestDataAsArrayOfBytes() {
81         return emptyPacket;
82     }
83
84     @Override
85     public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
86         KLF200Response.introLogging(logger, responseCommand, thisResponseData);
87         success = true;
88         finished = true;
89         KLF200Response.outroLogging(logger, success, finished);
90     }
91
92     @Override
93     public boolean isCommunicationFinished() {
94         return finished;
95     }
96
97     @Override
98     public boolean isCommunicationSuccessful() {
99         return success;
100     }
101 }