2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.netatmo.internal.api.dto;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.*;
18 import java.time.ZoneId;
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;
29 * @author Gaƫl L'hopital - Initial contribution
31 public class NAObjectTest {
32 private static NADeserializer gson;
35 public static void init() {
36 TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
37 when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
38 gson = new NADeserializer(timeZoneProvider);
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");
50 public void testWebHookEvent() throws NetatmoException {
51 String event = "{" + " \"user_id\": \"5c810xxxxxxx45f4\"," + " \"snapshot_id\": \"5d19bxxxxxx6380342\","
52 + " \"snapshot_key\": \"f0134210ff83fxxxxxxxf770090a423d9a5\","
53 + " \"snapshot_url\": \"https://netatmocameraimage.blob.core.windows.net/production/5d1xxxa5\","
54 + " \"event_type\": \"movement\"," + " \"camera_id\": \"70:exxxxxdd:a7\","
55 + " \"device_id\": \"70:exxxxdd:a7\"," + " \"home_id\": \"5c5d79xxxx08cd594\","
56 + " \"home_name\": \"Boulogne Billan.\"," + " \"event_id\": \"5d19baae369359e896380341\","
57 + " \"message\": \"Boulogne Billan: Movement detected by Indoor Camera\","
58 + " \"push_type\": \"NACamera-movement\"" + "}";
59 WebhookEvent object = gson.deserialize(WebhookEvent.class, event);
60 assertEquals(object.getEventType(), EventType.MOVEMENT);
64 public void testDashboardData() throws NetatmoException {
65 String dashboard = "{time_utc:1623160336,Temperature:22.1,CO2:511,"
66 + "Humidity:66,Noise:36,Pressure:1026.1,AbsolutePressure:1009.3,"
67 + "min_temp:20,max_temp:22.4,date_max_temp:1623147932,"
68 + "Sdate_min_temp:1623125249,pressure_trend:\"nonexistent\",temp_trend:\"stable\"}";
69 Dashboard object = gson.deserialize(Dashboard.class, dashboard);
70 assertEquals(511, object.getCo2(), 0);
71 assertEquals(TrendDescription.UNKNOWN, object.getPressureTrend());
72 assertEquals(TrendDescription.STABLE, object.getTempTrend());