]> git.basschouten.com Git - openhab-addons.git/blob
72a03a95982b61593dbd7a7bae6c093166d9fa65
[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 org.openhab.binding.livisismarthome.internal.client.api.entity.link.LinkDTO;
16
17 /**
18  * Defines the {@link EventDTO}, which is sent by the LIVISI websocket to inform the clients about changes.
19  *
20  * @author Oliver Kuhl - Initial contribution
21  */
22 public class EventDTO extends BaseEventDTO {
23
24     /**
25      * Reference to the associated entity (instance or metadata) for the given event. Always available.
26      */
27     private String source;
28
29     /**
30      * The product (context) that generated the event.
31      */
32     private String namespace;
33
34     /**
35      * This container includes only properties, e.g. for the changed state properties. If there is other data than
36      * properties to be transported, the data container will be used.
37      * Optional.
38      */
39     private EventPropertiesDTO properties;
40
41     /**
42      * Data for the event, The data container can contain any type of entity dependent on the event type. For example,
43      * the DeviceFound events contains the entire Device entity rather than selected properties.
44      * Optional.
45      */
46     private EventDataDTO data;
47
48     /**
49      * @return the link to the source
50      */
51     public String getSource() {
52         return source;
53     }
54
55     /**
56      * @param source the link to the source to set
57      */
58     public void setSource(String source) {
59         this.source = source;
60     }
61
62     /**
63      * @return the namespace
64      */
65     public String getNamespace() {
66         return namespace;
67     }
68
69     /**
70      * @param namespace the namespace to set
71      */
72     public void setNamespace(String namespace) {
73         this.namespace = namespace;
74     }
75
76     /**
77      * @return the properties
78      */
79     public EventPropertiesDTO getProperties() {
80         return properties;
81     }
82
83     /**
84      * @param properties the properties to set
85      */
86     public void setProperties(EventPropertiesDTO properties) {
87         this.properties = properties;
88     }
89
90     /**
91      * @return the dataList
92      */
93     public EventDataDTO getData() {
94         return data;
95     }
96
97     /**
98      * @param data the data to set
99      */
100     public void setData(EventDataDTO data) {
101         this.data = data;
102     }
103
104     /**
105      * Returns the id of the link or null, if there is no link or the link does not have an id.
106      *
107      * @return String the id of the link or null
108      */
109     public String getSourceId() {
110         final String linkType = getSourceLinkType();
111         if (linkType != null && !LinkDTO.LINK_TYPE_UNKNOWN.equals(linkType)
112                 && !LinkDTO.LINK_TYPE_SHC.equals(linkType)) {
113             if (source != null) {
114                 String sourceId = source.replace(linkType, "");
115                 sourceId = sourceId.replace("-", "");
116                 return sourceId;
117             }
118         }
119         return null;
120     }
121
122     /**
123      * Returns the Type of the {@link LinkDTO} in the {@link EventDTO}.
124      *
125      * @return link type
126      */
127     public String getSourceLinkType() {
128         if (source != null) {
129             return LinkDTO.getLinkType(source);
130         }
131         return null;
132     }
133
134     /**
135      * Returns true, if the {@link LinkDTO} points to a
136      * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.capability.CapabilityDTO}.
137      *
138      * @return true if the link points to a capability, otherwise false
139      */
140     public Boolean isLinkedtoCapability() {
141         return source != null && LinkDTO.isTypeCapability(source);
142     }
143
144     /**
145      * Returns true, if the {@link LinkDTO} points to a
146      * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.device.DeviceDTO}.
147      *
148      * @return true if the link points to a device, otherwise false
149      */
150     public Boolean isLinkedtoDevice() {
151         return source != null && LinkDTO.isTypeDevice(source);
152     }
153
154     /**
155      * Returns true, if the {@link LinkDTO} points to a
156      * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.message.MessageDTO}.
157      *
158      * @return true if the link points to a message, otherwise false
159      */
160     public Boolean isLinkedtoMessage() {
161         return source != null && LinkDTO.isTypeMessage(source);
162     }
163
164     /**
165      * Returns true, if the {@link LinkDTO} points to the SHC
166      * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.device.DeviceDTO}.
167      *
168      * @return true if the link points to a SHC bridge device, otherwise false
169      */
170     public Boolean isLinkedtoSHC() {
171         return source != null && LinkDTO.isTypeSHC(source);
172     }
173
174     /**
175      * Returns true, if it is a button pressed event. Otherwise false.
176      * It is a button pressed event when button index is set (LastPressedButtonIndex is set too).
177      * 
178      * @return true if it is a button pressed event, otherwise false
179      */
180     public boolean isButtonPressedEvent() {
181         final Integer buttonIndex = getProperties().getKeyPressButtonIndex();
182         return buttonIndex != null;
183     }
184
185     /**
186      * Returns the configurationVersion or null, if this
187      * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.PropertyDTO} is not available in the event.
188      *
189      * @return configuration version
190      */
191     public Integer getConfigurationVersion() {
192         return getData().getConfigVersion();
193     }
194
195     /**
196      * Returns the isConnected {@link org.openhab.binding.livisismarthome.internal.client.api.entity.PropertyDTO} value.
197      * Only available for event of type ControllerConnectivityChanged
198      *
199      * @return {@link Boolean} or <code>null</code>, if not available
200      */
201     public Boolean getIsConnected() {
202         return getProperties().getIsConnected();
203     }
204 }