]> git.basschouten.com Git - openhab-addons.git/blob
0ccbd728fe13b998a510e154a046f219720cb1ca
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.miio.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 import com.google.gson.JsonElement;
19 import com.google.gson.JsonObject;
20
21 /**
22  * Commands to be send
23  *
24  * @author Marcel Verpaalen - Initial contribution
25  */
26 @NonNullByDefault
27 public class MiIoSendCommand {
28
29     private final int id;
30     private final MiIoCommand command;
31     private final String commandString;
32     private @Nullable JsonObject response;
33
34     public void setResponse(JsonObject response) {
35         this.response = response;
36     }
37
38     public MiIoSendCommand(int id, MiIoCommand command, String commandString) {
39         this.id = id;
40         this.command = command;
41         this.commandString = commandString;
42     }
43
44     public int getId() {
45         return id;
46     }
47
48     public MiIoCommand getCommand() {
49         return command;
50     }
51
52     public String getCommandString() {
53         return commandString;
54     }
55
56     public JsonObject getResponse() {
57         final @Nullable JsonObject response = this.response;
58         return response != null ? response : new JsonObject();
59     }
60
61     public boolean isError() {
62         final @Nullable JsonObject response = this.response;
63         if (response != null) {
64             return response.has("error");
65         }
66         return true;
67     }
68
69     public JsonElement getResult() {
70         final @Nullable JsonObject response = this.response;
71         if (response != null && response.has("result")) {
72             return response.get("result");
73         }
74         return new JsonObject();
75     }
76 }