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.io.neeo.internal.models;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.io.neeo.internal.NeeoConstants;
18 import org.openhab.io.neeo.internal.NeeoUtil;
21 * The model representing a NEEO sensor notification (serialize/deserialize json use only).
23 * @author Tim Roberts - Initial Contribution
26 public class NeeoSensorNotification {
28 /** The type of notification */
29 private final String type;
31 /** The value of the notification */
32 private final SensorNotificationData data;
35 * Instantiates a new neeo sensor notification from the key, item name and data using the default sensor update type
37 * @param deviceKey the non-null, non-empty device key
38 * @param itemName the non-null, non-empty item name
39 * @param data the possibly null, possibly empty (if a string) data
41 public NeeoSensorNotification(String deviceKey, String itemName, @Nullable Object data) {
42 this(null, deviceKey, itemName, data);
46 * Instantiates a new neeo notification from the sensor type, key, item name and data.
48 * @param overrideType the sensor notification type
49 * @param deviceKey the non-null, non-empty device key
50 * @param itemName the non-null, non-empty item name
51 * @param data the possibly null, possibly empty (if a string) data
53 public NeeoSensorNotification(@Nullable String overrideType, String deviceKey, String itemName,
54 @Nullable Object data) {
55 NeeoUtil.requireNotEmpty(deviceKey, "deviceKey cannot be empty");
56 NeeoUtil.requireNotEmpty(itemName, "itemName cannot be empty");
58 this.type = overrideType == null || overrideType.isEmpty() ? NeeoConstants.NEEO_SENSOR_NOTIFICATION_TYPE
60 this.data = new SensorNotificationData(
61 deviceKey + ":" + itemName
62 + (itemName.toLowerCase().endsWith(NeeoConstants.NEEO_SENSOR_SUFFIX.toLowerCase()) ? ""
63 : NeeoConstants.NEEO_SENSOR_SUFFIX),
64 data == null || (data instanceof String && data.toString().isEmpty()) ? "-" : data);
68 * Gets the notification type.
70 * @return the notification type
72 public String getType() {
81 public SensorNotificationData getData() {
86 public String toString() {
87 return "NeeoNotification [type=" + type + ", data=" + data + "]";
90 class SensorNotificationData {
91 private final String sensorEventKey;
92 private final Object sensorValue;
94 public SensorNotificationData(String sensorEventKey, Object sensorValue) {
96 this.sensorEventKey = sensorEventKey;
97 this.sensorValue = sensorValue;
101 public String toString() {
102 return "SensorNotificationData [sensorEventKey=" + sensorEventKey + ", sensorValue=" + sensorValue + "]";