]> git.basschouten.com Git - openhab-addons.git/blob
9dd770b5101921c4dacb8941ba0e5572383c50a1
[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.hdpowerview.internal.dto;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * An enum for the type of power supply in a shade.
20  *
21  * @author Andrew Fiddian-Green - Initial contribution
22  */
23 @NonNullByDefault
24 public enum BatteryKind {
25     ERROR_UNKNOWN(-1),
26     HARDWIRED_POWER_SUPPLY(1),
27     BATTERY_WAND(2),
28     RECHARGEABLE_BATTERY_WAND(3);
29
30     private int batteryKind;
31
32     private BatteryKind(int i) {
33         this.batteryKind = i;
34     }
35
36     /**
37      * Determine the BatteryKind by parsing the given string value.
38      *
39      * @param value the string to parse, or null.
40      * @return the BatteryKind or ERROR_UNKNOWN in case of error.
41      */
42     public static BatteryKind fromString(@Nullable String value) {
43         if (value != null) {
44             try {
45                 int intValue = Integer.parseInt(value);
46                 for (BatteryKind e : values()) {
47                     if (e.batteryKind == intValue) {
48                         return e;
49                     }
50                 }
51             } catch (NumberFormatException e) {
52                 // fall through
53             }
54         }
55         return ERROR_UNKNOWN;
56     }
57 }