]> git.basschouten.com Git - openhab-addons.git/blob
f130c03c72a551458ac5355d880571da31c23c31
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.iammeter.internal;
14
15 import java.util.List;
16
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;
22
23 import com.google.gson.JsonElement;
24 import com.google.gson.JsonObject;
25 import com.google.gson.JsonParser;
26
27 /**
28  * The {@link IammeterHandler} is responsible for handling commands, which are
29  * sent to one of the channels.
30  *
31  * @author Yang Bo - Initial contribution
32  */
33
34 @NonNullByDefault
35 public class Iammeter3080THandler extends IammeterBaseHandler {
36
37     public Iammeter3080THandler(Thing thing) {
38         super(thing);
39     }
40
41     @SuppressWarnings("null")
42     @Override
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());
54                     if (chnl != null) {
55                         State state = getQuantityState(iammeterData.get(keyWord).getAsJsonArray().get(row)
56                                 .getAsJsonArray().get(channelConfig.ordinal()).toString(), channelConfig.getUnit());
57                         updateState(chnl.getUID(), state);
58                     }
59                 }
60                 updateStatus(ThingStatus.ONLINE);
61             }
62         }
63     }
64 }