use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler 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.");
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler 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;
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler in project smarthome by eclipse.
the class FirmwareUpdateService method receive.
@Override
public void receive(Event event) {
if (event instanceof ThingStatusInfoChangedEvent) {
ThingStatusInfoChangedEvent changedEvent = (ThingStatusInfoChangedEvent) event;
if (changedEvent.getStatusInfo().getStatus() != ThingStatus.ONLINE) {
return;
}
ThingUID thingUID = changedEvent.getThingUID();
FirmwareUpdateHandler firmwareUpdateHandler = getFirmwareUpdateHandler(thingUID);
if (firmwareUpdateHandler != null && !firmwareStatusInfoMap.containsKey(thingUID)) {
initializeFirmwareStatus(firmwareUpdateHandler);
}
}
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler in project smarthome by eclipse.
the class FirmwareUpdateService method cancelFirmwareUpdate.
/**
* Cancels the firmware update of the thing having the given thing UID by invoking the operation
* {@link FirmwareUpdateHandler#cancel()} of the thing´s firmware update handler.
*
* @param thingUID the thing UID (must not be null)
*/
public void cancelFirmwareUpdate(final ThingUID thingUID) {
Objects.requireNonNull(thingUID, "Thing UID must not be null.");
final FirmwareUpdateHandler firmwareUpdateHandler = getFirmwareUpdateHandler(thingUID);
if (firmwareUpdateHandler == null) {
throw new IllegalArgumentException(String.format("There is no firmware update handler for thing with UID %s.", thingUID));
}
final ProgressCallbackImpl progressCallback = getProgressCallback(thingUID);
logger.debug("Cancelling firmware update for thing with UID {}.", thingUID);
safeCaller.create(firmwareUpdateHandler, FirmwareUpdateHandler.class).withTimeout(timeout).withAsync().onTimeout(() -> {
logger.error("Timeout occurred while cancelling firmware update of thing with UID {}.", thingUID);
progressCallback.failedInternal("timeout-error-during-cancel");
}).onException(e -> {
logger.error("Unexpected exception occurred while cancelling firmware update of thing with UID {}.", thingUID, e.getCause());
progressCallback.failedInternal("unexpected-handler-error-during-cancel");
}).withIdentifier(new Object()).build().cancel();
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler in project smarthome by eclipse.
the class FirmwareUpdateService method updateFirmware.
/**
* Updates the firmware of the thing having the given thing UID by invoking the operation
* {@link FirmwareUpdateHandler#updateFirmware(Firmware, ProgressCallback)} of the thing´s firmware update handler.
* <p>
* This operation is a non-blocking operation by spawning a new thread around the invocation of the firmware update
* handler. The time out of the thread is 30 minutes.
*
* @param thingUID the thing UID (must not be null)
* @param firmwareUID the UID of the firmware to be updated (must not be null)
* @param locale the locale to be used to internationalize error messages (if null then the locale provided by the
* {@link LocaleProvider} is used)
* @throws NullPointerException if given thing UID or firmware UID is null
* @throws IllegalStateException if
* <ul>
* <li>there is no firmware update handler for the thing</li>
* <li>the firmware update handler is not able to execute the firmware update</li>
* </ul>
* @throws IllegalArgumentException if
* <ul>
* <li>the firmware cannot be found</li>
* <li>the firmware is not suitable for the thing</li>
* <li>the firmware requires another prerequisite firmware version</li>
* </ul>
*/
public void updateFirmware(final ThingUID thingUID, final FirmwareUID firmwareUID, final Locale locale) {
Objects.requireNonNull(thingUID, "Thing UID must not be null.");
Objects.requireNonNull(firmwareUID, "Firmware UID must not be null.");
final FirmwareUpdateHandler firmwareUpdateHandler = getFirmwareUpdateHandler(thingUID);
if (firmwareUpdateHandler == null) {
throw new IllegalArgumentException(String.format("There is no firmware update handler for thing with UID %s.", thingUID));
}
final Firmware firmware = getFirmware(firmwareUID);
validateFirmwareUpdateConditions(firmware, firmwareUpdateHandler);
final Locale loc = locale != null ? locale : localeProvider.getLocale();
final ProgressCallbackImpl progressCallback = new ProgressCallbackImpl(firmwareUpdateHandler, eventPublisher, i18nProvider, thingUID, firmwareUID, loc);
progressCallbackMap.put(thingUID, progressCallback);
logger.debug("Starting firmware update for thing with UID {} and firmware with UID {}", thingUID, firmwareUID);
safeCaller.create(firmwareUpdateHandler, FirmwareUpdateHandler.class).withTimeout(timeout).withAsync().onTimeout(() -> {
logger.error("Timeout occurred for firmware update of thing with UID {} and firmware with UID {}.", thingUID, firmwareUID);
progressCallback.failedInternal("timeout-error");
}).onException(e -> {
logger.error("Unexpected exception occurred for firmware update of thing with UID {} and firmware with UID {}.", thingUID, firmwareUID, e.getCause());
progressCallback.failedInternal("unexpected-handler-error");
}).build().updateFirmware(firmware, progressCallback);
}
Aggregations