]> git.basschouten.com Git - openhab-addons.git/blob
835f2091b6ade26c6214e5e2311c28c398cbdd26
[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.boschshc.internal.devices.windowcontact;
14
15 import static org.mockito.Mockito.verify;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.ThingTypeUID;
24 import org.openhab.core.types.UnDefType;
25
26 import com.google.gson.JsonElement;
27 import com.google.gson.JsonParser;
28
29 /**
30  * Unit tests for {@link WindowContact2Handler}.
31  * 
32  * @author David Pace - Initial contribution
33  *
34  */
35 @NonNullByDefault
36 class WindowContact2HandlerTest extends WindowContactHandlerTest {
37
38     @Override
39     protected WindowContactHandler createFixture() {
40         return new WindowContact2Handler(getThing());
41     }
42
43     @Override
44     protected ThingTypeUID getThingTypeUID() {
45         return BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2;
46     }
47
48     @Test
49     void testUpdateChannelsBypassService() {
50         String json = """
51                 {
52                   "@type": "bypassState",
53                   "state": "BYPASS_INACTIVE",
54                   "configuration": {
55                     "enabled": false,
56                     "timeout": 5,
57                     "infinite": false
58                   }
59                 }
60                 """;
61
62         JsonElement jsonObject = JsonParser.parseString(json);
63         getFixture().processUpdate("Bypass", jsonObject);
64         verify(getCallback()).stateUpdated(
65                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BYPASS_STATE), OnOffType.OFF);
66
67         json = """
68                 {
69                   "@type": "bypassState",
70                   "state": "BYPASS_ACTIVE",
71                   "configuration": {
72                     "enabled": false,
73                     "timeout": 5,
74                     "infinite": false
75                   }
76                 }
77                 """;
78
79         jsonObject = JsonParser.parseString(json);
80         getFixture().processUpdate("Bypass", jsonObject);
81         verify(getCallback()).stateUpdated(
82                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BYPASS_STATE), OnOffType.ON);
83
84         json = """
85                 {
86                   "@type": "bypassState",
87                   "state": "UNKNOWN",
88                   "configuration": {
89                     "enabled": false,
90                     "timeout": 5,
91                     "infinite": false
92                   }
93                 }
94                 """;
95
96         jsonObject = JsonParser.parseString(json);
97         getFixture().processUpdate("Bypass", jsonObject);
98         verify(getCallback()).stateUpdated(
99                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BYPASS_STATE), UnDefType.UNDEF);
100     }
101
102     @Test
103     void testUpdateChannelsCommunicationQualityService() {
104         String json = """
105                 {
106                     "@type": "communicationQualityState",
107                     "quality": "UNKNOWN"
108                 }
109                 """;
110         JsonElement jsonObject = JsonParser.parseString(json);
111
112         getFixture().processUpdate("CommunicationQuality", jsonObject);
113         verify(getCallback()).stateUpdated(
114                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH),
115                 new DecimalType(0));
116
117         json = """
118                 {
119                     "@type": "communicationQualityState",
120                     "quality": "GOOD"
121                 }
122                 """;
123         jsonObject = JsonParser.parseString(json);
124
125         getFixture().processUpdate("CommunicationQuality", jsonObject);
126         verify(getCallback()).stateUpdated(
127                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH),
128                 new DecimalType(4));
129     }
130 }