]> git.basschouten.com Git - openhab-addons.git/blob
aa0b5c3408742c9699ffea4ff702d8149f306fb9
[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.sensibo.internal.dto;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.io.IOException;
18 import java.time.ZonedDateTime;
19 import java.util.Map;
20
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.sensibo.internal.dto.poddetails.AcStateDTO;
23 import org.openhab.binding.sensibo.internal.dto.poddetails.MeasurementDTO;
24 import org.openhab.binding.sensibo.internal.dto.poddetails.ModeCapabilityDTO;
25 import org.openhab.binding.sensibo.internal.dto.poddetails.PodDetailsDTO;
26 import org.openhab.binding.sensibo.internal.dto.poddetails.TemperatureDTO;
27 import org.openhab.binding.sensibo.internal.model.SensiboSky;
28
29 /**
30  * @author Arne Seime - Initial contribution
31  */
32 public class GetPodDetailsResponseTest extends AbstractSerializationDeserializationTest {
33
34     @Test
35     public void testDeserializeWithSmartModeSetup() throws IOException {
36         final PodDetailsDTO rsp = wireHelper.deSerializeResponse("/get_pod_details_response_smartmode_settings.json",
37                 PodDetailsDTO.class);
38
39         assertEquals("34:15:13:AA:AA:AA", rsp.macAddress);
40     }
41
42     @Test
43     public void testDeserializeNullpointerExample() throws IOException {
44         final PodDetailsDTO rsp = wireHelper.deSerializeResponse("/get_pod_details_response_nullpointer.json",
45                 PodDetailsDTO.class);
46         SensiboSky internal = new SensiboSky(rsp);
47
48         assertEquals("50175457", internal.getSerialNumber());
49     }
50
51     @Test
52     public void testDeserialize() throws IOException {
53         final PodDetailsDTO rsp = wireHelper.deSerializeResponse("/get_pod_details_response.json", PodDetailsDTO.class);
54
55         assertEquals("MA:C:AD:DR:ES:S0", rsp.macAddress);
56         assertEquals("IN010056", rsp.firmwareVersion);
57         assertEquals("cc3100_stm32f0", rsp.firmwareType);
58         assertEquals("SERIALNUMASSTRING", rsp.serialNumber);
59         assertEquals("C", rsp.temperatureUnit);
60         assertEquals("skyv2", rsp.productModel);
61         assertAcState(rsp.acState);
62         assertMeasurement(rsp.lastMeasurement);
63         assertRemoteCapabilities(rsp.getRemoteCapabilities());
64     }
65
66     private void assertRemoteCapabilities(final Map<String, ModeCapabilityDTO> remoteCapabilities) {
67         assertNotNull(remoteCapabilities);
68
69         assertEquals(5, remoteCapabilities.size());
70         final ModeCapabilityDTO mode = remoteCapabilities.get("heat");
71
72         assertNotNull(mode.swingModes);
73         assertNotNull(mode.fanLevels);
74         assertNotNull(mode.temperatures);
75         final Map<String, TemperatureDTO> temperatures = mode.temperatures;
76         final TemperatureDTO temperature = temperatures.get("C");
77         assertNotNull(temperature);
78         assertNotNull(temperature.validValues);
79     }
80
81     private void assertMeasurement(final MeasurementDTO lastMeasurement) {
82         assertNotNull(lastMeasurement);
83         assertNull(lastMeasurement.batteryVoltage);
84         assertEquals(Double.valueOf("22.5"), lastMeasurement.temperature);
85         assertEquals(Double.valueOf("24.2"), lastMeasurement.humidity);
86         assertEquals(Integer.valueOf("-71"), lastMeasurement.wifiSignalStrength);
87         assertEquals(ZonedDateTime.parse("2019-05-05T07:52:11Z"), lastMeasurement.measurementTimestamp.time);
88     }
89
90     private void assertAcState(final AcStateDTO acState) {
91         assertNotNull(acState);
92
93         assertTrue(acState.on);
94         assertEquals("medium_high", acState.fanLevel);
95         assertEquals("C", acState.temperatureUnit);
96         assertEquals(21, acState.targetTemperature.intValue());
97         assertEquals("heat", acState.mode);
98         assertEquals("rangeFull", acState.swing);
99     }
100 }