]> git.basschouten.com Git - openhab-addons.git/blob
bf4c85c9d90aee6314955f8a6f31004dbebe6522
[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.innogysmarthome.internal.client.entity.event;
14
15 import java.util.Collections;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19
20 /**
21  * @author Oliver Kuhl - Initial contribution
22  *
23  */
24 public class BaseEvent {
25
26     public static final String TYPE_STATE_CHANGED = "StateChanged";// "device/SHC.RWE/1.0/event/StateChanged";
27     public static final String TYPE_NEW_MESSAGE_RECEIVED = "NewMessageReceived"; // "device/SHC.RWE/1.0/event/NewMessageReceived";
28     public static final String TYPE_MESSAGE_CREATED = "MessageCreated";
29     public static final String TYPE_MESSAGE_DELETED = "MessageDeleted"; // "device/SHC.RWE/1.0/event/MessageDeleted";
30     public static final String TYPE_DISCONNECT = "Disconnect"; // "/event/Disconnect";
31     public static final String TYPE_CONFIGURATION_CHANGED = "ConfigurationChanged"; // "device/SHC.RWE/1.0/event/ConfigChanged";
32     public static final String TYPE_CONTROLLER_CONNECTIVITY_CHANGED = "/event/ControllerConnectivityChanged"; // "device/SHC.RWE/1.0/event/ControllerConnectivityChanged";
33     public static final String TYPE_BUTTON_PRESSED = "ButtonPressed";
34
35     public static final Set<String> SUPPORTED_EVENT_TYPES = Collections
36             .unmodifiableSet(Stream.of(TYPE_STATE_CHANGED, TYPE_NEW_MESSAGE_RECEIVED, TYPE_MESSAGE_CREATED,
37                     TYPE_MESSAGE_DELETED, TYPE_DISCONNECT, TYPE_CONFIGURATION_CHANGED,
38                     TYPE_CONTROLLER_CONNECTIVITY_CHANGED, TYPE_BUTTON_PRESSED).collect(Collectors.toSet()));
39
40     /**
41      * The event sequence number – the gateway keeps track and adds a sequence number to each event for the client to
42      * identify order and missing events
43      */
44     private Integer sequenceNumber;
45
46     /**
47      * Specifies the type of the event. The type must be the full path to uniquely reference the event definition.
48      * Always available.
49      */
50     private String type;
51
52     /**
53      * Date and time when the event occurred in the system. Always available.
54      */
55     private String timestamp;
56
57     /**
58      * @return the sequenceNumber
59      */
60     public Integer getSequenceNumber() {
61         return sequenceNumber;
62     }
63
64     /**
65      * @return the timestamp
66      */
67     public String getTimestamp() {
68         return timestamp;
69     }
70
71     /**
72      * @return the type
73      */
74     public String getType() {
75         return type;
76     }
77
78     /**
79      * @param sequenceNumber the sequenceNumber to set
80      */
81     public void setSequenceNumber(Integer sequenceNumber) {
82         this.sequenceNumber = sequenceNumber;
83     }
84
85     /**
86      * @param timestamp the timestamp to set
87      */
88     public void setTimestamp(String timestamp) {
89         this.timestamp = timestamp;
90     }
91
92     /**
93      * @param type the type to set
94      */
95     public void setType(String type) {
96         this.type = type;
97     }
98
99     /**
100      * Returns true, if the {@link Event} is a ConfigChanged event.
101      *
102      * @return
103      */
104     public boolean isConfigChangedEvent() {
105         return TYPE_CONFIGURATION_CHANGED.equals(getType());
106     }
107
108     /**
109      * Returns true, if the {@link Event} is a ControllerConnectivityChanged event.
110      *
111      * @return
112      */
113     public boolean isControllerConnectivityChangedEvent() {
114         return TYPE_CONTROLLER_CONNECTIVITY_CHANGED.equals(getType());
115     }
116
117     /**
118      * Returns true, if the {@link Event} is a Disconnect event.
119      *
120      * @return
121      */
122     public boolean isDisconnectedEvent() {
123         return TYPE_DISCONNECT.equals(getType());
124     }
125
126     /**
127      * Returns true, if the {@link Event} is a MessageDeletedEvent.
128      *
129      * @return
130      */
131     public boolean isMessageDeletedEvent() {
132         return TYPE_MESSAGE_DELETED.equals(getType());
133     }
134
135     /**
136      * Returns true, if the {@link Event} is a NewMessageReceivedEvent.
137      *
138      * @return
139      */
140     public boolean isNewMessageReceivedEvent() {
141         return TYPE_NEW_MESSAGE_RECEIVED.equals(getType());
142     }
143
144     /**
145      * Returns true, if the {@link Event} is a StateChangedEvent.
146      *
147      * @return
148      */
149     public boolean isStateChangedEvent() {
150         return TYPE_STATE_CHANGED.equals(getType());
151     }
152 }