]> git.basschouten.com Git - openhab-addons.git/blob
728f914c1597eb837e2e5475ec85871ae3b5451d
[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.loxone.internal.controls;
14
15 import org.junit.jupiter.api.BeforeEach;
16 import org.junit.jupiter.api.Test;
17 import org.openhab.core.library.types.DecimalType;
18 import org.openhab.core.library.types.OnOffType;
19
20 /**
21  * Test class for (@link LxControlMeter}
22  *
23  * @author Pawel Pieczul - initial contribution
24  *
25  */
26 public class LxControlMeterTest extends LxControlTest {
27     private static final String ACTUAL_VALUE_CHANNEL = " / Current";
28     private static final String TOTAL_VALUE_CHANNEL = " / Total";
29     private static final String RESET_CHANNEL = " / Reset";
30
31     @BeforeEach
32     public void setup() {
33         setupControl("13b3ea27-00fc-6f1b-ffff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
34                 "0fe650c2-0004-d446-ffff504f9410790f", "Energy Meter");
35     }
36
37     @Test
38     public void testControlCreation() {
39         testControlCreation(LxControlMeter.class, 1, 0, 3, 3, 2);
40     }
41
42     @Test
43     public void testChannels() {
44         testChannel("Number", ACTUAL_VALUE_CHANNEL, null, null, null, "%.3fkW", true, null);
45         testChannel("Number", TOTAL_VALUE_CHANNEL, null, null, null, "%.1fkWh", true, null);
46         testChannel("Switch", RESET_CHANNEL);
47     }
48
49     @Test
50     public void testLoxoneStateChanges() {
51         for (Double i = 0.0; i < 50.0; i += 0.25) {
52             changeLoxoneState("actual", i);
53             changeLoxoneState("total", i * 2.0);
54             testChannelState(ACTUAL_VALUE_CHANNEL, new DecimalType(i));
55             testChannelState(TOTAL_VALUE_CHANNEL, new DecimalType(i * 2.0));
56             testChannelState(RESET_CHANNEL, OnOffType.OFF);
57         }
58     }
59
60     @Test
61     public void testCommands() {
62         testAction(null);
63         for (int i = 0; i < 100; i++) {
64             executeCommand(RESET_CHANNEL, OnOffType.ON);
65             testAction("reset");
66             testChannelState(RESET_CHANNEL, OnOffType.OFF);
67         }
68     }
69 }