]> git.basschouten.com Git - openhab-addons.git/blob
f0830c9953fe5a9f995ee3641e8c43804d7bfcff
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.bluetooth.govee.internal;
14
15 import static org.openhab.binding.bluetooth.govee.internal.GoveeBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
20 import org.openhab.core.thing.ThingTypeUID;
21
22 /**
23  * @author Connor Petty - Initial contribution
24  *
25  */
26 @NonNullByDefault
27 public enum GoveeModel {
28     H5051(THING_TYPE_HYGROMETER, "Govee Wi-Fi Temperature Humidity Monitor", false),
29     H5052(THING_TYPE_HYGROMETER_MONITOR, "Govee Temperature Humidity Monitor", true),
30     H5071(THING_TYPE_HYGROMETER, "Govee Temperature Humidity Monitor", false),
31     H5072(THING_TYPE_HYGROMETER_MONITOR, "Govee Temperature Humidity Monitor", true),
32     H5074(THING_TYPE_HYGROMETER_MONITOR, "Govee Mini Temperature Humidity Monitor", true),
33     H5075(THING_TYPE_HYGROMETER_MONITOR, "Govee Temperature Humidity Monitor", true),
34     H5101(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
35     H5102(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
36     H5177(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
37     H5179(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
38     B5175(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
39     B5178(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true);
40
41     private final ThingTypeUID thingTypeUID;
42     private final String label;
43     private final boolean supportsWarningBroadcast;
44
45     private GoveeModel(ThingTypeUID thingTypeUID, String label, boolean supportsWarningBroadcast) {
46         this.thingTypeUID = thingTypeUID;
47         this.label = label;
48         this.supportsWarningBroadcast = supportsWarningBroadcast;
49     }
50
51     public ThingTypeUID getThingTypeUID() {
52         return thingTypeUID;
53     }
54
55     public String getLabel() {
56         return label;
57     }
58
59     public boolean supportsWarningBroadcast() {
60         return supportsWarningBroadcast;
61     }
62
63     public static @Nullable GoveeModel getGoveeModel(BluetoothDiscoveryDevice device) {
64         String name = device.getName();
65         if (name != null) {
66             if (name.startsWith("Govee") && name.length() >= 11) {
67                 String uname = name.toUpperCase();
68                 for (GoveeModel model : GoveeModel.values()) {
69                     if (uname.contains(model.name())) {
70                         return model;
71                     }
72                 }
73             }
74         }
75         return null;
76     }
77 }