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