|
| 1 | +/** |
| 2 | + * Copyright (c) 2010-2024 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.smokedetector; |
| 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.AbstractSmokeDetectorHandlerTest; |
| 20 | +import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants; |
| 21 | +import org.openhab.core.library.types.DecimalType; |
| 22 | +import org.openhab.core.thing.ChannelUID; |
| 23 | +import org.openhab.core.thing.ThingTypeUID; |
| 24 | + |
| 25 | +import com.google.gson.JsonElement; |
| 26 | +import com.google.gson.JsonParser; |
| 27 | + |
| 28 | +/** |
| 29 | + * Unit Tests for {@link SmokeDetector2Handler}. |
| 30 | + * |
| 31 | + * @author Patrick Gell - Initial contribution |
| 32 | + * |
| 33 | + */ |
| 34 | +@NonNullByDefault |
| 35 | +public class SmokeDetector2HandlerTest extends AbstractSmokeDetectorHandlerTest<SmokeDetector2Handler> { |
| 36 | + |
| 37 | + @Override |
| 38 | + protected SmokeDetector2Handler createFixture() { |
| 39 | + return new SmokeDetector2Handler(getThing()); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + protected String getDeviceID() { |
| 44 | + return "hdm:ZigBee:70ac08abfe5fe5f9"; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + protected ThingTypeUID getThingTypeUID() { |
| 49 | + return BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR_2; |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + void testUpdateChannelsCommunicationQualityService() { |
| 54 | + String json = """ |
| 55 | + { |
| 56 | + "@type": "communicationQualityState", |
| 57 | + "quality": "UNKNOWN" |
| 58 | + } |
| 59 | + """; |
| 60 | + JsonElement jsonObject = JsonParser.parseString(json); |
| 61 | + |
| 62 | + getFixture().processUpdate("CommunicationQuality", jsonObject); |
| 63 | + verify(getCallback()).stateUpdated( |
| 64 | + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH), |
| 65 | + new DecimalType(0)); |
| 66 | + |
| 67 | + json = """ |
| 68 | + { |
| 69 | + "@type": "communicationQualityState", |
| 70 | + "quality": "NORMAL" |
| 71 | + } |
| 72 | + """; |
| 73 | + jsonObject = JsonParser.parseString(json); |
| 74 | + |
| 75 | + getFixture().processUpdate("CommunicationQuality", jsonObject); |
| 76 | + verify(getCallback()).stateUpdated( |
| 77 | + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH), |
| 78 | + new DecimalType(3)); |
| 79 | + } |
| 80 | +} |
0 commit comments