]> git.basschouten.com Git - openhab-addons.git/blob
4d87fd5ba62738840cd68aa5024abceb8a0e6e67
[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.deviceapi.json;
14
15 import org.openhab.binding.ecovacs.internal.api.model.CleanMode;
16
17 import com.google.gson.Gson;
18 import com.google.gson.annotations.SerializedName;
19
20 /**
21  * @author Danny Baumann - Initial contribution
22  */
23 public class CleanReportV2 {
24     @SerializedName("trigger")
25     public String trigger; // app, workComplete, ...?
26     @SerializedName("state")
27     public String state;
28     @SerializedName("cleanState")
29     public CleanStateReportV2 cleanState;
30
31     public static class CleanStateReportV2 {
32         @SerializedName("router")
33         public String router; // plan, ...?
34         @SerializedName("motionState")
35         public String motionState;
36         @SerializedName("content")
37         public CleanStateReportV2Content content;
38     }
39
40     public static class CleanStateReportV2Content {
41         @SerializedName("type")
42         public String type;
43         @SerializedName("value")
44         public String areaDefinition;
45     }
46
47     public CleanMode determineCleanMode(Gson gson) {
48         final String modeValue;
49         if ("clean".equals(state) && cleanState != null) {
50             if ("working".equals(cleanState.motionState)) {
51                 modeValue = cleanState.content.type;
52             } else {
53                 modeValue = cleanState.motionState;
54             }
55         } else {
56             modeValue = state;
57         }
58         return gson.fromJson(modeValue, CleanMode.class);
59     }
60 }