]> git.basschouten.com Git - openhab-addons.git/blob
339c88c3c139c6ffe95202d5353e3619762dfd4a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.ecovacs.internal.api.impl.dto.response.portal;
14
15 import com.google.gson.annotations.SerializedName;
16
17 /**
18  * @author Danny Baumann - Initial contribution
19  */
20 public class AbstractPortalIotCommandResponse {
21     @SerializedName("ret")
22     private final String result;
23
24     @SerializedName("errno")
25     private final int errorCode;
26     @SerializedName("error")
27     private final String errorMessage;
28
29     // unused field: 'id' (string)
30
31     public AbstractPortalIotCommandResponse(String result, int errorCode, String errorMessage) {
32         this.result = result;
33         this.errorCode = errorCode;
34         this.errorMessage = errorMessage;
35     }
36
37     public boolean wasSuccessful() {
38         return "ok".equals(result);
39     }
40
41     public boolean failedDueToAuthProblem() {
42         return "fail".equals(result) && errorMessage != null && errorMessage.toLowerCase().contains("auth error");
43     }
44
45     public String getErrorMessage() {
46         if (wasSuccessful()) {
47             return null;
48         }
49         return "result=" + result + ", errno=" + errorCode + ", error=" + errorMessage;
50     }
51 }