use of org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo in project smarthome by eclipse.
the class ThingResource method getFirmwareStatus.
@GET
@Path("/{thingUID}/firmware/status")
@ApiOperation(value = "Gets thing's firmware status.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 204, message = "No firmware status provided by this Thing.") })
public Response getFirmwareStatus(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID) throws IOException {
ThingUID thingUIDObject = new ThingUID(thingUID);
FirmwareStatusInfo info = firmwareUpdateService.getFirmwareStatusInfo(thingUIDObject);
if (info == null) {
return Response.status(Status.NO_CONTENT).build();
}
return Response.ok(null, MediaType.TEXT_PLAIN).entity(buildFirmwareStatusDTO(info)).build();
}
use of org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo in project smarthome by eclipse.
the class FirmwareUpdateService method processFirmwareStatusInfo.
private synchronized void processFirmwareStatusInfo(FirmwareUpdateHandler firmwareUpdateHandler, FirmwareStatusInfo newFirmwareStatusInfo, Firmware latestFirmware) {
ThingUID thingUID = firmwareUpdateHandler.getThing().getUID();
FirmwareStatusInfo previousFirmwareStatusInfo = firmwareStatusInfoMap.put(thingUID, newFirmwareStatusInfo);
if (previousFirmwareStatusInfo == null || !previousFirmwareStatusInfo.equals(newFirmwareStatusInfo)) {
eventPublisher.post(FirmwareEventFactory.createFirmwareStatusInfoEvent(newFirmwareStatusInfo, thingUID));
if (newFirmwareStatusInfo.getFirmwareStatus() == FirmwareStatus.UPDATE_AVAILABLE && firmwareUpdateHandler instanceof FirmwareUpdateBackgroundTransferHandler && !firmwareUpdateHandler.isUpdateExecutable()) {
transferLatestFirmware((FirmwareUpdateBackgroundTransferHandler) firmwareUpdateHandler, latestFirmware, previousFirmwareStatusInfo);
}
}
}
use of org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo in project smarthome by eclipse.
the class FirmwareUpdateConsoleCommandExtension method listFirmwareStatus.
private void listFirmwareStatus(Console console, String[] args) {
if (args.length != 2) {
console.println("Specify the thing id to get its firmware status: firmware status <thingUID>");
return;
}
ThingUID thingUID = new ThingUID(args[1]);
FirmwareStatusInfo firmwareStatusInfo = firmwareUpdateService.getFirmwareStatusInfo(thingUID);
if (firmwareStatusInfo != null) {
StringBuffer sb = new StringBuffer();
sb.append(String.format("Firmware status for thing with UID %s is %s.", thingUID, firmwareStatusInfo.getFirmwareStatus()));
if (firmwareStatusInfo.getUpdatableFirmwareUID() != null) {
sb.append(String.format(" The latest updatable firmware version is %s.", firmwareStatusInfo.getUpdatableFirmwareUID().getFirmwareVersion()));
}
console.println(sb.toString());
} else {
console.println(String.format("The firmware status for thing with UID %s could not be determined.", thingUID));
}
}
use of org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo in project smarthome by eclipse.
the class FirmwareUpdateService method getFirmwareStatusInfo.
/**
* Returns the {@link FirmwareStatusInfo} for the thing having the given thing UID.
*
* @param thingUID the UID of the thing (must not be null)
* @return the firmware status info (is null if there is no {@link FirmwareUpdateHandler} for the thing
* available)
* @throws NullPointerException if the given thing UID is null
*/
public FirmwareStatusInfo getFirmwareStatusInfo(ThingUID thingUID) {
Objects.requireNonNull(thingUID, "Thing UID must not be null.");
FirmwareUpdateHandler firmwareUpdateHandler = getFirmwareUpdateHandler(thingUID);
if (firmwareUpdateHandler == null) {
logger.trace("No firmware update handler available for thing with UID {}.", thingUID);
return null;
}
Firmware latestFirmware = getLatestSuitableFirmware(firmwareUpdateHandler.getThing());
FirmwareStatusInfo firmwareStatusInfo = getFirmwareStatusInfo(firmwareUpdateHandler, latestFirmware);
processFirmwareStatusInfo(firmwareUpdateHandler, firmwareStatusInfo, latestFirmware);
return firmwareStatusInfo;
}
Aggregations