]> git.basschouten.com Git - openhab-addons.git/blob
1b01ebe61fc3f7e0219ae3876ac0d2b479d6b6c3
[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.robonect.internal.model;
14
15 /**
16  * The mower mode from the status information. Please note
17  * that EOD and JOB from {@link org.openhab.binding.robonect.internal.model.cmd.ModeCommand.Mode}
18  * are just artificial and are therfore not reported in the status information.
19  * 
20  * @author Marco Meyer - Initial contribution
21  */
22 public enum MowerMode {
23
24     /**
25      * The AUTO mode
26      */
27     AUTO(0),
28
29     /**
30      * The MANUAL mode
31      */
32     MANUAL(1),
33
34     /**
35      * The HOME mode
36      */
37     HOME(2),
38
39     /**
40      * The DEMO mode
41      */
42     DEMO(3),
43
44     /**
45      * An unknown mode. Actually this mode should never be set but is there if for some reason an unexpected value
46      * is returned from the module response.
47      */
48     UNKNOWN(99);
49
50     private int code;
51
52     MowerMode(int code) {
53         this.code = code;
54     }
55
56     /**
57      * Translate the numeric mode from the JSON response into enum values.
58      * 
59      * @param mode - the numeric value of the mode.
60      * @return - the enum value of the mode.
61      */
62     public static MowerMode fromMode(int mode) {
63         for (MowerMode mowerMode : MowerMode.values()) {
64             if (mowerMode.code == mode) {
65                 return mowerMode;
66             }
67         }
68         return UNKNOWN;
69     }
70
71     /**
72      * @return - The numeric code of the mode.
73      */
74     public int getCode() {
75         return code;
76     }
77 }