2 * Copyright (c) 2010-2020 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.io.neeo.internal.models;
15 import org.apache.commons.lang.StringUtils;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.openhab.io.neeo.internal.NeeoConstants;
19 import org.openhab.io.neeo.internal.NeeoUtil;
22 * The model representing an NEEO sensor notification (serialize/deserialize json use only).
24 * @author Tim Roberts - Initial Contribution
27 public class NeeoSensorNotification {
29 /** The type of notification */
30 private final String type;
32 /** The value of the notification */
33 private final SensorNotificationData data;
36 * Instantiates a new neeo sensor notification from the key, item name and data using the default sensor update type
38 * @param deviceKey the non-null, non-empty device key
39 * @param itemName the non-null, non-empty item name
40 * @param data the possibly null, possibly empty (if a string) data
42 public NeeoSensorNotification(String deviceKey, String itemName, @Nullable Object data) {
43 this(null, deviceKey, itemName, data);
47 * Instantiates a new neeo notification from the sensor type, key, item name and data.
49 * @param overrideType the sensor notification type
50 * @param deviceKey the non-null, non-empty device key
51 * @param itemName the non-null, non-empty item name
52 * @param data the possibly null, possibly empty (if a string) data
54 public NeeoSensorNotification(@Nullable String overrideType, String deviceKey, String itemName,
55 @Nullable Object data) {
56 NeeoUtil.requireNotEmpty(deviceKey, "deviceKey cannot be empty");
57 NeeoUtil.requireNotEmpty(itemName, "itemName cannot be empty");
59 this.type = overrideType == null || StringUtils.isEmpty(overrideType)
60 ? NeeoConstants.NEEO_SENSOR_NOTIFICATION_TYPE
62 this.data = new SensorNotificationData(
63 deviceKey + ":" + itemName
64 + (StringUtils.endsWithIgnoreCase(itemName, NeeoConstants.NEEO_SENSOR_SUFFIX) ? ""
65 : NeeoConstants.NEEO_SENSOR_SUFFIX),
66 data == null || (data instanceof String && StringUtils.isEmpty(data.toString())) ? "-" : data);
70 * Gets the notification type.
72 * @return the notification type
74 public String getType() {
83 public SensorNotificationData getData() {
88 public String toString() {
89 return "NeeoNotification [type=" + type + ", data=" + data + "]";
92 class SensorNotificationData {
93 private final String sensorEventKey;
94 private final Object sensorValue;
96 public SensorNotificationData(String sensorEventKey, Object sensorValue) {
98 this.sensorEventKey = sensorEventKey;
99 this.sensorValue = sensorValue;
103 public String toString() {
104 return "SensorNotificationData [sensorEventKey=" + sensorEventKey + ", sensorValue=" + sensorValue + "]";