Search in sources :

Example 56 with Thing

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

the class FirmwareUpdateServiceTest method testUpdateFirmware_noFirmwareUpdateHandler.

@Test
public void testUpdateFirmware_noFirmwareUpdateHandler() {
    Thing thing4 = ThingBuilder.create(THING_TYPE_UID_WITHOUT_FW, THING5_ID).build();
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage(equalTo(String.format("There is no firmware update handler for thing with UID %s.", thing4.getUID())));
    firmwareUpdateService.updateFirmware(thing4.getUID(), FW009_EN.getUID(), null);
}
Also used : Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 57 with Thing

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

the class ThingActionService method getThingStatusInfo.

public static ThingStatusInfo getThingStatusInfo(String thingUid) {
    ThingUID uid = new ThingUID(thingUid);
    Thing thing = thingRegistry.get(uid);
    if (thing != null) {
        return thing.getStatusInfo();
    } else {
        return null;
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 58 with Thing

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

the class MagicHandlerFactoryTest method shoudlReturnDimmableLightHandler.

@Test
public void shoudlReturnDimmableLightHandler() {
    Thing thing = mock(Thing.class);
    when(thing.getThingTypeUID()).thenReturn(MagicBindingConstants.THING_TYPE_DIMMABLE_LIGHT);
    assertThat(factory.createHandler(thing), is(instanceOf(MagicDimmableLightHandler.class)));
}
Also used : Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test)

Example 59 with Thing

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

the class GenericItemChannelLinkProviderJavaTest method testLinkConfiguration.

@Test
public void testLinkConfiguration() {
    Collection<Thing> things = thingRegistry.getAll();
    assertThat(things.size(), is(0));
    String thingsModel = "Bridge hue:bridge:huebridge [ ipAddress = \"192.168.3.84\", userName = \"19fc3fa6fc870a4280a55f21315631f\" ] {" + // 
    "LCT001 bulb3 [ lightId = \"3\" ]" + // 
    "LCT001 bulb4 [ lightId = \"3\" ]" + "}";
    modelRepository.addOrRefreshModel(THINGS_TESTMODEL_NAME, new ByteArrayInputStream(thingsModel.getBytes()));
    String itemsModel = "Color Light3Color \"Light3 Color\" { channel=\"hue:LCT001:huebridge:bulb3:color\" [ foo=\"bar\", answer=42, always=true ] }" + "Group:Switch:MAX TestSwitches";
    modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
    waitForAssert(() -> {
        assertThat(thingRegistry.getAll().size(), is(3));
        assertThat(itemRegistry.getItems().size(), is(2));
        assertThat(itemChannelLinkRegistry.getAll().size(), is(1));
    });
    ItemChannelLink link = itemChannelLinkRegistry.get("Light3Color -> hue:LCT001:huebridge:bulb3:color");
    assertNotNull(link);
    assertEquals("Light3Color", link.getItemName());
    assertEquals("hue:LCT001:huebridge:bulb3:color", link.getLinkedUID().toString());
    assertEquals("bar", link.getConfiguration().get("foo"));
    assertEquals(new BigDecimal(42), link.getConfiguration().get("answer"));
    assertEquals(true, link.getConfiguration().get("always"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) Thing(org.eclipse.smarthome.core.thing.Thing) BigDecimal(java.math.BigDecimal) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 60 with Thing

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

the class GenericItemChannelLinkProviderJavaTest method testIntegrationWithGenericItemProvider.

@Test
public void testIntegrationWithGenericItemProvider() throws Exception {
    // Wait for the ChannelItemProvider to join the game
    Thread.sleep(2500);
    Collection<Thing> things = thingRegistry.getAll();
    assertThat(things.size(), is(0));
    String thingsModel = "Bridge hue:bridge:huebridge [ ipAddress = \"192.168.3.84\", userName = \"19fc3fa6fc870a4280a55f21315631f\" ] {" + "LCT001 bulb3 [ lightId = \"3\" ]" + "LCT001 bulb4 [ lightId = \"3\" ]" + "}";
    modelRepository.addOrRefreshModel(THINGS_TESTMODEL_NAME, new ByteArrayInputStream(thingsModel.getBytes()));
    Collection<Thing> actualThings = thingRegistry.getAll();
    assertThat(actualThings.size(), is(3));
    assertThat(itemRegistry.getItems().size(), is(0));
    assertThat(itemChannelLinkRegistry.getAll().size(), is(0));
    String itemsModel = "Color Light3Color \"Light3 Color\" { channel=\"hue:LCT001:huebridge:bulb3:color\" }" + "Group:Switch:MAX TestSwitches";
    // Initially load the model
    modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
    assertThat(itemRegistry.getItems().size(), is(2));
    assertThat(itemChannelLinkRegistry.getAll().size(), is(1));
    // Update the model to run into GenericItemChannelLinkProvider's amnesia
    modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
    assertThat(itemRegistry.getItems().size(), is(2));
    assertThat(itemChannelLinkRegistry.getAll().size(), is(1));
    // Remove the model (-> the link and therefore the item is kept)
    modelRepository.removeModel(ITEMS_TESTMODEL_NAME);
    assertThat(itemRegistry.getItems().size(), is(0));
    assertThat(itemChannelLinkRegistry.getAll().size(), is(0));
    // Now add the model again
    modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
    // -> ensure ChannelItemProvider cleans up properly
    assertThat(itemRegistry.getItems().size(), is(2));
    assertThat(itemChannelLinkRegistry.getAll().size(), is(1));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

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