]> git.basschouten.com Git - openhab-addons.git/blob
cfd4fbcafde1c3658c4bf70d30873fd11d389e35
[openhab-addons.git] /
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.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 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     void testUpdateChannelsAirQualityLevelService() {
60         JsonElement jsonObject = JsonParser.parseString(
61                 """
62                         {"temperatureRating":"GOOD","humidityRating":"MEDIUM","purity":620,"@type":"airQualityLevelState",
63                              "purityRating":"GOOD","temperature":23.77,"description":"LITTLE_DRY","humidity":32.69,"combinedRating":"MEDIUM"}\
64                         """);
65         getFixture().processUpdate("AirQualityLevel", jsonObject);
66
67         verify(getCallback()).stateUpdated(
68                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE),
69                 new QuantityType<Temperature>(23.77, SIUnits.CELSIUS));
70
71         verify(getCallback()).stateUpdated(
72                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE_RATING),
73                 new StringType("GOOD"));
74
75         verify(getCallback()).stateUpdated(
76                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_HUMIDITY),
77                 new QuantityType<Dimensionless>(32.69, Units.PERCENT));
78
79         verify(getCallback()).stateUpdated(
80                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_HUMIDITY_RATING),
81                 new StringType("MEDIUM"));
82
83         verify(getCallback()).stateUpdated(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PURITY),
84                 new QuantityType<Dimensionless>(620, Units.PARTS_PER_MILLION));
85
86         verify(getCallback()).stateUpdated(
87                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_PURITY_RATING),
88                 new StringType("GOOD"));
89
90         verify(getCallback()).stateUpdated(
91                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_AIR_DESCRIPTION),
92                 new StringType("LITTLE_DRY"));
93
94         verify(getCallback()).stateUpdated(
95                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_COMBINED_RATING),
96                 new StringType("MEDIUM"));
97     }
98 }