2 * Copyright (c) 2010-2023 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.livisismarthome.internal.client.api.entity.event;
15 import org.openhab.binding.livisismarthome.internal.client.api.entity.link.LinkDTO;
18 * Defines the {@link EventDTO}, which is sent by the LIVISI websocket to inform the clients about changes.
20 * @author Oliver Kuhl - Initial contribution
22 public class EventDTO extends BaseEventDTO {
25 * Reference to the associated entity (instance or metadata) for the given event. Always available.
27 private String source;
30 * The product (context) that generated the event.
32 private String namespace;
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.
39 private EventPropertiesDTO properties;
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.
46 private EventDataDTO data;
49 * @return the link to the source
51 public String getSource() {
56 * @param source the link to the source to set
58 public void setSource(String source) {
63 * @return the namespace
65 public String getNamespace() {
70 * @param namespace the namespace to set
72 public void setNamespace(String namespace) {
73 this.namespace = namespace;
77 * @return the properties
79 public EventPropertiesDTO getProperties() {
84 * @param properties the properties to set
86 public void setProperties(EventPropertiesDTO properties) {
87 this.properties = properties;
91 * @return the dataList
93 public EventDataDTO getData() {
98 * @param data the data to set
100 public void setData(EventDataDTO data) {
105 * Returns the id of the link or null, if there is no link or the link does not have an id.
107 * @return String the id of the link or null
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("-", "");
123 * Returns the Type of the {@link LinkDTO} in the {@link EventDTO}.
127 public String getSourceLinkType() {
128 if (source != null) {
129 return LinkDTO.getLinkType(source);
135 * Returns true, if the {@link LinkDTO} points to a
136 * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.capability.CapabilityDTO}.
138 * @return true if the link points to a capability, otherwise false
140 public Boolean isLinkedtoCapability() {
141 return source != null && LinkDTO.isTypeCapability(source);
145 * Returns true, if the {@link LinkDTO} points to a
146 * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.device.DeviceDTO}.
148 * @return true if the link points to a device, otherwise false
150 public Boolean isLinkedtoDevice() {
151 return source != null && LinkDTO.isTypeDevice(source);
155 * Returns true, if the {@link LinkDTO} points to a
156 * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.message.MessageDTO}.
158 * @return true if the link points to a message, otherwise false
160 public Boolean isLinkedtoMessage() {
161 return source != null && LinkDTO.isTypeMessage(source);
165 * Returns true, if the {@link LinkDTO} points to the SHC
166 * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.device.DeviceDTO}.
168 * @return true if the link points to a SHC bridge device, otherwise false
170 public Boolean isLinkedtoSHC() {
171 return source != null && LinkDTO.isTypeSHC(source);
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).
178 * @return true if it is a button pressed event, otherwise false
180 public boolean isButtonPressedEvent() {
181 final Integer buttonIndex = getProperties().getKeyPressButtonIndex();
182 return buttonIndex != null;
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.
189 * @return configuration version
191 public Integer getConfigurationVersion() {
192 return getData().getConfigVersion();
196 * Returns the isConnected {@link org.openhab.binding.livisismarthome.internal.client.api.entity.PropertyDTO} value.
197 * Only available for event of type ControllerConnectivityChanged
199 * @return {@link Boolean} or <code>null</code>, if not available
201 public Boolean getIsConnected() {
202 return getProperties().getIsConnected();