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.binding.iammeter.internal;
15 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.thing.Channel;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.thing.ThingStatus;
21 import org.openhab.core.types.State;
23 import com.google.gson.JsonElement;
24 import com.google.gson.JsonObject;
25 import com.google.gson.JsonParser;
28 * The {@link IammeterHandler} is responsible for handling commands, which are
29 * sent to one of the channels.
31 * @author Yang Bo - Initial contribution
35 public class Iammeter3080THandler extends IammeterBaseHandler {
37 public Iammeter3080THandler(Thing thing) {
41 @SuppressWarnings("null")
43 protected void resolveData(String response) {
44 JsonElement iammeterDataElement = JsonParser.parseString(response);
45 JsonObject iammeterData = iammeterDataElement.getAsJsonObject();
46 String keyWord = "Datas";
47 if (iammeterData.has("Datas") && iammeterData.has("SN")) {
48 String groups[] = { "powerPhaseA", "powerPhaseB", "powerPhaseC" };
49 for (int row = 0; row < groups.length; row++) {
50 String gpName = groups[row];
51 List<Channel> chnList = getThing().getChannelsOfGroup(gpName);
52 for (IammeterWEM3080Channel channelConfig : IammeterWEM3080Channel.values()) {
53 Channel chnl = chnList.get(channelConfig.ordinal());
55 State state = getQuantityState(iammeterData.get(keyWord).getAsJsonArray().get(row)
56 .getAsJsonArray().get(channelConfig.ordinal()).toString(), channelConfig.getUnit());
57 updateState(chnl.getUID(), state);
60 updateStatus(ThingStatus.ONLINE);