2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.innogysmarthome.internal.client.entity.event;
15 import java.util.HashMap;
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;
24 * Defines the {@link Event}, which is sent by the innogy websocket to inform the clients about changes.
26 * @author Oliver Kuhl - Initial contribution
28 public class Event extends BaseEvent {
30 public static final String EVENT_PROPERTY_CONFIGURATION_VERSION = "ConfigurationVersion";
31 public static final String EVENT_PROPERTY_IS_CONNECTED = "IsConnected";
34 * Reference to the associated entity (instance or metadata) for the given event. Always available.
36 private String source;
39 * The product (context) that generated the event.
41 private String namespace;
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.
48 private EventProperties properties;
50 protected HashMap<String, Property> propertyMap;
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.
57 private EventData data;
60 * @return the link to the source
62 public String getSource() {
67 * @param source the link to the source to set
69 public void setSource(String source) {
74 * @return the namespace
76 public String getNamespace() {
81 * @param namespace the namespace to set
83 public void setNamespace(String namespace) {
84 this.namespace = namespace;
88 * @return the properties
90 public EventProperties getProperties() {
95 * @param propertyList the propertyList to set
97 public void setProperties(EventProperties properties) {
98 this.properties = properties;
102 * @return the dataList
104 public EventData getData() {
109 * @param dataList the dataList to set
111 public void setData(EventData data) {
116 * Returns the id of the link or null, if there is no link or the link does not have an id.
118 * @return String the id of the link or null
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, "");
131 * Returns the Type of the {@link Link} in the {@link Event}.
135 public String getSourceLinkType() {
136 if (source != null) {
137 return Link.getLinkType(source);
143 * Returns true, if the {@link Link} points to a {@link Capability}.
147 public Boolean isLinkedtoCapability() {
148 return source == null ? false : Link.isTypeCapability(source);
152 * Returns true, if the {@link Link} points to a {@link Device}.
156 public Boolean isLinkedtoDevice() {
157 return source == null ? false : Link.isTypeDevice(source);
161 * Returns true, if the {@link Link} points to a {@link Message}.
165 public Boolean isLinkedtoMessage() {
166 return source == null ? false : Link.isTypeMessage(source);
170 * Returns true, if the {@link Link} points to the SHC {@link Device}.
174 public Boolean isLinkedtoSHC() {
175 return source == null ? false : Link.isTypeSHC(source);
179 * Returns the configurationVersion or null, if this {@link Property} is not available in the event.
183 public Integer getConfigurationVersion() {
184 return getData().getConfigVersion();
188 * Returns the isConnected {@link Property} value. Only available for event of type ControllerConnectivityChanged
190 * @return {@link Boolean} or <code>null</code>, if {@link Property} is not available or {@link Event} is not of
191 * type ControllerConnectivityChanged.
193 public Boolean getIsConnected() {
194 if (!isControllerConnectivityChangedEvent()) {
197 return getProperties().getIsConnected();