]> git.basschouten.com Git - openhab-addons.git/blob
2ef534dc6d56454f01f374e42bca005a861466df
[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.twinguard;
14
15 import static org.mockito.Mockito.verify;
16
17 import javax.measure.quantity.Dimensionless;
18 import javax.measure.quantity.Temperature;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.boschshc.internal.devices.AbstractSmokeDetectorHandlerTest;
23 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.types.StringType;
26 import org.openhab.core.library.unit.SIUnits;
27 import org.openhab.core.library.unit.Units;
28 import org.openhab.core.thing.ChannelUID;
29 import org.openhab.core.thing.ThingTypeUID;
30
31 import com.google.gson.JsonElement;
32 import com.google.gson.JsonParser;
33
34 /**
35  * Unit Tests for {@link TwinguardHandler}.
36  *
37  * @author David Pace - Initial contribution
38  *
39  */
40 @NonNullByDefault
41 public class TwinguardHandlerTest extends AbstractSmokeDetectorHandlerTest<TwinguardHandler> {
42
43     @Override
44     protected TwinguardHandler createFixture() {
45         return new TwinguardHandler(getThing());
46     }
47
48     @Override
49     protected String getDeviceID() {
50         return "hdm:ZigBee:000d6f0016d1a193";
51     }
52
53     @Override
54     protected ThingTypeUID getThingTypeUID() {
55         return BoschSHCBindingConstants.THING_TYPE_TWINGUARD;
56     }
57
58     @Test
59     public void testUpdateChannelsAirQualityLevelService() {
60         JsonElement jsonObject = JsonParser.parseString(
61                 "{\"temperatureRating\":\"GOOD\",\"humidityRating\":\"MEDIUM\",\"purity\":620,\"@type\":\"airQualityLevelState\",\n"
62                         + "     \"purityRating\":\"GOOD\",\"temperature\":23.77,\"description\":\"LITTLE_DRY\",\"humidity\":32.69,\"combinedRating\":\"MEDIUM\"}");
63         getFixture().processUpdate("AirQualityLevel", jsonObject);
64
65         verify(getCallback()).stateUpdated(
66                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE),
67                 new QuantityType<Temperature>(23.77, SIUnits.CELSIUS));
68
69         verify(getCallback()).stateUpdated(
70                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE_RATING),
71                 new StringType("GOOD"));
72
73         verify(getCallback()).stateUpdated(
74                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_HUMIDITY),
75                 new QuantityType<Dimensionless>(32.69, Units.PERCENT));
76
77         verify(getCallback()).stateUpdated(
78                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_HUMIDITY_RATING),
79                 new StringType("MEDIUM"));
80
81         verify(getCallback()).stateUpdated(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PURITY),
82                 new QuantityType<Dimensionless>(620, Units.PARTS_PER_MILLION));
83
84         verify(getCallback()).stateUpdated(
85                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PURITY_RATING),
86                 new StringType("GOOD"));
87
88         verify(getCallback()).stateUpdated(
89                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_AIR_DESCRIPTION),
90                 new StringType("LITTLE_DRY"));
91
92         verify(getCallback()).stateUpdated(
93                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_COMBINED_RATING),
94                 new StringType("MEDIUM"));
95     }
96 }