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.senechome.internal;
15 import java.math.BigDecimal;
16 import java.math.RoundingMode;
18 import org.eclipse.jetty.client.HttpClient;
19 import org.junit.jupiter.api.Assertions;
20 import org.junit.jupiter.api.extension.ExtendWith;
21 import org.junit.jupiter.params.ParameterizedTest;
22 import org.junit.jupiter.params.provider.MethodSource;
23 import org.mockito.Mock;
24 import org.mockito.junit.jupiter.MockitoExtension;
25 import org.openhab.core.thing.Thing;
28 * Test for senec value parsing. All test data are from "original" senec (using vars.html).
30 * @author Erwin Guib - Initial Contribution
32 @ExtendWith(MockitoExtension.class)
33 class SenecHomeHandlerTest {
35 protected static Object[][] data() {
36 return new Object[][] {
38 { "u1_0002", BigDecimal.valueOf(2) }, //
39 { "u1_07DB", BigDecimal.valueOf(2011) }, //
40 { "u3_0000194C", BigDecimal.valueOf(6476) }, //
41 { "u3_817E00E0", BigDecimal.valueOf(2172518624L) }, //
42 { "u6_0000000000000001", BigDecimal.valueOf(1) }, //
43 { "u6_00000000000C75D9", BigDecimal.valueOf(816601) }, //
44 { "u8_64", BigDecimal.valueOf(100) }, //
46 { "i1_00FA", BigDecimal.valueOf(250) }, //
47 { "i3_00000078", BigDecimal.valueOf(120) }, //
48 { "i3_609F8480", BigDecimal.valueOf(1621066880) }, //
49 { "i3_FFFFFFFF", BigDecimal.valueOf(-1) }, //
50 { "i8_18", BigDecimal.valueOf(24) }, //
52 { "st_HMI: 3.15.32 PU: 4.1.89", BigDecimal.valueOf(0) } };
55 protected static Object[][] floatData() {
56 return new Object[][] {
58 { "fl_41C80000", BigDecimal.valueOf(25), 0 }, //
59 { "fl_4247632F", BigDecimal.valueOf(49.85), 2 }, //
60 { "fl_C5AB6F0B", BigDecimal.valueOf(-5485.88), 2 }, //
61 { "fl_4248CCCD", BigDecimal.valueOf(50.2), 1 }, //
69 HttpClient mockHttpClient;
71 SenecHomeHandler cut = new SenecHomeHandler(mockThing, mockHttpClient);
75 void getSenecValue(String value, Object expectedResult) {
76 Assertions.assertEquals(expectedResult, cut.getSenecValue(value));
80 @MethodSource("floatData")
81 void getSenecValueFloat(String value, Object expectedResult, int scale) {
82 Assertions.assertEquals(expectedResult, cut.getSenecValue(value).setScale(scale, RoundingMode.HALF_UP));