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.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 final String sender;
34 private @Nullable JsonObject response;
35 private String cloudServer = "";
37 public void setResponse(JsonObject response) {
38 this.response = response;
41 public MiIoSendCommand(int id, MiIoCommand command, JsonObject fullCommand, String sender) {
43 this.command = command;
44 this.commandJson = fullCommand;
48 public MiIoSendCommand(int id, MiIoCommand command, JsonObject fullCommand, String cloudServer, String sender) {
50 this.command = command;
51 this.commandJson = fullCommand;
52 this.cloudServer = cloudServer;
60 public MiIoCommand getCommand() {
64 public JsonObject getCommandJson() {
68 public String getCommandString() {
69 return commandJson.toString();
72 public String getMethod() {
73 return commandJson.has("method") ? commandJson.get("method").getAsString() : "";
76 public JsonElement getParams() {
77 return commandJson.has("params") ? commandJson.get("params") : new JsonArray();
80 public JsonObject getResponse() {
81 final @Nullable JsonObject response = this.response;
82 return response != null ? response : new JsonObject();
85 public boolean isError() {
86 final @Nullable JsonObject response = this.response;
87 if (response != null) {
88 return response.has("error");
93 public JsonElement getResult() {
94 final @Nullable JsonObject response = this.response;
95 if (response != null && response.has("result")) {
96 return response.get("result");
98 return new JsonObject();
101 public String getCloudServer() {
105 public void setCloudServer(String cloudServer) {
106 this.cloudServer = cloudServer;
109 public String getSender() {