]> git.basschouten.com Git - openhab-addons.git/blob
d654d74bd2d5f64b3e82f6d66daf12a5b976c3ce
[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.netatmo.internal.api.dto;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.*;
17
18 import java.time.ZoneId;
19
20 import org.junit.jupiter.api.BeforeAll;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.netatmo.internal.api.NetatmoException;
23 import org.openhab.binding.netatmo.internal.api.data.EventType;
24 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.TrendDescription;
25 import org.openhab.binding.netatmo.internal.deserialization.NADeserializer;
26 import org.openhab.core.i18n.TimeZoneProvider;
27
28 /**
29  * @author GaĆ«l L'hopital - Initial contribution
30  */
31 public class NAObjectTest {
32     private static NADeserializer gson;
33
34     @BeforeAll
35     public static void init() {
36         TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
37         when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
38         gson = new NADeserializer(timeZoneProvider);
39     }
40
41     @Test
42     public void testNAObject() throws Exception {
43         String naObject = "{id:\"5954e7f249c75f97428b7b23\",name:\"Your House\"}";
44         NAObject object = gson.deserialize(NAObject.class, naObject);
45         assertEquals(object.getName(), "Your House");
46         assertEquals(object.getId(), "5954e7f249c75f97428b7b23");
47     }
48
49     @Test
50     public void testWebHookEvent() throws NetatmoException {
51         String event = """
52                 {\
53                   "user_id": "5c810xxxxxxx45f4",\
54                   "snapshot_id": "5d19bxxxxxx6380342",\
55                   "snapshot_key": "f0134210ff83fxxxxxxxf770090a423d9a5",\
56                   "snapshot_url": "https://netatmocameraimage.blob.core.windows.net/production/5d1xxxa5",\
57                   "event_type": "movement",\
58                   "camera_id": "70:exxxxxdd:a7",\
59                   "device_id": "70:exxxxdd:a7",\
60                   "home_id": "5c5d79xxxx08cd594",\
61                   "home_name": "Boulogne Billan.",\
62                   "event_id": "5d19baae369359e896380341",\
63                   "message": "Boulogne Billan: Movement detected by Indoor Camera",\
64                   "push_type": "NACamera-movement"\
65                 }\
66                 """;
67         WebhookEvent object = gson.deserialize(WebhookEvent.class, event);
68         assertEquals(object.getEventType(), EventType.MOVEMENT);
69     }
70
71     @Test
72     public void testDashboardData() throws NetatmoException {
73         String dashboard = """
74                 {time_utc:1623160336,Temperature:22.1,CO2:511,\
75                 Humidity:66,Noise:36,Pressure:1026.1,AbsolutePressure:1009.3,\
76                 min_temp:20,max_temp:22.4,date_max_temp:1623147932,\
77                 Sdate_min_temp:1623125249,pressure_trend:"nonexistent",temp_trend:"stable"}\
78                 """;
79         Dashboard object = gson.deserialize(Dashboard.class, dashboard);
80         assertEquals(511, object.getCo2(), 0);
81         assertEquals(TrendDescription.UNKNOWN, object.getPressureTrend());
82         assertEquals(TrendDescription.STABLE, object.getTempTrend());
83     }
84 }