use of org.eclipse.smarthome.core.thing.binding.firmware.Firmware in project smarthome by eclipse.
the class ThingTypeResource method getFirmwares.
@GET
@Path("/{thingTypeUID}/firmwares")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available firmwares for provided thingType", response = StrippedThingTypeDTO.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 204, message = "No firmwares found.") })
public Response getFirmwares(@PathParam("thingTypeUID") @ApiParam(value = "thingTypeUID") String thingTypeUID, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language) {
ThingTypeUID athingTypeUID = new ThingTypeUID(thingTypeUID);
Collection<Firmware> firmwares = firmwareRegistry.getFirmwares(athingTypeUID, LocaleUtil.getLocale(language));
if (firmwares.isEmpty()) {
return Response.status(Status.NO_CONTENT).build();
}
Stream<FirmwareDTO> firmwareStream = firmwares.stream().map(this::convertToFirmwareDTO);
return Response.ok(null, MediaType.TEXT_PLAIN).entity(new Stream2JSONInputStream(firmwareStream)).build();
}
use of org.eclipse.smarthome.core.thing.binding.firmware.Firmware in project smarthome by eclipse.
the class FirmwareUpdateConsoleCommandExtension method listFirmwares.
private void listFirmwares(Console console, String[] args) {
if (args.length != 2) {
console.println("Specify the thing type id to get its available firmwares: firmware list <thingTypeUID>");
return;
}
ThingTypeUID thingTypeUID = new ThingTypeUID(args[1]);
Collection<Firmware> firmwares = firmwareRegistry.getFirmwares(thingTypeUID);
if (firmwares.isEmpty()) {
console.println("No firmwares found.");
}
for (Firmware firmware : firmwares) {
console.println(firmware.toString());
}
}
use of org.eclipse.smarthome.core.thing.binding.firmware.Firmware in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method addHandler.
private FirmwareUpdateHandler addHandler(Thing thing) {
FirmwareUpdateHandler mockHandler = mock(FirmwareUpdateHandler.class);
when(mockHandler.getThing()).thenReturn(thing);
doReturn(true).when(mockHandler).isUpdateExecutable();
doAnswer(invocation -> {
Firmware firmware = (Firmware) invocation.getArguments()[0];
thing.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion());
return null;
}).when(mockHandler).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
firmwareUpdateService.addFirmwareUpdateHandler(mockHandler);
return mockHandler;
}
use of org.eclipse.smarthome.core.thing.binding.firmware.Firmware in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testBackgroundTransfer.
@Test
public void testBackgroundTransfer() throws Exception {
Map<String, String> props = new HashMap<>();
props.put(Thing.PROPERTY_FIRMWARE_VERSION, V111);
Thing thing4 = ThingBuilder.create(THING_TYPE_UID3, THING4_ID).withProperties(props).build();
FirmwareUpdateBackgroundTransferHandler handler4 = mock(FirmwareUpdateBackgroundTransferHandler.class);
when(handler4.getThing()).thenReturn(thing4);
doAnswer(invocation -> {
return updateExecutable.get();
}).when(handler4).isUpdateExecutable();
doAnswer(invocation -> {
Firmware firmware = (Firmware) invocation.getArguments()[0];
thing4.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion());
updateExecutable.set(false);
return null;
}).when(handler4).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
firmwareUpdateService.addFirmwareUpdateHandler(handler4);
doAnswer(invocation -> {
try {
Thread.sleep(25);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
updateExecutable.set(true);
return null;
}).when(handler4).transferFirmware(any(Firmware.class));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING4_UID), is(unknownInfo));
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(mockPublisher, times(1)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING4_UID, eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1), unknownInfo);
FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
when(firmwareProvider2.getFirmware(eq(FW120_EN.getUID()), any(Locale.class))).thenReturn(FW120_EN);
when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
if (THING_TYPE_UID3.equals(thingTypeUID)) {
return Collections.singleton(FW120_EN);
} else {
return Collections.emptySet();
}
});
firmwareRegistry.addFirmwareProvider(firmwareProvider2);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING4_UID), is(updateAvailableInfo));
verify(mockPublisher, times(2)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING4_UID, eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1), updateAvailableInfo);
waitForAssert(() -> {
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING4_UID), is(updateExecutableInfoFw120));
verify(mockPublisher, times(3)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING4_UID, eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1), updateExecutableInfoFw120);
});
firmwareUpdateService.updateFirmware(THING4_UID, FW120_EN.getUID(), null);
waitForAssert(() -> {
assertThat(thing4.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V120));
});
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING4_UID), is(upToDateInfo));
verify(mockPublisher, times(4)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING4_UID, eventCaptor.getAllValues().get(eventCaptor.getAllValues().size() - 1), upToDateInfo);
assertThat(handler4.isUpdateExecutable(), is(false));
}
use of org.eclipse.smarthome.core.thing.binding.firmware.Firmware in project smarthome by eclipse.
the class ModelRestrictedFirmwareUpdateServiceOSGiTest method testUpdateModelRestrictedFirmware.
@Test
public void testUpdateModelRestrictedFirmware() {
// 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
Firmware firmwareModelA = createModelRestrictedFirmware(MODEL_ID_1, VERSION_1_0_1);
Firmware firmwareModelB = createModelRestrictedFirmware(MODEL_ID_2, VERSION_1_0_2);
registerService(createFirmwareProvider(firmwareModelA, firmwareModelB));
// when the firmware on thing1 is updated to the firmware for model1
firmwareUpdateService.updateFirmware(thingUID1, firmwareModelA.getUID(), null);
// then the new firmware is installed on thing 1 and no more update is available
waitForAssert(() -> {
assertThatThingHasFirmware(thingUID1, VERSION_1_0_1);
assertThatThingHasFirmwareStatus(thingUID1, UP_TO_DATE);
});
// and when the firmware on thing2 is updated to the firmware for model2
firmwareUpdateService.updateFirmware(thingUID2, firmwareModelB.getUID(), null);
// then the new firmware is installed on thing2 and no more update is available
waitForAssert(() -> {
assertThatThingHasFirmware(thingUID2, VERSION_1_0_2);
assertThatThingHasFirmwareStatus(thingUID2, UP_TO_DATE);
});
}
Aggregations