Search in sources :

Example 66 with ThingUID

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

the class TradfriDiscoveryServiceTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    when(handler.getThing()).thenReturn(BridgeBuilder.create(GATEWAY_TYPE_UID, "1").build());
    discovery = new TradfriDiscoveryService(handler);
    listener = new DiscoveryListener() {

        @Override
        public void thingRemoved(DiscoveryService source, ThingUID thingUID) {
        }

        @Override
        public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
            discoveryResult = result;
        }

        @Override
        public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
            return null;
        }
    };
    discovery.addDiscoveryListener(listener);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Collection(java.util.Collection) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) TradfriDiscoveryService(org.eclipse.smarthome.binding.tradfri.internal.discovery.TradfriDiscoveryService) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) TradfriDiscoveryService(org.eclipse.smarthome.binding.tradfri.internal.discovery.TradfriDiscoveryService) Before(org.junit.Before)

Example 67 with ThingUID

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

the class TradfriDiscoveryServiceTest method validDiscoveryResultWhiteLightW.

@Test
public void validDiscoveryResultWhiteLightW() {
    String json = "{\"9001\":\"TRADFRI bulb E27 W opal 1000lm\",\"9002\":1492856270,\"9020\":1507194357,\"9003\":65537,\"3311\":[{\"5850\":1,\"5851\":254,\"9003\":0}],\"9054\":0,\"5750\":2,\"9019\":1,\"3\":{\"0\":\"IKEA of Sweden\",\"1\":\"TRADFRI bulb E27 W opal 1000lm\",\"2\":\"\",\"3\":\"1.2.214\",\"6\":1}}";
    JsonObject data = new JsonParser().parse(json).getAsJsonObject();
    discovery.onUpdate("65537", data);
    assertNotNull(discoveryResult);
    assertThat(discoveryResult.getFlag(), is(DiscoveryResultFlag.NEW));
    assertThat(discoveryResult.getThingUID(), is(new ThingUID("tradfri:0100:1:65537")));
    assertThat(discoveryResult.getThingTypeUID(), is(THING_TYPE_DIMMABLE_LIGHT));
    assertThat(discoveryResult.getBridgeUID(), is(GATEWAY_THING_UID));
    assertThat(discoveryResult.getProperties().get(CONFIG_ID), is(65537));
    assertThat(discoveryResult.getRepresentationProperty(), is(CONFIG_ID));
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Example 68 with ThingUID

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

the class TradfriDiscoveryServiceTest method validDiscoveryResultRemoteControl.

@Test
public void validDiscoveryResultRemoteControl() {
    String json = "{\"9001\":\"TRADFRI remote control\",\"9002\":1492843083,\"9020\":1506977986,\"9003\":65536,\"9054\":0,\"5750\":0,\"9019\":1,\"3\":{\"0\":\"IKEA of Sweden\",\"1\":\"TRADFRI remote control\",\"2\":\"\",\"3\":\"1.2.214\",\"6\":3,\"9\":47},\"15009\":[{\"9003\":0}]}";
    JsonObject data = new JsonParser().parse(json).getAsJsonObject();
    discovery.onUpdate("65536", data);
    assertNotNull(discoveryResult);
    assertThat(discoveryResult.getFlag(), is(DiscoveryResultFlag.NEW));
    assertThat(discoveryResult.getThingUID(), is(new ThingUID("tradfri:0830:1:65536")));
    assertThat(discoveryResult.getThingTypeUID(), is(THING_TYPE_REMOTE_CONTROL));
    assertThat(discoveryResult.getBridgeUID(), is(GATEWAY_THING_UID));
    assertThat(discoveryResult.getProperties().get(CONFIG_ID), is(65536));
    assertThat(discoveryResult.getRepresentationProperty(), is(CONFIG_ID));
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Example 69 with ThingUID

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

the class NtpOSGiTest method initialize.

private void initialize(Configuration configuration, String channelID, String acceptedItemType, Configuration channelConfiguration) {
    configuration.put(NtpBindingConstants.PROPERTY_NTP_SERVER_PORT, TEST_PORT);
    ThingUID ntpUid = new ThingUID(NtpBindingConstants.THING_TYPE_NTP, TEST_THING_ID);
    ChannelUID channelUID = new ChannelUID(ntpUid, channelID);
    Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withType(channelTypeUID).withConfiguration(channelConfiguration).withLabel("label").withKind(ChannelKind.STATE).build();
    ntpThing = ThingBuilder.create(NtpBindingConstants.THING_TYPE_NTP, ntpUid).withConfiguration(configuration).withChannel(channel).build();
    managedThingProvider.add(ntpThing);
    // Wait for the NTP thing to be added to the ManagedThingProvider.
    ntpHandler = waitForAssert(() -> {
        final ThingHandler thingHandler = ntpThing.getHandler();
        assertThat(thingHandler, is(instanceOf(NtpHandler.class)));
        return (NtpHandler) thingHandler;
    }, DFL_TIMEOUT * 3, DFL_SLEEP_TIME);
    if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_STRING)) {
        testItem = new StringItem(TEST_ITEM_NAME);
    } else if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_DATE_TIME)) {
        testItem = new DateTimeItem(TEST_ITEM_NAME);
    }
    itemRegistry.add(testItem);
    // Wait for the item , linked to the NTP thing to be added to the
    // ManagedThingProvider.
    final ManagedItemChannelLinkProvider itemChannelLinkProvider = waitForAssert(() -> {
        final ManagedItemChannelLinkProvider tmp = getService(ManagedItemChannelLinkProvider.class);
        assertNotNull(tmp);
        return tmp;
    });
    itemChannelLinkProvider.add(new ItemChannelLink(TEST_ITEM_NAME, channelUID));
}
Also used : ManagedItemChannelLinkProvider(org.eclipse.smarthome.core.thing.link.ManagedItemChannelLinkProvider) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Channel(org.eclipse.smarthome.core.thing.Channel) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) NtpHandler(org.eclipse.smarthome.binding.ntp.handler.NtpHandler) DateTimeItem(org.eclipse.smarthome.core.library.items.DateTimeItem) StringItem(org.eclipse.smarthome.core.library.items.StringItem)

Example 70 with ThingUID

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

the class PersistentInbox method removeResultsForBridge.

private void removeResultsForBridge(ThingUID bridgeUID) {
    for (ThingUID thingUID : getResultsForBridge(bridgeUID)) {
        DiscoveryResult discoveryResult = get(thingUID);
        if (discoveryResult != null) {
            this.discoveryResultStorage.remove(thingUID.toString());
            notifyListeners(discoveryResult, EventType.removed);
        }
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) InboxPredicates.forThingUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Aggregations

ThingUID (org.eclipse.smarthome.core.thing.ThingUID)99 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)29 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)27 Thing (org.eclipse.smarthome.core.thing.Thing)26 Test (org.junit.Test)25 HashMap (java.util.HashMap)21 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)14 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Path (javax.ws.rs.Path)9 JsonObject (com.google.gson.JsonObject)8 JsonParser (com.google.gson.JsonParser)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Locale (java.util.Locale)6 Nullable (org.eclipse.jdt.annotation.Nullable)6 Consumes (javax.ws.rs.Consumes)5 Configuration (org.eclipse.smarthome.config.core.Configuration)5 Collection (java.util.Collection)4 GET (javax.ws.rs.GET)4 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)4