]> git.basschouten.com Git - openhab-addons.git/blob
206ef4944f0d526d8714a314bc5fcf87ff4d85cc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * @author Connor Petty - Initial contribution
26  *
27  */
28 @NonNullByDefault
29 public enum GoveeModel {
30     H5051(THING_TYPE_HYGROMETER, "Govee Wi-Fi Temperature Humidity Monitor", false),
31     H5052(THING_TYPE_HYGROMETER_MONITOR, "Govee Temperature Humidity Monitor", true),
32     H5071(THING_TYPE_HYGROMETER, "Govee Temperature Humidity Monitor", false),
33     H5072(THING_TYPE_HYGROMETER_MONITOR, "Govee Temperature Humidity Monitor", true),
34     H5074(THING_TYPE_HYGROMETER_MONITOR, "Govee Mini Temperature Humidity Monitor", true),
35     H5075(THING_TYPE_HYGROMETER_MONITOR, "Govee Temperature Humidity Monitor", true),
36     H5101(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
37     H5102(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
38     H5177(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
39     H5179(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
40     B5175(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true),
41     B5178(THING_TYPE_HYGROMETER_MONITOR, "Govee Smart Thermo-Hygrometer", true);
42
43     private final ThingTypeUID thingTypeUID;
44     private final String label;
45     private final boolean supportsWarningBroadcast;
46
47     private static final Logger logger = LoggerFactory.getLogger(GoveeModel.class);
48
49     private GoveeModel(ThingTypeUID thingTypeUID, String label, boolean supportsWarningBroadcast) {
50         this.thingTypeUID = thingTypeUID;
51         this.label = label;
52         this.supportsWarningBroadcast = supportsWarningBroadcast;
53     }
54
55     public ThingTypeUID getThingTypeUID() {
56         return thingTypeUID;
57     }
58
59     public String getLabel() {
60         return label;
61     }
62
63     public boolean supportsWarningBroadcast() {
64         return supportsWarningBroadcast;
65     }
66
67     public static @Nullable GoveeModel getGoveeModel(BluetoothDiscoveryDevice device) {
68         String name = device.getName();
69         if (name != null) {
70             if ((name.startsWith("Govee") && name.length() >= 11) || name.startsWith("GVH")) {
71                 String uname = name.toUpperCase();
72                 for (GoveeModel model : GoveeModel.values()) {
73                     if (uname.contains(model.name())) {
74                         logger.debug("detected model {}", model);
75                         return model;
76                     }
77                 }
78             }
79         }
80         logger.debug("Device {} is no Govee", name);
81         return null;
82     }
83 }