]> git.basschouten.com Git - openhab-addons.git/blob
f01bc6884f97264e160e4f50b4318df29e8a0eaf
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.satel.internal.event;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * Event class describing connection status to Satel module.
20  *
21  * @author Krzysztof Goworek - Initial contribution
22  */
23 @NonNullByDefault
24 public class ConnectionStatusEvent implements SatelEvent {
25
26     private boolean connected;
27
28     private @Nullable String reason;
29
30     /**
31      * Constructs event class with given connection status.
32      *
33      * @param connected value describing connection status
34      */
35     public ConnectionStatusEvent(boolean connected) {
36         this(connected, null);
37     }
38
39     /**
40      * Constructs event class with given connection status and disconnection reason.
41      *
42      * @param connected value describing connection status
43      * @param reason disconnection reason
44      */
45     public ConnectionStatusEvent(boolean connected, @Nullable String reason) {
46         this.connected = connected;
47         this.reason = reason;
48     }
49
50     /**
51      * Returns status of connection.
52      *
53      * @return a boolean value describing connection status
54      */
55     public boolean isConnected() {
56         return this.connected;
57     }
58
59     /**
60      * Returns disconnection reason.
61      *
62      * @return optional text description in case of disconnection
63      */
64     public @Nullable String getReason() {
65         return reason;
66     }
67
68     @Override
69     public String toString() {
70         return String.format("%s: connected = %b, reason = %s", this.getClass().getName(), this.connected, this.reason);
71     }
72 }