]> git.basschouten.com Git - openhab-addons.git/blob
9dcd2fc9db432596a7c16b5cd710a9185eb71c36
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.nibeuplink.internal.model;
14
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import com.google.gson.annotations.SerializedName;
26
27 /**
28  * data class to map the json status response
29  *
30  * @author Alexander Friese - initial contribution
31  */
32 @NonNullByDefault
33 public class GenericDataResponse implements DataResponse {
34     private final Logger logger = LoggerFactory.getLogger(GenericDataResponse.class);
35
36     public static class Value {
37         @SerializedName("VariableId")
38         private @Nullable String variableId;
39         @SerializedName("CurrentValue")
40         private @Nullable String currentValue;
41         @SerializedName("CurrentIntValue")
42         private @Nullable Long currentIntValue;
43         @SerializedName("IsLoading")
44         private boolean isLoading;
45     }
46
47     @SerializedName("IsOffline")
48     private @Nullable String isOffline;
49     @SerializedName("OnlineImage")
50     private @Nullable String onlineImage;
51     @SerializedName("Date")
52     private @Nullable String date;
53     @SerializedName("FuzzyDate")
54     private @Nullable String fuzzyDate;
55     @SerializedName("Values")
56     private List<Value> values = new ArrayList<>();
57
58     @Override
59     public Map<String, @Nullable Long> getValues() {
60         Map<String, @Nullable Long> valueMap = new HashMap<>();
61         for (Value value : values) {
62             String id = value.variableId;
63             if (!value.isLoading && id != null) {
64                 if (logger.isDebugEnabled()) {
65                     logger.debug("Channel {} updated to: {} ({})", value.variableId, value.currentIntValue,
66                             value.currentValue);
67                 }
68                 valueMap.put(id, value.currentIntValue);
69             }
70         }
71         return valueMap;
72     }
73
74     public @Nullable String getIsOffline() {
75         return isOffline;
76     }
77
78     public @Nullable String getOnlineImage() {
79         return onlineImage;
80     }
81
82     public @Nullable String getDate() {
83         return date;
84     }
85
86     public @Nullable String getFuzzyDate() {
87         return fuzzyDate;
88     }
89 }