]> git.basschouten.com Git - openhab-addons.git/blob
b38ab82d609afadea14164cf95a7576d4697dcd3
[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 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * An enumeration for the possible mower status.
20  *
21  * @author Marco Meyer - Initial contribution
22  */
23 public enum MowerStatus {
24
25     /**
26      * Status is being detected.
27      */
28     DETECTING_STATUS(0),
29     /**
30      * Mower is in charging station.
31      */
32     PARKING(1),
33
34     /**
35      * Mower is mowing.
36      */
37     MOWING(2),
38
39     /**
40      * Mower searches charging station
41      */
42     SEARCH_CHARGING_STATION(3),
43
44     /**
45      * Mower is charging.
46      */
47     CHARGING(4),
48
49     /**
50      * Mower is searching the remote start point.
51      */
52     SEARCHING(5),
53
54     /**
55      * Mower is in error state.
56      */
57     ERROR_STATUS(7),
58
59     /**
60      * Mower lost WLAN signal.
61      */
62     LOST_SIGNAL(8),
63
64     /**
65      * Mower is OFF.
66      */
67     OFF(16),
68
69     /**
70      * Mower is sleeping
71      */
72     SLEEPING(17),
73
74     /**
75      * Mower waits for door to open
76      */
77     DOORDELAY(18),
78
79     /**
80      * unknown status. If the module return any not listed code here it will result in this state in the binding.
81      */
82     UNKNOWN(99);
83
84     private static final Logger LOGGER = LoggerFactory.getLogger(MowerStatus.class);
85
86     private int statusCode;
87
88     MowerStatus(int statusCode) {
89         this.statusCode = statusCode;
90     }
91
92     /**
93      * translates a numeric code into an enum value. If code is not known the value {@link #UNKNOWN} is returned.
94      * 
95      * @param code - the code to translate
96      * @return - the correpsonding enum value.
97      */
98     public static MowerStatus fromCode(int code) {
99         for (MowerStatus status : MowerStatus.values()) {
100             if (status.statusCode == code) {
101                 return status;
102             }
103         }
104         LOGGER.debug("Got an unknown state with code {}", code);
105         return UNKNOWN;
106     }
107
108     /**
109      * returns the numeric code of the status.
110      * 
111      * @return
112      */
113     public int getStatusCode() {
114         return statusCode;
115     }
116 }