]> git.basschouten.com Git - openhab-addons.git/blob
d878ae97414d50fc2bb9cf714e0e79ddccd2a586
[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.homematic.internal.type;
14
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.openhab.binding.homematic.test.util.BridgeHelper.createHomematicBridge;
18 import static org.openhab.binding.homematic.test.util.DimmerHelper.*;
19
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.homematic.internal.model.HmChannel;
22 import org.openhab.binding.homematic.internal.model.HmDatapoint;
23 import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
24 import org.openhab.binding.homematic.internal.model.HmDevice;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.ChannelUID;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.openhab.core.thing.ThingUID;
30 import org.openhab.core.thing.type.ChannelGroupTypeUID;
31 import org.openhab.core.thing.type.ChannelTypeUID;
32
33 /**
34  * Tests for {@link UidUtilsTest}.
35  * 
36  * @author Florian Stolte - Initial Contribution
37  *
38  */
39 public class UidUtilsTest {
40
41     @Test
42     public void testGeneratedThingTypeUIDHasExpectedFormat() {
43         HmDevice hmDevice = createDimmerHmDevice();
44
45         ThingTypeUID generatedThingTypeUID = UidUtils.generateThingTypeUID(hmDevice);
46
47         assertThat(generatedThingTypeUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3"));
48     }
49
50     @Test
51     public void testGeneratedThingTypeUIDHasExpectedFormatForHomegear() {
52         HmDevice hmDevice = createDimmerHmDevice("HOMEGEAR");
53
54         ThingTypeUID generatedThingTypeUID = UidUtils.generateThingTypeUID(hmDevice);
55
56         assertThat(generatedThingTypeUID.getAsString(), is("homematic:HG-HM-LC-Dim1-Pl3"));
57     }
58
59     @Test
60     public void testGeneratedChannelTypeUIDHasExpectedFormat() {
61         HmDatapoint hmDatapoint = createDimmerHmDatapoint();
62
63         ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(hmDatapoint);
64
65         assertThat(channelTypeUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3_1_DIMMER"));
66     }
67
68     @Test
69     public void testGeneratedChannelUIDHasExpectedFormat() {
70         HmDatapoint hmDatapoint = createDimmerHmDatapoint();
71         ThingUID thingUID = createDimmerThingUID();
72
73         ChannelUID channelUID = UidUtils.generateChannelUID(hmDatapoint, thingUID);
74
75         assertThat(channelUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3:ABC12345678:1#DIMMER"));
76     }
77
78     @Test
79     public void testGeneratedChannelGroupTypeUIDHasExpectedFormat() {
80         HmChannel hmChannel = createDimmerHmChannel();
81
82         ChannelGroupTypeUID channelGroupTypeUID = UidUtils.generateChannelGroupTypeUID(hmChannel);
83
84         assertThat(channelGroupTypeUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3_1"));
85     }
86
87     @Test
88     public void testGeneratedThingUIDHasExpectedFormat() {
89         HmDevice hmDevice = createDimmerHmDevice();
90         Bridge bridge = createHomematicBridge();
91
92         ThingUID thingUID = UidUtils.generateThingUID(hmDevice, bridge);
93
94         assertThat(thingUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3:myBridge:ABC12345678"));
95     }
96
97     @Test
98     public void testCreateHmDatapointInfoParsesChannelUIDCorrectly() {
99         ChannelUID channelUid = new ChannelUID("homematic:HM-LC-Dim1-Pl3:myBridge:ABC12345678:1#DIMMER");
100
101         HmDatapointInfo hmDatapointInfo = UidUtils.createHmDatapointInfo(channelUid);
102
103         assertThat(hmDatapointInfo.getAddress(), is("ABC12345678"));
104         assertThat(hmDatapointInfo.getChannel(), is(1));
105         assertThat(hmDatapointInfo.getName(), is("DIMMER"));
106     }
107
108     @Test
109     public void testHomematicAddressIsGeneratedFromThingID() {
110         Thing thing = createDimmerThing();
111
112         String generatedAddress = UidUtils.getHomematicAddress(thing);
113
114         assertThat(generatedAddress, is("ABC12345678"));
115     }
116 }