Search in sources :

Example 6 with FirmwareUpdateHandler

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

Example 7 with FirmwareUpdateHandler

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;
}
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)

Example 8 with FirmwareUpdateHandler

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

Example 9 with 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();
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) URISyntaxException(java.net.URISyntaxException) ProgressCallback(org.eclipse.smarthome.core.thing.binding.firmware.ProgressCallback) LoggerFactory(org.slf4j.LoggerFactory) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware) EventFilter(org.eclipse.smarthome.core.events.EventFilter) EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) FirmwareUpdateBackgroundTransferHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateBackgroundTransferHandler) ThingStatusInfoChangedEvent(org.eclipse.smarthome.core.thing.events.ThingStatusInfoChangedEvent) Component(org.osgi.service.component.annotations.Component) FirmwareStatusInfo(org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo) SafeCaller(org.eclipse.smarthome.core.common.SafeCaller) Locale(java.util.Locale) FirmwareUID(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) URI(java.net.URI) FirmwareUpdateHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler) ThreadPoolManager(org.eclipse.smarthome.core.common.ThreadPoolManager) TranslationProvider(org.eclipse.smarthome.core.i18n.TranslationProvider) ConfigValidationException(org.eclipse.smarthome.config.core.validation.ConfigValidationException) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ConfigDescriptionValidator(org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) List(java.util.List) Modified(org.osgi.service.component.annotations.Modified) LocaleProvider(org.eclipse.smarthome.core.i18n.LocaleProvider) Event(org.eclipse.smarthome.core.events.Event) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) FirmwareUpdateHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler)

Example 10 with FirmwareUpdateHandler

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

Aggregations

FirmwareUpdateHandler (org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler)10 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)4 Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Test (org.junit.Test)3 Locale (java.util.Locale)2 FirmwareUID (org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID)2 ProgressCallback (org.eclipse.smarthome.core.thing.binding.firmware.ProgressCallback)2 ThingStatusInfoChangedEvent (org.eclipse.smarthome.core.thing.events.ThingStatusInfoChangedEvent)2 FirmwareStatusInfo (org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1