use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID in project smarthome by eclipse.
the class ThingResource method updateFirmware.
@PUT
@Path("/{thingUID}/firmware/{firmwareVersion}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update thing firmware.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Firmware update preconditions not satisfied."), @ApiResponse(code = 404, message = "Thing not found.") })
public Response updateFirmware(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID, @PathParam("firmwareVersion") @ApiParam(value = "version") String firmwareVersion) throws IOException {
Thing thing = thingRegistry.get(new ThingUID(thingUID));
if (thing == null) {
return getThingNotFoundResponse(thingUID);
}
FirmwareUID firmwareUID = new FirmwareUID(thing.getThingTypeUID(), firmwareVersion);
try {
firmwareUpdateService.updateFirmware(thing.getUID(), firmwareUID, LocaleUtil.getLocale(language));
} catch (IllegalArgumentException | NullPointerException | IllegalStateException ex) {
return JSONResponse.createResponse(Status.BAD_REQUEST, null, "Firmware update preconditions not satisfied.");
}
return Response.status(Status.OK).build();
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testPrerequisiteVersionCheck_illegalVersion.
@Test
public void testPrerequisiteVersionCheck_illegalVersion() {
FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
when(firmwareProvider2.getFirmware(any(FirmwareUID.class), any(Locale.class))).thenAnswer(invocation -> {
FirmwareUID firmwareUID = (FirmwareUID) invocation.getArguments()[0];
if (FW111_FIX_EN.getUID().equals(firmwareUID)) {
return FW111_FIX_EN;
} else if (FW113_EN.getUID().equals(firmwareUID)) {
return FW113_EN;
} else {
return null;
}
});
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_UID2.equals(thingTypeUID)) {
return Collections.emptySet();
} else {
return Stream.of(FW111_FIX_EN, FW113_EN).collect(Collectors.toSet());
}
});
firmwareRegistry.addFirmwareProvider(firmwareProvider2);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113));
try {
firmwareUpdateService.updateFirmware(THING1_UID, FW113_EN.getUID(), null);
fail("Expeced an IllegalArgumentException, but it was not thrown.");
} catch (IllegalArgumentException expected) {
assertThat(expected.getMessage(), is(String.format("Firmware with UID %s requires at least firmware version %s to get installed. But the current firmware version of the thing with UID %s is %s.", FW113_EN.getUID(), FW113_EN.getPrerequisiteVersion(), THING1_UID, V111)));
}
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testPrerequisiteVersionCheck.
@Test
public void testPrerequisiteVersionCheck() {
FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
when(firmwareProvider2.getFirmware(any(FirmwareUID.class), any(Locale.class))).thenAnswer(invocation -> {
FirmwareUID firmwareUID = (FirmwareUID) invocation.getArguments()[0];
if (FW111_FIX_EN.getUID().equals(firmwareUID)) {
return FW111_FIX_EN;
} else if (FW113_EN.getUID().equals(firmwareUID)) {
return FW113_EN;
} else {
return null;
}
});
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_UID2.equals(thingTypeUID)) {
return Collections.emptySet();
} else {
return Stream.of(FW111_FIX_EN, FW113_EN).collect(Collectors.toSet());
}
});
firmwareRegistry.addFirmwareProvider(firmwareProvider2);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113));
firmwareUpdateService.updateFirmware(THING1_UID, FW111_FIX_EN.getUID(), null);
waitForAssert(() -> {
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111_FIX));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113));
});
firmwareUpdateService.updateFirmware(THING1_UID, FW113_EN.getUID(), null);
waitForAssert(() -> {
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V113));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(upToDateInfo));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(updateExecutableInfoFw113));
});
firmwareUpdateService.updateFirmware(THING2_UID, FW113_EN.getUID(), null);
waitForAssert(() -> {
assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V113));
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(upToDateInfo));
});
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID in project smarthome by eclipse.
the class FirmwareUpdateConsoleCommandExtension method updateFirmware.
private void updateFirmware(Console console, String[] args) {
if (args.length != 3) {
console.println("Specify the thing id and the firmware version to update the firmware: firmware update <thingUID> <firmware version>");
return;
}
ThingUID thingUID = new ThingUID(args[1]);
FirmwareUpdateHandler firmwareUpdateHandler = getFirmwareUpdateHandler(thingUID);
if (firmwareUpdateHandler == null) {
console.println(String.format("No firmware update handler available for thing with UID %s.", thingUID));
return;
}
FirmwareUID firmwareUID = new FirmwareUID(firmwareUpdateHandler.getThing().getThingTypeUID(), args[2]);
firmwareUpdateService.updateFirmware(thingUID, firmwareUID, null);
console.println("Firmware update started.");
}
Aggregations