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.govee.internal;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.govee.internal.model.Color;
20 import org.openhab.binding.govee.internal.model.ColorData;
21 import org.openhab.binding.govee.internal.model.EmptyValueQueryStatusData;
22 import org.openhab.binding.govee.internal.model.GenericGoveeMsg;
23 import org.openhab.binding.govee.internal.model.GenericGoveeRequest;
24 import org.openhab.binding.govee.internal.model.ValueIntData;
26 import com.google.gson.Gson;
29 * @author Stefan Höhn - Initial contribution
32 public class GoveeSerializeTest {
34 private static final Gson GSON = new Gson();
35 private final String lightOffJsonString = "{\"msg\":{\"cmd\":\"turn\",\"data\":{\"value\":0}}}";
36 private final String lightOnJsonString = "{\"msg\":{\"cmd\":\"brightness\",\"data\":{\"value\":100}}}";
37 private final String lightColorJsonString = "{\"msg\":{\"cmd\":\"colorwc\",\"data\":{\"color\":{\"r\":0,\"g\":1,\"b\":2},\"colorTemInKelvin\":3}}}";
38 private final String lightBrightnessJsonString = "{\"msg\":{\"cmd\":\"brightness\",\"data\":{\"value\":99}}}";
39 private final String lightQueryJsonString = "{\"msg\":{\"cmd\":\"devStatus\",\"data\":{}}}";
42 public void testSerializeMessage() {
43 GenericGoveeRequest lightOff = new GenericGoveeRequest(new GenericGoveeMsg("turn", new ValueIntData(0)));
44 assertEquals(lightOffJsonString, GSON.toJson(lightOff));
45 GenericGoveeRequest lightOn = new GenericGoveeRequest(new GenericGoveeMsg("brightness", new ValueIntData(100)));
46 assertEquals(lightOnJsonString, GSON.toJson(lightOn));
47 GenericGoveeRequest lightColor = new GenericGoveeRequest(
48 new GenericGoveeMsg("colorwc", new ColorData(new Color(0, 1, 2), 3)));
49 assertEquals(lightColorJsonString, GSON.toJson(lightColor));
50 GenericGoveeRequest lightBrightness = new GenericGoveeRequest(
51 new GenericGoveeMsg("brightness", new ValueIntData(99)));
52 assertEquals(lightBrightnessJsonString, GSON.toJson(lightBrightness));
53 GenericGoveeRequest lightQuery = new GenericGoveeRequest(
54 new GenericGoveeMsg("devStatus", new EmptyValueQueryStatusData()));
55 assertEquals(lightQueryJsonString, GSON.toJson(lightQuery));