]> git.basschouten.com Git - openhab-addons.git/blob
05d9f279ded8b88815351956c3148003c6322aa7
[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.motiondetector;
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.AbstractBatteryPoweredDeviceHandlerTest;
20 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
21 import org.openhab.core.library.types.DateTimeType;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.ThingTypeUID;
25
26 import com.google.gson.JsonElement;
27 import com.google.gson.JsonParser;
28
29 /**
30  * Unit Tests for {@link MotionDetectorHandler}.
31  *
32  * @author David Pace - Initial contribution
33  *
34  */
35 @NonNullByDefault
36 class MotionDetectorHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<MotionDetectorHandler> {
37
38     @Override
39     protected MotionDetectorHandler createFixture() {
40         return new MotionDetectorHandler(getThing());
41     }
42
43     @Override
44     protected String getDeviceID() {
45         return "hdm:ZigBee:000d6f0012fd2571";
46     }
47
48     @Override
49     protected ThingTypeUID getThingTypeUID() {
50         return BoschSHCBindingConstants.THING_TYPE_MOTION_DETECTOR;
51     }
52
53     @Test
54     void testUpdateChannelsLatestMotionService() {
55         JsonElement jsonObject = JsonParser.parseString("""
56                 {
57                    "@type": "latestMotionState",
58                    "latestMotionDetected": "2020-04-03T19:02:19.054Z"
59                  }\
60                 """);
61         getFixture().processUpdate("LatestMotion", jsonObject);
62         verify(getCallback()).stateUpdated(
63                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_LATEST_MOTION),
64                 new DateTimeType("2020-04-03T19:02:19.054Z"));
65     }
66
67     @Test
68     void testUpdateChannelsIlluminanceService() {
69         JsonElement jsonObject = JsonParser.parseString("""
70                 {
71                     "@type": "illuminanceLevelState",
72                     "illuminance": 42
73                 }\
74                 """);
75         getFixture().processUpdate("MultiLevelSensor", jsonObject);
76         verify(getCallback()).stateUpdated(
77                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ILLUMINANCE), new DecimalType(42));
78     }
79 }