use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class FirmwareTest method testFirmwareIsNotSuitableForThingWithDifferentThingType.
@Test
public void testFirmwareIsNotSuitableForThingWithDifferentThingType() {
Firmware firmware = new Firmware.Builder(new FirmwareUID(new ThingTypeUID("binding:thingTypeA"), "version")).build();
Thing thing = ThingBuilder.create(new ThingTypeUID("binding:thingTypeB"), "thing").build();
assertThat(firmware.isSuitableFor(thing), is(false));
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testGetFirmwareStatusInfo_firmwareProviderAddedLate.
@Test
public void testGetFirmwareStatusInfo_firmwareProviderAddedLate() {
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING3_UID), is(unknownInfo));
FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
when(firmwareProvider2.getFirmware(eq(FWALPHA_EN.getUID()), any(Locale.class))).thenReturn(FWALPHA_EN);
when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID1.equals(thingTypeUID)) {
return Collections.emptySet();
} else {
return Collections.singleton(FWALPHA_EN);
}
});
firmwareRegistry.addFirmwareProvider(firmwareProvider2);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING3_UID), is(upToDateInfo));
// verify that the corresponding events are sent
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(mockPublisher, times(2)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(0), unknownInfo);
assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testUpdateFirmware_wrongThingType.
@Test
public void testUpdateFirmware_wrongThingType() {
FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
when(firmwareProvider2.getFirmware(eq(FWALPHA_EN.getUID()), any(Locale.class))).thenReturn(FWALPHA_EN);
when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID1.equals(thingTypeUID)) {
return Collections.emptySet();
} else {
return Collections.singleton(FWALPHA_EN);
}
});
firmwareRegistry.addFirmwareProvider(firmwareProvider2);
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(String.format("Firmware with UID %s is not suitable for thing with UID %s.", FWALPHA_EN.getUID(), THING1_UID)));
firmwareUpdateService.updateFirmware(THING1_UID, FWALPHA_EN.getUID(), null);
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class DigitalSTROMHandlerFactory method createHandler.
@Override
protected ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID == null) {
return null;
}
if (BridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
BridgeHandler handler = new BridgeHandler((Bridge) thing);
if (bridgeHandlers == null) {
bridgeHandlers = new HashMap<ThingUID, BridgeHandler>();
}
bridgeHandlers.put(thing.getUID(), handler);
DiscoveryServiceManager discoveryServiceManager = new DiscoveryServiceManager(handler);
discoveryServiceManager.registerDiscoveryServices(bundleContext);
discoveryServiceManagers.put(handler.getThing().getUID().getAsString(), discoveryServiceManager);
return handler;
}
if (DeviceHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
return new DeviceHandler(thing);
}
if (CircuitHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
return new CircuitHandler(thing);
}
if (ZoneTemperatureControlHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
return new ZoneTemperatureControlHandler(thing);
}
if (SceneHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
return new SceneHandler(thing);
}
return null;
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class DeviceDiscoveryService method getThingUID.
private ThingUID getThingUID(GeneralDeviceInformation device) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
ThingTypeUID thingTypeUID = null;
if (device instanceof Device) {
Device tempDevice = (Device) device;
thingTypeUID = new ThingTypeUID(BINDING_ID, tempDevice.getHWinfo().substring(0, 2));
if (tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) {
thingTypeUID = new ThingTypeUID(BINDING_ID, deviceType);
}
} else {
thingTypeUID = new ThingTypeUID(BINDING_ID, DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString());
}
if (getSupportedThingTypes().contains(thingTypeUID)) {
String thingDeviceId = device.getDSID().toString();
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingDeviceId);
return thingUID;
} else {
return null;
}
}
Aggregations