2 * Copyright (c) 2010-2020 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
14 package org.openhab.binding.touchwand.internal.dto;
16 import static org.openhab.binding.touchwand.internal.TouchWandBindingConstants.*;
18 import java.util.Arrays;
20 import com.google.gson.Gson;
21 import com.google.gson.JsonObject;
22 import com.google.gson.JsonParser;
25 * The {@link TouchWandUnitFromJson} parse Json unit data
27 * @author Roie Geron - Initial contribution
29 public class TouchWandUnitFromJson {
31 public TouchWandUnitFromJson() {
34 public static TouchWandUnitData parseResponse(JsonObject jsonUnit) {
35 final Gson gson = new Gson();
36 TouchWandUnitData touchWandUnit;
37 String type = jsonUnit.get("type").getAsString();
38 if (!Arrays.asList(SUPPORTED_TOUCHWAND_TYPES).contains(type)) {
42 if (!jsonUnit.has("currStatus") || (jsonUnit.get("currStatus") == null)) {
47 case TYPE_WALLCONTROLLER:
48 touchWandUnit = gson.fromJson(jsonUnit, TouchWandUnitDataWallController.class);
51 touchWandUnit = gson.fromJson(jsonUnit, TouchWandShutterSwitchUnitData.class);
54 touchWandUnit = gson.fromJson(jsonUnit, TouchWandShutterSwitchUnitData.class);
57 touchWandUnit = gson.fromJson(jsonUnit, TouchWandShutterSwitchUnitData.class);
66 public static TouchWandUnitData parseResponse(String JsonUnit) {
67 final JsonParser jsonParser = new JsonParser();
68 JsonObject unitObj = jsonParser.parse(JsonUnit).getAsJsonObject();
69 return parseResponse(unitObj);