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