Search in sources :

Example 61 with Thing

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

the class GenericItemChannelLinkProviderJavaTest method testMultiLinkConfiguration.

@Test
public void testMultiLinkConfiguration() {
    Collection<Thing> things = thingRegistry.getAll();
    assertThat(things.size(), is(0));
    String thingsModel = "Bridge hue:bridge:huebridge [ ipAddress = \"192.168.3.84\", userName = \"19fc3fa6fc870a4280a55f21315631f\" ] {" + // 
    "LCT001 bulb2 [ lightId = \"2\" ]" + // 
    "LCT001 bulb3 [ lightId = \"3\" ]" + // 
    "LCT001 bulb4 [ lightId = \"4\" ]" + "}";
    modelRepository.addOrRefreshModel(THINGS_TESTMODEL_NAME, new ByteArrayInputStream(thingsModel.getBytes()));
    String itemsModel = // 
    "Color Light3Color \"Light3 Color\" { " + // 
    "channel=\"hue:LCT001:huebridge:bulb2:color,hue:LCT001:huebridge:bulb3:color\" [ value=1 ]," + // 
    "channel=\"hue:LCT001:huebridge:bulb4:color\" [ value=2 ]" + "}";
    modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
    waitForAssert(() -> {
        assertThat(thingRegistry.getAll().size(), is(4));
        assertThat(itemRegistry.getItems().size(), is(1));
        assertThat(itemChannelLinkRegistry.getAll().size(), is(3));
    });
    assertEquals(new BigDecimal(1), itemChannelLinkRegistry.get("Light3Color -> hue:LCT001:huebridge:bulb2:color").getConfiguration().get("value"));
    assertEquals(new BigDecimal(1), itemChannelLinkRegistry.get("Light3Color -> hue:LCT001:huebridge:bulb3:color").getConfiguration().get("value"));
    assertEquals(new BigDecimal(2), itemChannelLinkRegistry.get("Light3Color -> hue:LCT001:huebridge:bulb4:color").getConfiguration().get("value"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Thing(org.eclipse.smarthome.core.thing.Thing) BigDecimal(java.math.BigDecimal) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 62 with Thing

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

the class BridgeHandler method setStatus.

private void setStatus(ThingStatus status) {
    logger.debug("set status to: {}", status);
    updateStatus(status);
    for (Thing thing : getThing().getThings()) {
        ThingHandler handler = thing.getHandler();
        if (handler != null) {
            handler.bridgeStatusChanged(getThing().getStatusInfo());
        }
    }
}
Also used : ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 63 with Thing

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

the class Job method scheduleEvent.

/**
 * Schedules an {@link EventJob} instance
 *
 * @param thingUID the Thing UID
 * @param astroHandler the {@link ThingHandler} instance
 * @param eventAt the {@link Calendar} instance denoting scheduled instant
 * @param events the event IDs to schedule
 * @param channelId the channel ID
 */
public static void scheduleEvent(String thingUID, AstroThingHandler astroHandler, Calendar eventAt, List<String> events, String channelId, boolean configAlreadyApplied) {
    boolean thingNull = checkNull(thingUID, "Thing UID is null");
    boolean astroHandlerNull = checkNull(astroHandler, "AstroThingHandler is null");
    boolean eventAtNull = checkNull(eventAt, "Scheduled Instant is null");
    boolean eventsNull = checkNull(events, "Events list is null");
    boolean channelIdNull = checkNull(channelId, "Channel ID is null");
    if (thingNull || astroHandlerNull || eventAtNull || eventsNull || channelIdNull || events.isEmpty()) {
        return;
    }
    final Calendar instant;
    if (!configAlreadyApplied) {
        final Channel channel = astroHandler.getThing().getChannel(channelId);
        if (channel == null) {
            LOGGER.warn("Cannot find channel '{}' for thing '{}'.", channelId, astroHandler.getThing().getUID());
            return;
        }
        AstroChannelConfig config = channel.getConfiguration().as(AstroChannelConfig.class);
        instant = applyConfig(eventAt, config);
    } else {
        instant = eventAt;
    }
    List<Job> jobs = events.stream().map(e -> new EventJob(thingUID, channelId, e)).collect(toList());
    schedule(thingUID, astroHandler, new CompositeJob(thingUID, jobs), instant);
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) SECOND(java.util.Calendar.SECOND) AstroChannelConfig(org.eclipse.smarthome.binding.astro.internal.config.AstroChannelConfig) Logger(org.slf4j.Logger) DateTimeUtils(org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils) MethodHandles(java.lang.invoke.MethodHandles) Planet(org.eclipse.smarthome.binding.astro.internal.model.Planet) LoggerFactory(org.slf4j.LoggerFactory) AstroThingHandler(org.eclipse.smarthome.binding.astro.handler.AstroThingHandler) Collections.singletonList(java.util.Collections.singletonList) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Calendar(java.util.Calendar) Range(org.eclipse.smarthome.binding.astro.internal.model.Range) Arrays.asList(java.util.Arrays.asList) Thing(org.eclipse.smarthome.core.thing.Thing) Objects.isNull(java.util.Objects.isNull) DateUtils.truncatedEquals(org.apache.commons.lang.time.DateUtils.truncatedEquals) AstroBindingConstants(org.eclipse.smarthome.binding.astro.AstroBindingConstants) SunPhaseName(org.eclipse.smarthome.binding.astro.internal.model.SunPhaseName) Calendar(java.util.Calendar) Channel(org.eclipse.smarthome.core.thing.Channel) AstroChannelConfig(org.eclipse.smarthome.binding.astro.internal.config.AstroChannelConfig)

Example 64 with Thing

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

the class NtpOSGiTest method tearDown.

@After
public void tearDown() {
    if (ntpThing != null) {
        Thing removedThing = thingRegistry.forceRemove(ntpThing.getUID());
        assertNotNull(removedThing);
    }
    if (testItem != null) {
        itemRegistry.remove(TEST_ITEM_NAME);
    }
}
Also used : Thing(org.eclipse.smarthome.core.thing.Thing) After(org.junit.After)

Example 65 with Thing

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

the class TradfriGatewayHandler method thingUpdated.

@Override
public void thingUpdated(Thing thing) {
    super.thingUpdated(thing);
    logger.info("Bridge configuration updated. Updating paired things (if any).");
    for (Thing t : getThing().getThings()) {
        final ThingHandler thingHandler = t.getHandler();
        if (thingHandler != null) {
            thingHandler.thingUpdated(t);
        }
    }
}
Also used : ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Thing(org.eclipse.smarthome.core.thing.Thing)

Aggregations

Thing (org.eclipse.smarthome.core.thing.Thing)98 Test (org.junit.Test)43 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)28 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)24 Configuration (org.eclipse.smarthome.config.core.Configuration)19 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 JavaTest (org.eclipse.smarthome.test.java.JavaTest)18 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)14 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)13 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Item (org.eclipse.smarthome.core.items.Item)9 Path (javax.ws.rs.Path)8 Nullable (org.eclipse.jdt.annotation.Nullable)8 Locale (java.util.Locale)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Channel (org.eclipse.smarthome.core.thing.Channel)7 ThingHandlerCallback (org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback)7 Command (org.eclipse.smarthome.core.types.Command)7 List (java.util.List)6