2 * Copyright (c) 2010-2021 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.miio.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
18 import com.google.gson.JsonArray;
19 import com.google.gson.JsonElement;
20 import com.google.gson.JsonObject;
25 * @author Marcel Verpaalen - Initial contribution
28 public class MiIoSendCommand {
31 private final MiIoCommand command;
32 private final JsonObject commandJson;
33 private @Nullable JsonObject response;
34 private String cloudServer = "";
36 public void setResponse(JsonObject response) {
37 this.response = response;
40 public MiIoSendCommand(int id, MiIoCommand command, JsonObject fullCommand) {
42 this.command = command;
43 this.commandJson = fullCommand;
46 public MiIoSendCommand(int id, MiIoCommand command, JsonObject fullCommand, String cloudServer) {
48 this.command = command;
49 this.commandJson = fullCommand;
50 this.cloudServer = cloudServer;
57 public MiIoCommand getCommand() {
61 public JsonObject getCommandJson() {
65 public String getCommandString() {
66 return commandJson.toString();
69 public String getMethod() {
70 return commandJson.has("method") ? commandJson.get("method").getAsString() : "";
73 public JsonElement getParams() {
74 return commandJson.has("params") ? commandJson.get("params").getAsJsonArray() : new JsonArray();
77 public JsonObject getResponse() {
78 final @Nullable JsonObject response = this.response;
79 return response != null ? response : new JsonObject();
82 public boolean isError() {
83 final @Nullable JsonObject response = this.response;
84 if (response != null) {
85 return response.has("error");
90 public JsonElement getResult() {
91 final @Nullable JsonObject response = this.response;
92 if (response != null && response.has("result")) {
93 return response.get("result");
95 return new JsonObject();
98 public String getCloudServer() {
102 public void setCloudServer(String cloudServer) {
103 this.cloudServer = cloudServer;