use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ScriptEngineOSGiTest method setup.
@Before
public void setup() {
registerVolatileStorageService();
EventPublisher eventPublisher = event -> {
};
registerService(eventPublisher);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
return Lists.newArrayList(new SwitchItem(ITEM_NAME), createNumberItem(NUMBER_ITEM_TEMPERATURE, Temperature.class), createNumberItem(NUMBER_ITEM_LENGTH, Length.class), new NumberItem(NUMBER_ITEM_DECIMAL));
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
}
};
registerService(itemProvider);
ScriptServiceUtil scriptServiceUtil = getService(ScriptServiceUtil.class);
assertNotNull(scriptServiceUtil);
scriptEngine = ScriptServiceUtil.getScriptEngine();
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ScriptEngineOSGiTest method testLessThanWithItemState.
@SuppressWarnings("null")
@Test
public void testLessThanWithItemState() throws ScriptExecutionException, ScriptParsingException {
Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE);
((NumberItem) numberItem).setState(new QuantityType<>("20 °F"));
assertTrue(runScript("NumberA.state < 20 [°C]"));
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class BusEvent method sendCommand.
/**
* Sends a command for a specified item to the event bus.
*
* @param itemName the name of the item to send the command to
* @param commandString the command to send
*/
public static Object sendCommand(String itemName, String commandString) {
ItemRegistry registry = ScriptServiceUtil.getItemRegistry();
EventPublisher publisher = ScriptServiceUtil.getEventPublisher();
if (publisher != null && registry != null) {
try {
Item item = registry.getItem(itemName);
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandString);
if (command != null) {
publisher.post(ItemEventFactory.createCommandEvent(itemName, command));
} else {
LoggerFactory.getLogger(BusEvent.class).warn("Cannot convert '{}' to a command type which item '{}' accepts: {}.", commandString, itemName, getAcceptedCommandNames(item));
}
} catch (ItemNotFoundException e) {
LoggerFactory.getLogger(BusEvent.class).warn("Item '{}' does not exist.", itemName);
}
}
return null;
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class NtpOSGiTest method getItemState.
private State getItemState(String acceptedItemType) {
final Item testItem = waitForAssert(() -> {
Item tmp;
try {
tmp = itemRegistry.getItem(TEST_ITEM_NAME);
} catch (ItemNotFoundException e) {
tmp = null;
}
assertNotNull(tmp);
return tmp;
});
return waitForAssert(() -> {
final State testItemState = testItem.getState();
if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_STRING)) {
assertThat(testItemState, is(instanceOf(StringType.class)));
} else if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_DATE_TIME)) {
assertThat(testItemState, is(instanceOf(DateTimeType.class)));
}
return testItemState;
}, 3 * DFL_TIMEOUT, 2 * DFL_SLEEP_TIME);
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class SayCommandTest method testSayCommand.
@Test
public void testSayCommand() throws IOException {
String[] methodParameters = new String[2];
methodParameters[0] = SUBCMD_SAY;
if (defaultTTSService != null) {
Dictionary<String, Object> config = new Hashtable<String, Object>();
config.put(CONFIG_DEFAULT_TTS, defaultTTSService);
ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class);
String pid = "org.eclipse.smarthome.voice";
Configuration configuration = configAdmin.getConfiguration(pid);
configuration.update(config);
}
if (TTSServiceMockShouldBeRegistered) {
registerService(ttsService);
}
if (shouldItemsBePassed) {
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
ManagedThingProvider managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertNotNull(managedThingProvider);
ItemRegistry itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
Item item = new StringItem("itemName");
if (shouldItemsBeRegistered) {
itemRegistry.add(item);
}
methodParameters[1] = "%" + item.getName() + "%";
if (shouldMultipleItemsBeRegistered) {
Item item1 = new StringItem("itemName1");
itemRegistry.add(item1);
Item item2 = new StringItem("itemName2");
itemRegistry.add(item2);
Item item3 = new StringItem("itemName3");
itemRegistry.add(item3);
methodParameters[1] = "%itemName.%";
}
} else {
methodParameters[1] = "hello";
}
extensionService.execute(methodParameters, console);
assertThat(sink.isStreamProcessed(), is(shouldStreamBeExpected));
}
Aggregations