]> git.basschouten.com Git - openhab-addons.git/blob
01c73d6e3c71013e1e392568c9d20b26cfca63d8
[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.govee.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.Map;
18 import java.util.Objects;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.govee.internal.model.DiscoveryResponse;
24 import org.openhab.core.config.discovery.DiscoveryResult;
25
26 import com.google.gson.Gson;
27
28 /**
29  * @author Stefan Höhn - Initial contribution
30  */
31 @NonNullByDefault
32 public class GoveeDiscoveryTest {
33
34     String response = """
35              {
36                 "msg":{
37                    "cmd":"scan",
38                    "data":{
39                       "ip":"192.168.178.171",
40                       "device":"7D:31:C3:35:33:33:44:15",
41                       "sku":"H6076",
42                       "bleVersionHard":"3.01.01",
43                       "bleVersionSoft":"1.04.04",
44                       "wifiVersionHard":"1.00.10",
45                       "wifiVersionSoft":"1.02.11"
46                    }
47                 }
48             }
49              """;
50
51     @Test
52     public void testProcessScanMessage() {
53         GoveeDiscoveryService service = new GoveeDiscoveryService(new CommunicationManager());
54         DiscoveryResponse resp = new Gson().fromJson(response, DiscoveryResponse.class);
55         Objects.requireNonNull(resp);
56         @Nullable
57         DiscoveryResult result = service.responseToResult(resp);
58         assertNotNull(result);
59         Map<String, Object> deviceProperties = result.getProperties();
60         assertEquals(deviceProperties.get(GoveeBindingConstants.DEVICE_TYPE), "H6076");
61         assertEquals(deviceProperties.get(GoveeBindingConstants.IP_ADDRESS), "192.168.178.171");
62         assertEquals(deviceProperties.get(GoveeBindingConstants.MAC_ADDRESS), "7D:31:C3:35:33:33:44:15");
63     }
64 }