Search in sources :

Example 1 with FirmwareStatusInfo

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();
}
Also used : FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with FirmwareStatusInfo

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);
        }
    }
}
Also used : FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) FirmwareUpdateBackgroundTransferHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateBackgroundTransferHandler) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 3 with FirmwareStatusInfo

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));
    }
}
Also used : FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 4 with FirmwareStatusInfo

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;
}
Also used : FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) FirmwareUpdateHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware)

Aggregations

FirmwareStatusInfo (org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo)4 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)3 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)1 FirmwareUpdateBackgroundTransferHandler (org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateBackgroundTransferHandler)1 FirmwareUpdateHandler (org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler)1