]> git.basschouten.com Git - openhab-addons.git/blob
ea185c5a5e5dfc6607ba7057b236a4f4f1dbe55f
[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.anthem.internal.handler;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.openhab.binding.anthem.internal.AnthemBindingConstants.*;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.core.library.types.DecimalType;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.thing.Thing;
24
25 /**
26  * The {@link AnthemCommandParserTest} is responsible for testing the functionality
27  * of the Anthem command parser.
28  *
29  * @author Mark Hilbush - Initial contribution
30  */
31 @NonNullByDefault
32 public class AnthemCommandParserTest {
33
34     AnthemCommandParser parser = new AnthemCommandParser();
35
36     @Test
37     public void testInvalidCommands() {
38         @Nullable
39         AnthemUpdate update;
40
41         update = parser.parseCommand("BOGUS_COMMAND;");
42         assertEquals(null, update);
43
44         update = parser.parseCommand("UNTERMINATED_COMMAND");
45         assertEquals(null, update);
46
47         update = parser.parseCommand("Z1POW0");
48         assertEquals(null, update);
49
50         update = parser.parseCommand("X");
51         assertEquals(null, update);
52
53         update = parser.parseCommand("Y;");
54         assertEquals(null, update);
55
56         update = parser.parseCommand("Z1POW67;");
57         assertEquals(null, update);
58
59         update = parser.parseCommand("POW0;");
60         assertEquals(null, update);
61     }
62
63     @Test
64     public void testPowerCommands() {
65         @Nullable
66         AnthemUpdate update;
67
68         update = parser.parseCommand("Z1POW1;");
69         assertNotEquals(null, update);
70         if (update != null) {
71             assertTrue(update.isStateUpdate());
72             assertFalse(update.isPropertyUpdate());
73             assertEquals("1", update.getStateUpdate().getGroupId());
74             assertEquals(CHANNEL_POWER, update.getStateUpdate().getChannelId());
75             assertEquals(OnOffType.ON, update.getStateUpdate().getState());
76         }
77
78         update = parser.parseCommand("Z2POW0;");
79         assertNotEquals(null, update);
80         if (update != null) {
81             assertEquals("2", update.getStateUpdate().getGroupId());
82             assertEquals(CHANNEL_POWER, update.getStateUpdate().getChannelId());
83             assertEquals(OnOffType.OFF, update.getStateUpdate().getState());
84         }
85     }
86
87     @Test
88     public void testVolumeCommands() {
89         @Nullable
90         AnthemUpdate update;
91
92         update = parser.parseCommand("Z1VOL55;");
93         assertNotEquals(null, update);
94         if (update != null) {
95             assertEquals("1", update.getStateUpdate().getGroupId());
96             assertEquals(CHANNEL_VOLUME_DB, update.getStateUpdate().getChannelId());
97             assertEquals(new DecimalType(55), update.getStateUpdate().getState());
98         }
99
100         update = parser.parseCommand("Z2VOL99;");
101         assertNotEquals(null, update);
102         if (update != null) {
103             assertEquals("2", update.getStateUpdate().getGroupId());
104             assertEquals(CHANNEL_VOLUME_DB, update.getStateUpdate().getChannelId());
105             assertEquals(new DecimalType(99), update.getStateUpdate().getState());
106         }
107     }
108
109     @Test
110     public void testMuteCommands() {
111         @Nullable
112         AnthemUpdate update;
113
114         update = parser.parseCommand("Z1MUT1;");
115         assertNotEquals(null, update);
116         if (update != null) {
117             assertEquals("1", update.getStateUpdate().getGroupId());
118             assertEquals(CHANNEL_MUTE, update.getStateUpdate().getChannelId());
119             assertEquals(OnOffType.ON, update.getStateUpdate().getState());
120         }
121
122         update = parser.parseCommand("Z2MUT0;");
123         assertNotEquals(null, update);
124         if (update != null) {
125             assertTrue(update.isStateUpdate());
126             assertEquals("2", update.getStateUpdate().getGroupId());
127             assertEquals(CHANNEL_MUTE, update.getStateUpdate().getChannelId());
128             assertEquals(OnOffType.OFF, update.getStateUpdate().getState());
129         }
130     }
131
132     @Test
133     public void testNumInputsCommand() {
134         @Nullable
135         AnthemUpdate update;
136
137         update = parser.parseCommand("ICN8;");
138         assertNotEquals(null, update);
139         if (update != null) {
140             assertTrue(update.isPropertyUpdate());
141             assertEquals(PROPERTY_NUM_AVAILABLE_INPUTS, update.getPropertyUpdate().getName());
142             assertEquals("8", update.getPropertyUpdate().getValue());
143         }
144
145         update = parser.parseCommand("ICN15;");
146         assertNotEquals(null, update);
147         if (update != null) {
148             assertTrue(update.isPropertyUpdate());
149             assertEquals(PROPERTY_NUM_AVAILABLE_INPUTS, update.getPropertyUpdate().getName());
150             assertEquals("15", update.getPropertyUpdate().getValue());
151         }
152     }
153
154     @Test
155     public void testRegionProperty() {
156         @Nullable
157         AnthemUpdate update;
158
159         update = parser.parseCommand("IDRUS;");
160         assertNotEquals(null, update);
161         if (update != null) {
162             assertTrue(update.isPropertyUpdate());
163             assertFalse(update.isStateUpdate());
164             assertEquals(PROPERTY_REGION, update.getPropertyUpdate().getName());
165             assertEquals("US", update.getPropertyUpdate().getValue());
166         }
167     }
168
169     @Test
170     public void testSoftwareVersionProperty() {
171         @Nullable
172         AnthemUpdate update;
173
174         update = parser.parseCommand("IDS1.2.3.4;");
175         assertNotEquals(null, update);
176         if (update != null) {
177             assertTrue(update.isPropertyUpdate());
178             assertEquals(Thing.PROPERTY_FIRMWARE_VERSION, update.getPropertyUpdate().getName());
179             assertEquals("1.2.3.4", update.getPropertyUpdate().getValue());
180         }
181     }
182 }