2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.homematic.internal.type;
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.*;
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;
34 * Tests for {@link UidUtilsTest}.
36 * @author Florian Stolte - Initial Contribution
39 public class UidUtilsTest {
42 public void testGeneratedThingTypeUIDHasExpectedFormat() {
43 HmDevice hmDevice = createDimmerHmDevice();
45 ThingTypeUID generatedThingTypeUID = UidUtils.generateThingTypeUID(hmDevice);
47 assertThat(generatedThingTypeUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3"));
51 public void testGeneratedThingTypeUIDHasExpectedFormatForHomegear() {
52 HmDevice hmDevice = createDimmerHmDevice("HOMEGEAR");
54 ThingTypeUID generatedThingTypeUID = UidUtils.generateThingTypeUID(hmDevice);
56 assertThat(generatedThingTypeUID.getAsString(), is("homematic:HG-HM-LC-Dim1-Pl3"));
60 public void testGeneratedChannelTypeUIDHasExpectedFormat() {
61 HmDatapoint hmDatapoint = createDimmerHmDatapoint();
63 ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(hmDatapoint);
65 assertThat(channelTypeUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3_1_DIMMER"));
69 public void testGeneratedChannelUIDHasExpectedFormat() {
70 HmDatapoint hmDatapoint = createDimmerHmDatapoint();
71 ThingUID thingUID = createDimmerThingUID();
73 ChannelUID channelUID = UidUtils.generateChannelUID(hmDatapoint, thingUID);
75 assertThat(channelUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3:ABC12345678:1#DIMMER"));
79 public void testGeneratedChannelGroupTypeUIDHasExpectedFormat() {
80 HmChannel hmChannel = createDimmerHmChannel();
82 ChannelGroupTypeUID channelGroupTypeUID = UidUtils.generateChannelGroupTypeUID(hmChannel);
84 assertThat(channelGroupTypeUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3_1"));
88 public void testGeneratedThingUIDHasExpectedFormat() {
89 HmDevice hmDevice = createDimmerHmDevice();
90 Bridge bridge = createHomematicBridge();
92 ThingUID thingUID = UidUtils.generateThingUID(hmDevice, bridge);
94 assertThat(thingUID.getAsString(), is("homematic:HM-LC-Dim1-Pl3:myBridge:ABC12345678"));
98 public void testCreateHmDatapointInfoParsesChannelUIDCorrectly() {
99 ChannelUID channelUid = new ChannelUID("homematic:HM-LC-Dim1-Pl3:myBridge:ABC12345678:1#DIMMER");
101 HmDatapointInfo hmDatapointInfo = UidUtils.createHmDatapointInfo(channelUid);
103 assertThat(hmDatapointInfo.getAddress(), is("ABC12345678"));
104 assertThat(hmDatapointInfo.getChannel(), is(1));
105 assertThat(hmDatapointInfo.getName(), is("DIMMER"));
109 public void testHomematicAddressIsGeneratedFromThingID() {
110 Thing thing = createDimmerThing();
112 String generatedAddress = UidUtils.getHomematicAddress(thing);
114 assertThat(generatedAddress, is("ABC12345678"));