Search in sources :

Example 1 with FirmwareUpdateHandler

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

Example 2 with FirmwareUpdateHandler

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);
}
Also used : FirmwareUpdateHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 3 with FirmwareUpdateHandler

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));
}
Also used : FirmwareUpdateHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 4 with FirmwareUpdateHandler

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

Example 5 with FirmwareUpdateHandler

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);
}
Also used : FirmwareUpdateHandler(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

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