use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler in project smarthome by eclipse.
the class FirmwareUpdateConsoleCommandExtension method cancelUpdate.
private void cancelUpdate(Console console, String[] args) {
if (args.length != 2) {
console.println("Specify the thing id to cancel the update: firmware cancel <thingUID>");
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;
}
firmwareUpdateService.cancelFirmwareUpdate(thingUID);
console.println("Firmware update canceled.");
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testCancelFirmwareUpdate_takesLong.
@Test
public void testCancelFirmwareUpdate_takesLong() {
firmwareUpdateService.timeout = 50;
FirmwareUpdateHandler firmwareUpdateHandler = mock(FirmwareUpdateHandler.class);
doAnswer(invocation -> {
Thread.sleep(200);
return null;
}).when(firmwareUpdateHandler).cancel();
doReturn(true).when(firmwareUpdateHandler).isUpdateExecutable();
when(firmwareUpdateHandler.getThing()).thenReturn(ThingBuilder.create(THING_TYPE_UID1, THING4_UID).build());
firmwareUpdateService.addFirmwareUpdateHandler(firmwareUpdateHandler);
assertCancellationMessage("timeout-error-during-cancel", "english", null, 1);
when(mockLocaleProvider.getLocale()).thenReturn(Locale.FRENCH);
assertCancellationMessage("timeout-error-during-cancel", "français", Locale.FRENCH, 2);
when(mockLocaleProvider.getLocale()).thenReturn(Locale.GERMAN);
assertCancellationMessage("timeout-error-during-cancel", "deutsch", Locale.GERMAN, 3);
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testIndependentHandlers.
@Test
public void testIndependentHandlers() {
FirmwareUpdateHandler firmwareUpdateHandler = mock(FirmwareUpdateHandler.class);
when(firmwareUpdateHandler.getThing()).thenReturn(ThingBuilder.create(THING_TYPE_UID3, UNKNOWN_THING_UID).build());
firmwareUpdateService.addFirmwareUpdateHandler(firmwareUpdateHandler);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(UNKNOWN_THING_UID), is(unknownInfo));
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method addHandler.
private FirmwareUpdateHandler addHandler(Thing thing) {
FirmwareUpdateHandler mockHandler = mock(FirmwareUpdateHandler.class);
when(mockHandler.getThing()).thenReturn(thing);
doReturn(true).when(mockHandler).isUpdateExecutable();
doAnswer(invocation -> {
Firmware firmware = (Firmware) invocation.getArguments()[0];
thing.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion());
return null;
}).when(mockHandler).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
firmwareUpdateService.addFirmwareUpdateHandler(mockHandler);
return mockHandler;
}
use of org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testCancelFirmwareUpdate_unexpectedFailure.
@Test
public void testCancelFirmwareUpdate_unexpectedFailure() {
FirmwareUpdateHandler firmwareUpdateHandler = mock(FirmwareUpdateHandler.class);
doThrow(new RuntimeException()).when(firmwareUpdateHandler).cancel();
doReturn(true).when(firmwareUpdateHandler).isUpdateExecutable();
when(firmwareUpdateHandler.getThing()).thenReturn(ThingBuilder.create(THING_TYPE_UID1, THING4_UID).build());
firmwareUpdateService.addFirmwareUpdateHandler(firmwareUpdateHandler);
assertCancellationMessage("unexpected-handler-error-during-cancel", "english", null, 1);
when(mockLocaleProvider.getLocale()).thenReturn(Locale.FRENCH);
assertCancellationMessage("unexpected-handler-error-during-cancel", "français", Locale.FRENCH, 2);
when(mockLocaleProvider.getLocale()).thenReturn(Locale.GERMAN);
assertCancellationMessage("unexpected-handler-error-during-cancel", "deutsch", Locale.GERMAN, 3);
}
Aggregations