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