use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class HueBridgeNupnpDiscoveryOSGITest method invalidBridgesAreNotDiscovered.
@Test
public void invalidBridgesAreNotDiscovered() {
List<DiscoveryResult> oldResults = inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID)).collect(Collectors.toList());
for (final DiscoveryResult oldResult : oldResults) {
inbox.remove(oldResult.getThingUID());
}
sut = new ConfigurableBridgeNupnpDiscoveryMock();
registerService(sut, DiscoveryService.class.getName());
final Map<ThingUID, DiscoveryResult> results = new HashMap<>();
registerDiscoveryListener(new DiscoveryListener() {
@Override
public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
results.put(result.getThingUID(), result);
}
@Override
public void thingRemoved(DiscoveryService source, ThingUID thingUID) {
}
@Override
public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
return null;
}
});
// missing ip
discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
});
// missing id
discoveryResult = "[{\"id\":\"\",\"internalipaddress\":192.168.30.22}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
});
// id < 10
discoveryResult = "[{\"id\":\"012345678\",\"internalipaddress\":192.168.30.22}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
});
// bridge indicator not part of id
discoveryResult = "[{\"id\":\"0123456789\",\"internalipaddress\":192.168.30.22}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
});
// bridge indicator at wrong position (-1)
discoveryResult = "[{\"id\":\"01234" + HueBridgeNupnpDiscovery.BRIDGE_INDICATOR + "7891\",\"internalipaddress\":192.168.30.22}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
});
// bridge indicator at wrong position (+1)
discoveryResult = "[{\"id\":\"0123456" + HueBridgeNupnpDiscovery.BRIDGE_INDICATOR + "7891\",\"internalipaddress\":192.168.30.22}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
});
// bridge not reachable
discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":192.168.30.1}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
});
// invalid bridge description
expBridgeDescription = "";
;
discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":" + ip1 + "}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
});
waitForAssert(() -> {
assertThat(inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID)).collect(Collectors.toList()).size(), is(0));
});
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class FSInternetRadioDiscoveryParticipantJavaTest method validDiscoveryResultIfWithoutBaseUrl.
/**
* Verify valid DiscoveryResult with FSInterntRadio device without base URL.
*
* @throws ValidationException
*/
@SuppressWarnings("null")
@Test
public void validDiscoveryResultIfWithoutBaseUrl() throws ValidationException {
RemoteDevice fsInternetRadioDeviceWithoutUrl = createDefaultFSInternetRadioDevice(null);
final DiscoveryResult result = discoveryParticipant.createResult(fsInternetRadioDeviceWithoutUrl);
assertEquals(new ThingUID(DEFAULT_RADIO_THING_UID), result.getThingUID());
assertEquals(FSInternetRadioBindingConstants.THING_TYPE_RADIO, result.getThingTypeUID());
assertEquals(DEFAULT_RADIO_MANIFACTURER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MANUFACTURER));
assertEquals(DEFAULT_RADIO_MODEL_NUMBER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MODEL));
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class HueBridgeNupnpDiscovery method discoverHueBridges.
/**
* Discover available Hue Bridges and then add them in the discovery inbox
*/
private void discoverHueBridges() {
for (BridgeJsonParameters bridge : getBridgeList()) {
if (isReachableAndValidHueBridge(bridge)) {
String host = bridge.getInternalIpAddress();
String serialNumber = bridge.getId().substring(0, 6) + bridge.getId().substring(10);
ThingUID uid = new ThingUID(THING_TYPE_BRIDGE, serialNumber);
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(buildProperties(host, serialNumber)).withLabel(LABEL_PATTERN.replace("IP", host)).withRepresentationProperty(SERIAL_NUMBER).build();
thingDiscovered(result);
}
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ModelRestrictedFirmwareUpdateServiceOSGiTest method testGetModelRestrictedFirmwareStatusInfo.
@Test
public void testGetModelRestrictedFirmwareStatusInfo() {
// given two things of the same thing type but with different models, both with firmware 1.0.0 installed
ThingUID thingUID1 = createAndRegisterThing(THING_ID_1, MODEL_ID_1, VERSION_1_0_0).getUID();
ThingUID thingUID2 = createAndRegisterThing(THING_ID_2, MODEL_ID_2, VERSION_1_0_0).getUID();
// given a firmware provider that provides different firmwares for the different models
registerService(createFirmwareProvider(createModelRestrictedFirmware(MODEL_ID_1, VERSION_1_0_1), createModelRestrictedFirmware(MODEL_ID_2, VERSION_1_0_2)));
// then there is an update to 1.0.1 available for thing1
FirmwareStatusInfo firmwareStatusInfoA = firmwareUpdateService.getFirmwareStatusInfo(thingUID1);
assertThat(firmwareStatusInfoA.getFirmwareStatus(), is(UPDATE_EXECUTABLE));
assertThat(firmwareStatusInfoA.getUpdatableFirmwareUID().getFirmwareVersion(), is(VERSION_1_0_1));
// and then there is an update to 1.0.2 available for thing2
FirmwareStatusInfo firmwareStatusInfoB = firmwareUpdateService.getFirmwareStatusInfo(thingUID2);
assertThat(firmwareStatusInfoB.getFirmwareStatus(), is(UPDATE_EXECUTABLE));
assertThat(firmwareStatusInfoB.getUpdatableFirmwareUID().getFirmwareVersion(), is(VERSION_1_0_2));
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ChannelStateDescriptionProviderOSGiTest method presentItemStateDescription.
/**
* Assert that item's state description is present.
*/
@Test
public void presentItemStateDescription() throws ItemNotFoundException {
ThingRegistry thingRegistry = getService(ThingRegistry.class);
ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class);
Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), new ThingUID("hue:lamp:lamp1"), null, "test thing", new Configuration());
assertNotNull(thing);
managedThingProvider.add(thing);
ItemChannelLink link = new ItemChannelLink("TestItem", getChannel(thing, "1").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem2", getChannel(thing, "2").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem3", getChannel(thing, "3").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem4", getChannel(thing, "4").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem5", getChannel(thing, "5").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem6", getChannel(thing, "6").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem7_1", getChannel(thing, "7_1").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem7_2", getChannel(thing, "7_2").getUID());
linkRegistry.add(link);
//
final Collection<Item> items = itemRegistry.getItems();
assertEquals(false, items.isEmpty());
Item item = itemRegistry.getItem("TestItem");
assertEquals("Number", item.getType());
StateDescription state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.ZERO, state.getMinimum());
assertEquals(BigDecimal.valueOf(100), state.getMaximum());
assertEquals(BigDecimal.TEN, state.getStep());
assertEquals("%d Peek", state.getPattern());
assertEquals(true, state.isReadOnly());
List<StateOption> opts = state.getOptions();
assertEquals(1, opts.size());
final StateOption opt = opts.get(0);
assertEquals("SOUND", opt.getValue());
assertEquals("My great sound.", opt.getLabel());
item = itemRegistry.getItem("TestItem2");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.ZERO, state.getMinimum());
assertEquals(BigDecimal.valueOf(256), state.getMaximum());
assertEquals(BigDecimal.valueOf(8), state.getStep());
assertEquals("%.0f", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertEquals(0, opts.size());
item = itemRegistry.getItem("TestItem3");
assertEquals("String", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertNull(state.getMinimum());
assertNull(state.getMaximum());
assertNull(state.getStep());
assertEquals("%s", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertEquals(0, opts.size());
item = itemRegistry.getItem("TestItem4");
assertEquals("Color", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem5");
assertEquals("Dimmer", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem6");
assertEquals("Switch", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem7_1");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.valueOf(10), state.getMinimum());
assertEquals(BigDecimal.valueOf(100), state.getMaximum());
assertEquals(BigDecimal.valueOf(5), state.getStep());
assertEquals("VALUE %d", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertNotNull(opts);
assertEquals(2, opts.size());
final StateOption opt0 = opts.get(0);
assertNotNull(opt0);
assertEquals(opt0.getValue(), "value0");
assertEquals(opt0.getLabel(), "label0");
final StateOption opt1 = opts.get(1);
assertNotNull(opt1);
assertEquals(opt1.getValue(), "value1");
assertEquals(opt1.getLabel(), "label1");
item = itemRegistry.getItem("TestItem7_2");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.valueOf(1), state.getMinimum());
assertEquals(BigDecimal.valueOf(101), state.getMaximum());
assertEquals(BigDecimal.valueOf(20), state.getStep());
assertEquals("NEW %d Peek", state.getPattern());
assertEquals(true, state.isReadOnly());
opts = state.getOptions();
assertNotNull(opts);
assertEquals(1, opts.size());
final StateOption opt2 = opts.get(0);
assertEquals("SOUND", opt2.getValue());
assertEquals("My great sound.", opt2.getLabel());
}
Aggregations