Search in sources :

Example 11 with Firmware

use of org.eclipse.smarthome.core.thing.binding.firmware.Firmware in project smarthome by eclipse.

the class FirmwareRegistry method getFirmware.

/**
 * Returns the firmware for the given UID.
 *
 * @param firmwareUID the firmware UID (must not be null)
 * @param locale the locale to be used (if null then the locale provided by the {@link LocaleProvider} is used)
 * @return the corresponding firmware or null if no firmware was found
 * @throws NullPointerException if given firmware UID is null
 */
public Firmware getFirmware(FirmwareUID firmwareUID, Locale locale) {
    Objects.requireNonNull(firmwareUID, "Firmware UID must not be null.");
    Locale loc = locale != null ? locale : localeProvider.getLocale();
    for (FirmwareProvider firmwareProvider : firmwareProviders) {
        try {
            Firmware firmware = firmwareProvider.getFirmware(firmwareUID, loc);
            if (firmware != null) {
                return firmware;
            }
        } catch (Exception e) {
            logger.warn("Unexpected exception occurred for firmware provider {} while getting firmware for firmware UID {}.", firmwareProvider.getClass().getSimpleName(), firmwareUID, e);
        }
    }
    return null;
}
Also used : Locale(java.util.Locale) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware)

Example 12 with Firmware

use of org.eclipse.smarthome.core.thing.binding.firmware.Firmware in project smarthome by eclipse.

the class FirmwareRegistry method getFirmwares.

/**
 * Returns the collection of available firmwares for the given thing type UID and locale. The collection is
 * sorted in descending order, i.e. the latest firmware will be the first element in the collection.
 *
 * @param thingTypeUID the thing type UID for which the firmwares are to be provided (not null)
 * @param locale the locale to be used (if null then the locale provided by the {@link LocaleProvider} is used)
 * @return the collection of available firmwares for the given thing type UID (not null)
 * @throws NullPointerException if given thing type UID is null
 */
public Collection<Firmware> getFirmwares(ThingTypeUID thingTypeUID, Locale locale) {
    Objects.requireNonNull(thingTypeUID, "Thing type UID must not be null.");
    Locale loc = locale != null ? locale : localeProvider.getLocale();
    Set<Firmware> firmwares = new TreeSet<>();
    for (FirmwareProvider firmwareProvider : firmwareProviders) {
        try {
            Collection<Firmware> result = firmwareProvider.getFirmwares(thingTypeUID, loc);
            if (result != null) {
                firmwares.addAll(result);
            }
        } catch (Exception e) {
            logger.warn("Unexpected exception occurred for firmware provider {} while getting firmwares for thing type UID {}.", firmwareProvider.getClass().getSimpleName(), thingTypeUID, e);
        }
    }
    return Collections.unmodifiableCollection(firmwares);
}
Also used : Locale(java.util.Locale) TreeSet(java.util.TreeSet) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware)

Aggregations

Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)12 Locale (java.util.Locale)6 FirmwareUpdateHandler (org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler)5 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)4 ProgressCallback (org.eclipse.smarthome.core.thing.binding.firmware.ProgressCallback)4 Event (org.eclipse.smarthome.core.events.Event)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)3 FirmwareUpdateBackgroundTransferHandler (org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateBackgroundTransferHandler)3 FirmwareStatusInfo (org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Test (org.junit.Test)3 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 ConfigDescriptionValidator (org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator)2 SafeCaller (org.eclipse.smarthome.core.common.SafeCaller)2 EventPublisher (org.eclipse.smarthome.core.events.EventPublisher)2