Search in sources :

Example 1 with FirmwareStatusInfo

use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.

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.getUpdatableFirmwareVersion() != null) {
            sb.append(String.format(" The latest updatable firmware version is %s.", firmwareStatusInfo.getUpdatableFirmwareVersion()));
        }
        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.openhab.core.thing.firmware.FirmwareStatusInfo) ThingUID(org.openhab.core.thing.ThingUID)

Example 2 with FirmwareStatusInfo

use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.

the class FirmwareUpdateServiceImpl method getFirmwareStatusInfo.

@Override
@Nullable
public FirmwareStatusInfo getFirmwareStatusInfo(ThingUID thingUID) {
    ParameterChecks.checkNotNull(thingUID, "Thing UID");
    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.openhab.core.thing.firmware.FirmwareStatusInfo) FirmwareUpdateHandler(org.openhab.core.thing.binding.firmware.FirmwareUpdateHandler) Firmware(org.openhab.core.thing.binding.firmware.Firmware) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with FirmwareStatusInfo

use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method testGetFirmwareStatusInfo.

@Test
public void testGetFirmwareStatusInfo() {
    final FirmwareStatusInfo unknownInfo = createUnknownInfo(thing2.getUID());
    final FirmwareStatusInfo upToDateInfo = createUpToDateInfo(thing2.getUID());
    final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
    assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111));
    assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V112));
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(upToDateInfo));
    thing2.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, null);
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(unknownInfo));
    // verify that the corresponding events are sent
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventPublisherMock, times(3)).post(eventCaptor.capture());
    assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
    assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
    assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(2), unknownInfo);
}
Also used : FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) Event(org.openhab.core.events.Event) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 4 with FirmwareStatusInfo

use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method testEvents.

@Test
public void testEvents() {
    doAnswer(invocation -> {
        Firmware firmware = (Firmware) invocation.getArguments()[0];
        ProgressCallback progressCallback = (ProgressCallback) invocation.getArguments()[1];
        progressCallback.defineSequence(SEQUENCE);
        progressCallback.next();
        progressCallback.next();
        progressCallback.next();
        progressCallback.next();
        thing1.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion());
        return null;
    }).when(handler1Mock).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
    // getFirmwareStatusInfo() method will internally generate and post one FirmwareStatusInfoEvent event.
    final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
    firmwareUpdateService.updateFirmware(THING1_UID, FW112_EN.getVersion(), null);
    AtomicReference<List<Event>> events = new AtomicReference<>(new ArrayList<>());
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    waitForAssert(() -> {
        // Wait for four FirmwareUpdateProgressInfoEvents plus one FirmwareStatusInfoEvent event.
        verify(eventPublisherMock, atLeast(SEQUENCE.length + 1)).post(eventCaptor.capture());
    });
    events.get().addAll(eventCaptor.getAllValues());
    List<Event> list = events.get().stream().filter(event -> event instanceof FirmwareUpdateProgressInfoEvent).collect(Collectors.toList());
    assertTrue(list.size() >= SEQUENCE.length);
    for (int i = 0; i < SEQUENCE.length; i++) {
        FirmwareUpdateProgressInfoEvent event = (FirmwareUpdateProgressInfoEvent) list.get(i);
        assertThat(event.getTopic(), containsString(THING1_UID.getAsString()));
        assertThat(event.getProgressInfo().getThingUID(), is(THING1_UID));
        assertThat(event.getProgressInfo().getProgressStep(), is(SEQUENCE[i]));
    }
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ProgressCallback(org.openhab.core.thing.binding.firmware.ProgressCallback) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) SafeCaller(org.openhab.core.common.SafeCaller) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Locale(java.util.Locale) Map(java.util.Map) FirmwareUpdateService(org.openhab.core.thing.firmware.FirmwareUpdateService) ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) Bundle(org.osgi.framework.Bundle) EventPublisher(org.openhab.core.events.EventPublisher) FirmwareRegistry(org.openhab.core.thing.firmware.FirmwareRegistry) BundleResolver(org.openhab.core.util.BundleResolver) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) FirmwareUpdateHandler(org.openhab.core.thing.binding.firmware.FirmwareUpdateHandler) Set(java.util.Set) FirmwareUpdateBackgroundTransferHandler(org.openhab.core.thing.binding.firmware.FirmwareUpdateBackgroundTransferHandler) TranslationProvider(org.openhab.core.i18n.TranslationProvider) Collectors(java.util.stream.Collectors) Firmware(org.openhab.core.thing.binding.firmware.Firmware) Test(org.junit.jupiter.api.Test) List(java.util.List) LocaleProvider(org.openhab.core.i18n.LocaleProvider) Stream(java.util.stream.Stream) FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ConfigDescriptionValidator(org.openhab.core.config.core.validation.ConfigDescriptionValidator) Answer(org.mockito.stubbing.Answer) Thing(org.openhab.core.thing.Thing) ArgumentCaptor(org.mockito.ArgumentCaptor) Map.entry(java.util.Map.entry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NoSuchElementException(java.util.NoSuchElementException) FirmwareUpdateResult(org.openhab.core.thing.firmware.FirmwareUpdateResult) ThingUID(org.openhab.core.thing.ThingUID) Event(org.openhab.core.events.Event) Constants(org.openhab.core.thing.firmware.Constants) IOException(java.io.IOException) ProgressStep(org.openhab.core.thing.binding.firmware.ProgressStep) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) ProgressCallback(org.openhab.core.thing.binding.firmware.ProgressCallback) AtomicReference(java.util.concurrent.atomic.AtomicReference) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) Event(org.openhab.core.events.Event) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) List(java.util.List) ArrayList(java.util.ArrayList) Firmware(org.openhab.core.thing.binding.firmware.Firmware) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 5 with FirmwareStatusInfo

