forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Iammeter3080THandler.java
64 lines (57 loc) · 2.3 KB
/
Iammeter3080THandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.iammeter.internal;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.thing.Channel;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.types.State;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
* The {@link IammeterHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Yang Bo - Initial contribution
*/
@NonNullByDefault
public class Iammeter3080THandler extends IammeterBaseHandler {
public Iammeter3080THandler(Thing thing) {
super(thing);
}
@SuppressWarnings("null")
@Override
protected void resolveData(String response) {
JsonElement iammeterDataElement = new JsonParser().parse(response);
JsonObject iammeterData = iammeterDataElement.getAsJsonObject();
String keyWord = "Datas";
if (iammeterData.has("Datas") && iammeterData.has("SN")) {
String groups[] = { "powerPhaseA", "powerPhaseB", "powerPhaseC" };
for (int row = 0; row < groups.length; row++) {
String gpName = groups[row];
List<Channel> chnList = getThing().getChannelsOfGroup(gpName);
for (IammeterWEM3080Channel channelConfig : IammeterWEM3080Channel.values()) {
Channel chnl = chnList.get(channelConfig.ordinal());
if (chnl != null) {
State state = getQuantityState(iammeterData.get(keyWord).getAsJsonArray().get(row)
.getAsJsonArray().get(channelConfig.ordinal()).toString(), channelConfig.getUnit());
updateState(chnl.getUID(), state);
}
}
updateStatus(ThingStatus.ONLINE);
}
}
}
}