2 * Copyright (c) 2010-2024 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.boschshc.internal.devices.intrusion;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.verify;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.TimeoutException;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.junit.jupiter.api.Test;
24 import org.mockito.ArgumentCaptor;
25 import org.mockito.Captor;
26 import org.openhab.binding.boschshc.internal.devices.AbstractBoschSHCHandlerTest;
27 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
28 import org.openhab.binding.boschshc.internal.services.intrusion.actions.arm.dto.ArmActionRequest;
29 import org.openhab.core.library.types.OnOffType;
30 import org.openhab.core.library.types.StringType;
31 import org.openhab.core.thing.ChannelUID;
32 import org.openhab.core.thing.ThingTypeUID;
34 import com.google.gson.JsonElement;
35 import com.google.gson.JsonParser;
38 * Unit test for {@link IntrusionDetectionHandler}.
40 * @author David Pace - Initial contribution
44 class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<IntrusionDetectionHandler> {
46 private @Captor @NonNullByDefault({}) ArgumentCaptor<ArmActionRequest> armActionRequestCaptor;
49 protected IntrusionDetectionHandler createFixture() {
50 return new IntrusionDetectionHandler(getThing());
54 protected ThingTypeUID getThingTypeUID() {
55 return BoschSHCBindingConstants.THING_TYPE_INTRUSION_DETECTION_SYSTEM;
59 void testHandleCommandArmAction() throws InterruptedException, TimeoutException, ExecutionException {
60 getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ARM_ACTION),
62 verify(getBridgeHandler()).postAction(eq("intrusion/actions/arm"), armActionRequestCaptor.capture());
63 ArmActionRequest armRequest = armActionRequestCaptor.getValue();
64 assertEquals("0", armRequest.profileId);
68 void testHandleCommandDisarmAction() throws InterruptedException, TimeoutException, ExecutionException {
69 getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_DISARM_ACTION),
71 verify(getBridgeHandler()).postAction("intrusion/actions/disarm");
75 void testHandleCommandMuteAction() throws InterruptedException, TimeoutException, ExecutionException {
76 getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_MUTE_ACTION),
78 verify(getBridgeHandler()).postAction("intrusion/actions/mute");
82 void testUpdateChannelsIntrusionDetectionSystemState() {
83 JsonElement jsonObject = JsonParser.parseString("""
85 "@type": "systemState",
86 "systemAvailability": {
87 "@type": "systemAvailabilityState",
92 "@type": "armingState",
93 "state": "SYSTEM_DISARMED",
97 "@type": "alarmState",
102 "activeConfigurationProfile": {
103 "@type": "activeConfigurationProfile",
106 "securityGapState": {
107 "@type": "securityGapState",
114 getFixture().processUpdate(BoschSHCBindingConstants.SERVICE_INTRUSION_DETECTION, jsonObject);
115 verify(getCallback()).stateUpdated(
116 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SYSTEM_AVAILABILITY),
118 verify(getCallback()).stateUpdated(
119 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ARMING_STATE),
120 new StringType("SYSTEM_DISARMED"));
121 verify(getCallback()).stateUpdated(
122 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ALARM_STATE),
123 new StringType("ALARM_OFF"));
124 verify(getCallback()).stateUpdated(
125 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ACTIVE_CONFIGURATION_PROFILE),
126 new StringType(null));
130 void testUpdateChannelsIntrusionDetectionControlState() {
131 JsonElement jsonObject = JsonParser.parseString("""
133 "@type": "intrusionDetectionControlState",
134 "activeProfile": "0",
135 "alarmActivationDelayTime": 30,
140 "id": "intrusion:video"
145 "id": "intrusion:siren"
148 "remainingTimeUntilArmed": 29559,
149 "armActivationDelayTime": 30,
154 "id": "hdm:ZigBee:000d6f0012f02378"
157 "value": "SYSTEM_ARMING"
160 getFixture().processUpdate("IntrusionDetectionControl", jsonObject);
161 verify(getCallback()).stateUpdated(
162 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ARMING_STATE),
163 new StringType("SYSTEM_ARMING"));
164 verify(getCallback()).stateUpdated(
165 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ACTIVE_CONFIGURATION_PROFILE),
166 new StringType("0"));
170 void testUpdateChannelsSurveillanceAlarmState() {
171 JsonElement jsonObject = JsonParser.parseString("""
173 "@type": "surveillanceAlarmState",
176 "triggerName": "Motion Detector",
177 "locationId": "hz_5",
178 "location": "Living Room",
179 "id": "hdm:ZigBee:000d6f0012f02342",
180 "time": 1652615755336,
187 getFixture().processUpdate("SurveillanceAlarm", jsonObject);
188 verify(getCallback()).stateUpdated(
189 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ALARM_STATE),
190 new StringType("ALARM_ON"));