use of org.openhab.core.thing.firmware.FirmwareStatusInfo in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method testUpdateFirmwareTimeOut.

@Test
public void testUpdateFirmwareTimeOut() {
    firmwareUpdateService.timeout = 50;
    final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
    waitForAssert(() -> {
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventPublisherMock, times(1)).post(eventCaptor.capture());
    });
    doAnswer(invocation -> {
        Thread.sleep(200);
        return null;
    }).when(handler1Mock).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
    assertResultInfoEvent(THING1_UID, FW112_EN, "timeout-error", Locale.ENGLISH, "english", 1);
    assertResultInfoEvent(THING1_UID, FW112_EN, "timeout-error", Locale.GERMAN, "deutsch", 2);
}
Also used : FirmwareStatusInfo(org.openhab.core.thing.firmware.FirmwareStatusInfo) ProgressCallback(org.openhab.core.thing.binding.firmware.ProgressCallback) FirmwareUpdateResultInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent) FirmwareStatusInfoEvent(org.openhab.core.thing.firmware.FirmwareStatusInfoEvent) FirmwareUpdateProgressInfoEvent(org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent) Event(org.openhab.core.events.Event) Firmware(org.openhab.core.thing.binding.firmware.Firmware) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Aggregations

FirmwareStatusInfo (org.openhab.core.thing.firmware.FirmwareStatusInfo)18 Test (org.junit.jupiter.api.Test)16 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)16 Event (org.openhab.core.events.Event)11 FirmwareStatusInfoEvent (org.openhab.core.thing.firmware.FirmwareStatusInfoEvent)11 FirmwareUpdateProgressInfoEvent (org.openhab.core.thing.firmware.FirmwareUpdateProgressInfoEvent)11 FirmwareUpdateResultInfoEvent (org.openhab.core.thing.firmware.FirmwareUpdateResultInfoEvent)11 Firmware (org.openhab.core.thing.binding.firmware.Firmware)7 Thing (org.openhab.core.thing.Thing)6 ProgressCallback (org.openhab.core.thing.binding.firmware.ProgressCallback)6 HashMap (java.util.HashMap)3 NoSuchElementException (java.util.NoSuchElementException)3 TreeSet (java.util.TreeSet)3 FirmwareUpdateHandler (org.openhab.core.thing.binding.firmware.FirmwareUpdateHandler)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2