use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class MagicHandlerFactoryTest method shoudlReturnNullForUnknownThingTypeUID.
@Test
public void shoudlReturnNullForUnknownThingTypeUID() {
Thing thing = mock(Thing.class);
when(thing.getThingTypeUID()).thenReturn(new ThingTypeUID("anyBinding:someThingType"));
assertThat(factory.createHandler(thing), is(nullValue()));
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class LIRCRemoteDiscoveryService method addRemote.
private void addRemote(ThingUID bridge, String remote) {
ThingTypeUID uid = LIRCBindingConstants.THING_TYPE_REMOTE;
ThingUID thingUID = new ThingUID(uid, bridge, remote);
if (thingUID != null) {
if (discoveryServiceCallback != null && discoveryServiceCallback.getExistingDiscoveryResult(thingUID) != null) {
// Ignore this remote as we already know about it
logger.debug("Remote {}: Already known.", remote);
return;
}
logger.trace("Remote {}: Discovered new remote.", remote);
Map<String, Object> properties = new HashMap<>(1);
properties.put(LIRCBindingConstants.PROPERTY_REMOTE, remote);
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withLabel(remote).withBridge(bridge).withProperties(properties).build();
thingDiscovered(discoveryResult);
}
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class DiscoveryServiceRegistryOSGiTest method testGetExistingThing.
@Test
public void testGetExistingThing() {
ThingUID thingUID = new ThingUID(EXTENDED_BINDING_ID, "foo");
// verify that the callback has been set
assertNotNull(extendedDiscoveryServiceMock.discoveryServiceCallback);
// verify that the thing cannot be found if it's not there
assertNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingThing(thingUID));
thingRegistry.add(ThingBuilder.create(new ThingTypeUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE), thingUID).build());
// verify that the existing Thing can be accessed
assertNotNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingThing(thingUID));
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID 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.ThingTypeUID in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method setup.
@Before
public void setup() {
initMocks(this);
Map<String, String> props1 = new HashMap<>();
props1.put(Thing.PROPERTY_FIRMWARE_VERSION, V111);
props1.put(Thing.PROPERTY_MODEL_ID, MODEL1);
thing1 = ThingBuilder.create(THING_TYPE_UID1, THING1_ID).withProperties(props1).build();
Map<String, String> props2 = new HashMap<>();
props2.put(Thing.PROPERTY_FIRMWARE_VERSION, V112);
props2.put(Thing.PROPERTY_MODEL_ID, MODEL2);
thing2 = ThingBuilder.create(THING_TYPE_UID1, THING2_ID).withProperties(props2).build();
Map<String, String> props3 = new HashMap<>();
props3.put(Thing.PROPERTY_FIRMWARE_VERSION, VALPHA);
thing3 = ThingBuilder.create(THING_TYPE_UID2, THING3_ID).withProperties(props3).build();
firmwareUpdateService = new FirmwareUpdateService();
safeCaller = getService(SafeCaller.class);
assertNotNull(safeCaller);
firmwareUpdateService.setSafeCaller(safeCaller);
handler1 = addHandler(thing1);
handler2 = addHandler(thing2);
handler3 = addHandler(thing3);
firmwareUpdateService.setEventPublisher(mockPublisher);
when(mockLocaleProvider.getLocale()).thenReturn(Locale.ENGLISH);
firmwareUpdateService.setLocaleProvider(mockLocaleProvider);
firmwareRegistry = new FirmwareRegistry();
firmwareUpdateService.setFirmwareRegistry(firmwareRegistry);
firmwareUpdateService.setLocaleProvider(mockLocaleProvider);
firmwareRegistry.setLocaleProvider(mockLocaleProvider);
when(mockProvider.getFirmware(eq(FW009_EN.getUID()), any())).thenReturn(FW009_EN);
when(mockProvider.getFirmware(eq(FW111_EN.getUID()), any())).thenReturn(FW111_EN);
when(mockProvider.getFirmware(eq(FW112_EN.getUID()), any())).thenReturn(FW112_EN);
when(mockProvider.getFirmware(eq(FWALPHA_EN.getUID()), any())).thenReturn(FWALPHA_EN);
when(mockProvider.getFirmwares(any(ThingTypeUID.class), any())).then(invocation -> {
ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID2.equals(thingTypeUID) || THING_TYPE_UID3.equals(thingTypeUID)) {
return Collections.emptySet();
} else {
return Stream.of(FW009_EN, FW111_EN, FW112_EN).collect(Collectors.toSet());
}
});
firmwareRegistry.addFirmwareProvider(mockProvider);
firmwareUpdateService.setTranslationProvider(mockTranslationProvider);
firmwareUpdateService.setConfigDescriptionValidator(getService(ConfigDescriptionValidator.class));
}
Aggregations