2 * Copyright (c) 2010-2022 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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.thing.Channel;
17 import org.openhab.core.thing.Thing;
18 import org.openhab.core.types.State;
20 import com.google.gson.JsonElement;
21 import com.google.gson.JsonObject;
22 import com.google.gson.JsonParser;
25 * The {@link IammeterHandler} is responsible for handling commands, which are
26 * sent to one of the channels.
28 * @author Yang Bo - Initial contribution
32 public class IammeterHandler extends IammeterBaseHandler {
34 public IammeterHandler(Thing thing) {
39 protected void resolveData(String response) {
40 JsonElement iammeterDataElement = JsonParser.parseString(response);
41 JsonObject iammeterData = iammeterDataElement.getAsJsonObject();
42 String keyWord = "Data";
43 if (iammeterData.has("data") || (iammeterData.has("Data") && iammeterData.has("SN"))) {
44 if (iammeterData.has("data")) {
47 for (IammeterWEM3080Channel channelConfig : IammeterWEM3080Channel.values()) {
48 Channel channel = getThing().getChannel(channelConfig.getId());
49 if (channel != null) {
50 State state = getQuantityState(
51 iammeterData.get(keyWord).getAsJsonArray().get(channelConfig.ordinal()).toString(),
52 channelConfig.getUnit());
53 updateState(channel.getUID(), state);