]> git.basschouten.com Git - openhab-addons.git/blob
5776cc1765aa6acb1423484c0ab3d9c1e004b4e9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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     @NonNullByDefault
37     public static class Value {
38         @SerializedName("VariableId")
39         private @Nullable String variableId;
40         @SerializedName("CurrentValue")
41         private @Nullable String currentValue;
42         @SerializedName("CurrentIntValue")
43         private @Nullable Long currentIntValue;
44         @SerializedName("IsLoading")
45         private boolean isLoading;
46     }
47
48     @SerializedName("IsOffline")
49     private @Nullable String isOffline;
50     @SerializedName("OnlineImage")
51     private @Nullable String onlineImage;
52     @SerializedName("Date")
53     private @Nullable String date;
54     @SerializedName("FuzzyDate")
55     private @Nullable String fuzzyDate;
56     @SerializedName("Values")
57     private List<Value> values = new ArrayList<>();
58
59     @Override
60     public Map<String, @Nullable Long> getValues() {
61         Map<String, @Nullable Long> valueMap = new HashMap<>();
62         for (Value value : values) {
63             String id = value.variableId;
64             if (!value.isLoading && id != null) {
65                 if (logger.isDebugEnabled()) {
66                     logger.debug("Channel {} updated to: {} ({})", value.variableId, value.currentIntValue,
67                             value.currentValue);
68                 }
69                 valueMap.put(id, value.currentIntValue);
70             }
71         }
72         return valueMap;
73     }
74
75     public @Nullable String getIsOffline() {
76         return isOffline;
77     }
78
79     public @Nullable String getOnlineImage() {
80         return onlineImage;
81     }
82
83     public @Nullable String getDate() {
84         return date;
85     }
86
87     public @Nullable String getFuzzyDate() {
88         return fuzzyDate;
89     }
90 }