]> git.basschouten.com Git - openhab-addons.git/blob
3c80f059ff2f75290c9fdb1aa3c48d688cbd5c84
[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.innogysmarthome.internal.client.entity.event;
14
15 import org.openhab.binding.innogysmarthome.internal.client.entity.capability.Capability;
16 import org.openhab.binding.innogysmarthome.internal.client.entity.device.Device;
17 import org.openhab.binding.innogysmarthome.internal.client.entity.link.Link;
18 import org.openhab.binding.innogysmarthome.internal.client.entity.message.Message;
19
20 /**
21  * Defines the {@link Event}, which is sent by the innogy websocket to inform the clients about changes.
22  *
23  * @author Oliver Kuhl - Initial contribution
24  */
25 public class MessageEvent extends BaseEvent {
26
27     public static final String EVENT_PROPERTY_CONFIGURATION_VERSION = "ConfigurationVersion";
28     public static final String EVENT_PROPERTY_IS_CONNECTED = "IsConnected";
29
30     /**
31      * Reference to the associated entity (instance or metadata) for the given event. Always available.
32      */
33     private String source;
34
35     /**
36      * The product (context) that generated the event.
37      */
38     private String namespace;
39
40     /**
41      * Data for the event, The data container can contain any type of entity dependent on the event type. For example,
42      * the DeviceFound events contains the entire Device entity rather than selected properties.
43      * Optional.
44      */
45     private Message data;
46
47     /**
48      * @return the link to the source
49      */
50     public String getSource() {
51         return source;
52     }
53
54     /**
55      * @param source the link to the source to set
56      */
57     public void setSource(String source) {
58         this.source = source;
59     }
60
61     /**
62      * @return the namespace
63      */
64     public String getNamespace() {
65         return namespace;
66     }
67
68     /**
69      * @param namespace the namespace to set
70      */
71     public void setNamespace(String namespace) {
72         this.namespace = namespace;
73     }
74
75     /**
76      * @return the dataList
77      */
78     public Message getData() {
79         return data;
80     }
81
82     /**
83      * @param message the message to set
84      */
85     public void setData(Message data) {
86         this.data = data;
87     }
88
89     public Message getMessage() {
90         return data;
91     }
92
93     /**
94      * Returns the id of the link or null, if there is no link or the link does not have an id.
95      *
96      * @return String the id of the link or null
97      */
98     public String getSourceId() {
99         final String linkType = getSourceLinkType();
100         if (linkType != null && !Link.LINK_TYPE_UNKNOWN.equals(linkType) && !Link.LINK_TYPE_SHC.equals(linkType)) {
101             if (source != null) {
102                 return source.replace(linkType, "");
103             }
104         }
105         return null;
106     }
107
108     /**
109      * Returns the Type of the {@link Link} in the {@link Event}.
110      *
111      * @return
112      */
113     public String getSourceLinkType() {
114         if (source != null) {
115             return Link.getLinkType(source);
116         }
117         return null;
118     }
119
120     /**
121      * Returns true, if the {@link Link} points to a {@link Capability}.
122      *
123      * @return
124      */
125     public Boolean isLinkedtoCapability() {
126         return source == null ? false : Link.isTypeCapability(source);
127     }
128
129     /**
130      * Returns true, if the {@link Link} points to a {@link Device}.
131      *
132      * @return
133      */
134     public Boolean isLinkedtoDevice() {
135         return source == null ? false : Link.isTypeDevice(source);
136     }
137
138     /**
139      * Returns true, if the {@link Link} points to a {@link Message}.
140      *
141      * @return
142      */
143     public Boolean isLinkedtoMessage() {
144         return source == null ? false : Link.isTypeMessage(source);
145     }
146
147     /**
148      * Returns true, if the {@link Link} points to the SHC {@link Device}.
149      *
150      * @return
151      */
152     public Boolean isLinkedtoSHC() {
153         return source == null ? false : Link.isTypeSHC(source);
154     }
155 }