Search in sources :

Example 11 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class WemoHandler method removeSubscription.

private synchronized void removeSubscription() {
    logger.debug("Removing WeMo GENA subscription for '{}'", this);
    if (service.isRegistered(this)) {
        ThingTypeUID thingTypeUID = thing.getThingTypeUID();
        String subscription = "basicevent1";
        if ((subscriptionState.get(subscription) != null) && subscriptionState.get(subscription).booleanValue()) {
            logger.debug("WeMo {}: Unsubscribing from service {}...", getUDN(), subscription);
            service.removeSubscription(this, subscription);
        }
        if (thingTypeUID.equals(THING_TYPE_INSIGHT)) {
            subscription = "insight1";
            if ((subscriptionState.get(subscription) != null) && subscriptionState.get(subscription).booleanValue()) {
                logger.debug("WeMo {}: Unsubscribing from service {}...", getUDN(), subscription);
                service.removeSubscription(this, subscription);
            }
        }
        subscriptionState = new HashMap<String, Boolean>();
        service.unregisterParticipant(this);
    }
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 12 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class FirmwareUpdateConsoleCommandExtension method listFirmwares.

private void listFirmwares(Console console, String[] args) {
    if (args.length != 2) {
        console.println("Specify the thing type id to get its available firmwares: firmware list <thingTypeUID>");
        return;
    }
    ThingTypeUID thingTypeUID = new ThingTypeUID(args[1]);
    Collection<Firmware> firmwares = firmwareRegistry.getFirmwares(thingTypeUID);
    if (firmwares.isEmpty()) {
        console.println("No firmwares found.");
    }
    for (Firmware firmware : firmwares) {
        console.println(firmware.toString());
    }
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware)

Example 13 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class ThingDTOMapper method map.

/**
 * Maps thing DTO into thing
 *
 * @param thingDTO the thingDTO
 * @return the corresponding thing
 */
public static Thing map(ThingDTO thingDTO) {
    ThingUID thingUID = new ThingUID(thingDTO.UID);
    ThingTypeUID thingTypeUID = thingDTO.thingTypeUID == null ? new ThingTypeUID("") : new ThingTypeUID(thingDTO.thingTypeUID);
    Thing thing = ThingBuilder.create(thingTypeUID, thingUID).build();
    return ThingHelper.merge(thing, thingDTO);
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 14 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class FirmwareUpdateServiceTest method testUpdateFirmware_wrongModel.

@Test
public void testUpdateFirmware_wrongModel() {
    FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
    when(firmwareProvider2.getFirmware(eq(FWALPHA_RESTRICTED_TO_MODEL2.getUID()), any(Locale.class))).thenReturn(FWALPHA_RESTRICTED_TO_MODEL2);
    when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
        ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
        if (THING_TYPE_UID1.equals(thingTypeUID)) {
            return Collections.singleton(FWALPHA_RESTRICTED_TO_MODEL2);
        } else {
            return Collections.emptySet();
        }
    });
    firmwareRegistry.addFirmwareProvider(firmwareProvider2);
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage(equalTo(String.format("Firmware with UID %s is not suitable for thing with UID %s.", FWALPHA_RESTRICTED_TO_MODEL2.getUID(), THING1_UID)));
    firmwareUpdateService.updateFirmware(THING1_UID, FWALPHA_RESTRICTED_TO_MODEL2.getUID(), null);
}
Also used : Locale(java.util.Locale) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 15 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class FirmwareUpdateServiceTest method testPrerequisiteVersionCheck_illegalVersion.

@Test
public void testPrerequisiteVersionCheck_illegalVersion() {
    FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
    when(firmwareProvider2.getFirmware(any(FirmwareUID.class), any(Locale.class))).thenAnswer(invocation -> {
        FirmwareUID firmwareUID = (FirmwareUID) invocation.getArguments()[0];
        if (FW111_FIX_EN.getUID().equals(firmwareUID)) {
            return FW111_FIX_EN;
        } else if (FW113_EN.getUID().equals(firmwareUID)) {
            return FW113_EN;
        } else {
            return null;
        }
    });
    when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
        ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
        if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID2.equals(thingTypeUID)) {
            return Collections.emptySet();
        } else {
            return Stream.of(FW111_FIX_EN, FW113_EN).collect(Collectors.toSet());
        }
    });
    firmwareRegistry.addFirmwareProvider(firmwareProvider2);
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw113));
    try {
        firmwareUpdateService.updateFirmware(THING1_UID, FW113_EN.getUID(), null);
        fail("Expeced an IllegalArgumentException, but it was not thrown.");
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage(), is(String.format("Firmware with UID %s requires at least firmware version %s to get installed. But the current firmware version of the thing with UID %s is %s.", FW113_EN.getUID(), FW113_EN.getPrerequisiteVersion(), THING1_UID, V111)));
    }
}
Also used : Locale(java.util.Locale) FirmwareUID(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)63 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)27 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)25 Thing (org.eclipse.smarthome.core.thing.Thing)12 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)11 Locale (java.util.Locale)10 HashMap (java.util.HashMap)9 Collection (java.util.Collection)5 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)5 Before (org.junit.Before)5 Configuration (org.eclipse.smarthome.config.core.Configuration)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)3 BaseThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory)3 Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)3 ArrayList (java.util.ArrayList)2