use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class GenericItemProvider method modelChanged.
@Override
public void modelChanged(String modelName, EventType type) {
if (modelName.endsWith("items")) {
switch(type) {
case ADDED:
case MODIFIED:
Map<String, Item> oldItems = toItemMap(itemsMap.get(modelName));
Map<String, Item> newItems = toItemMap(getItemsFromModel(modelName));
itemsMap.put(modelName, newItems.values());
for (Item newItem : newItems.values()) {
if (oldItems.containsKey(newItem.getName())) {
Item oldItem = oldItems.get(newItem.getName());
if (hasItemChanged(oldItem, newItem)) {
notifyListenersAboutUpdatedElement(oldItem, newItem);
}
} else {
notifyListenersAboutAddedElement(newItem);
}
}
processBindingConfigsFromModel(modelName, type);
for (Item oldItem : oldItems.values()) {
if (!newItems.containsKey(oldItem.getName())) {
notifyListenersAboutRemovedElement(oldItem);
this.stateDescriptions.remove(oldItem.getName());
}
}
break;
case REMOVED:
processBindingConfigsFromModel(modelName, type);
Collection<Item> itemsFromModel = getItemsFromModel(modelName);
itemsMap.remove(modelName);
for (Item item : itemsFromModel) {
notifyListenersAboutRemovedElement(item);
}
break;
}
}
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class FSInternetRadioHandlerJavaTest method volumechannelUpdatedAbsIncDec.
/**
* Verify the volume is updated through the CHANNEL_VOLUME_ABSOLUTE using INCREASE and DECREASE commands.
*/
@Test
public void volumechannelUpdatedAbsIncDec() {
String absoluteVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_ABSOLUTE;
String absoluteAcceptedItemType = acceptedItemTypes.get(absoluteVolumeChannelID);
createChannel(DEFAULT_THING_UID, absoluteVolumeChannelID, absoluteAcceptedItemType);
Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
testRadioThingConsideringConfiguration(radioThing);
turnTheRadioOn(radioThing);
ChannelUID absoluteVolumeChannelUID = getChannelUID(radioThing, absoluteVolumeChannelID);
Item volumeTestItem = initializeItem(absoluteVolumeChannelUID, DEFAULT_TEST_ITEM_NAME, absoluteAcceptedItemType);
testChannelWithINCREASEAndDECREASECommands(absoluteVolumeChannelUID, volumeTestItem);
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class FSInternetRadioHandlerJavaTest method volumeChannelUpdatedPercUpDown.
/**
* Verify the volume is updated through the CHANNEL_VOLUME_PERCENT using UP and DOWN commands.
*/
@Test
public void volumeChannelUpdatedPercUpDown() {
/*
* The volume is set through the CHANNEL_VOLUME_PERCENT in order to check if
* the absolute volume will be updated properly.
*/
String absoluteVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_ABSOLUTE;
String absoluteAcceptedItemType = acceptedItemTypes.get(absoluteVolumeChannelID);
createChannel(DEFAULT_THING_UID, absoluteVolumeChannelID, absoluteAcceptedItemType);
String percentVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_PERCENT;
String percentAcceptedItemType = acceptedItemTypes.get(percentVolumeChannelID);
createChannel(DEFAULT_THING_UID, percentVolumeChannelID, percentAcceptedItemType);
Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
testRadioThingConsideringConfiguration(radioThing);
turnTheRadioOn(radioThing);
ChannelUID absoluteVolumeChannelUID = getChannelUID(radioThing, absoluteVolumeChannelID);
Item volumeTestItem = initializeItem(absoluteVolumeChannelUID, DEFAULT_TEST_ITEM_NAME, absoluteAcceptedItemType);
ChannelUID percentVolumeChannelUID = getChannelUID(radioThing, percentVolumeChannelID);
testChannelWithUPAndDOWNCommands(percentVolumeChannelUID, volumeTestItem);
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class FSInternetRadioHandlerJavaTest method volumeChannelUpdatedPercIncDec.
/**
* Verify the volume is updated through the CHANNEL_VOLUME_PERCENT using INCREASE and DECREASE commands.
*/
@Test
public void volumeChannelUpdatedPercIncDec() {
/*
* The volume is set through the CHANNEL_VOLUME_PERCENT in order to check if
* the absolute volume will be updated properly.
*/
String absoluteVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_ABSOLUTE;
String absoluteAcceptedItemType = acceptedItemTypes.get(absoluteVolumeChannelID);
createChannel(DEFAULT_THING_UID, absoluteVolumeChannelID, absoluteAcceptedItemType);
String percentVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_PERCENT;
String percentAcceptedItemType = acceptedItemTypes.get(percentVolumeChannelID);
createChannel(DEFAULT_THING_UID, percentVolumeChannelID, percentAcceptedItemType);
Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
testRadioThingConsideringConfiguration(radioThing);
turnTheRadioOn(radioThing);
ChannelUID absoluteVolumeChannelUID = getChannelUID(radioThing, absoluteVolumeChannelID);
Item volumeTestItem = initializeItem(absoluteVolumeChannelUID, DEFAULT_TEST_ITEM_NAME, absoluteAcceptedItemType);
ChannelUID percentVolumeChannelUID = getChannelUID(radioThing, percentVolumeChannelID);
testChannelWithINCREASEAndDECREASECommands(percentVolumeChannelUID, volumeTestItem);
}
use of org.eclipse.smarthome.core.items.Item in project habot by ghys.
the class ActivateObjectSkill method interpret.
@Override
public IntentInterpretation interpret(Intent intent, String language) {
IntentInterpretation interpretation = new IntentInterpretation();
Set<Item> matchedItems = findItems(intent);
if (matchedItems == null || matchedItems.isEmpty()) {
interpretation.setAnswer(answerFormatter.getRandomAnswer("nothing_activated"));
interpretation.setHint(answerFormatter.getStandardTagHint(intent.getEntities()));
} else {
interpretation.setMatchedItems(matchedItems);
// filter out the items which can't receive an ON command
List<Item> filteredItems = matchedItems.stream().filter(i -> i.getAcceptedCommandTypes().contains(OnOffType.class)).collect(Collectors.toList());
interpretation.setCard(cardBuilder.buildCard(intent, filteredItems));
if (filteredItems.isEmpty()) {
interpretation.setAnswer(answerFormatter.getRandomAnswer("nothing_activated"));
interpretation.setHint(answerFormatter.getStandardTagHint(intent.getEntities()));
} else if (filteredItems.size() == 1) {
if (filteredItems.get(0).getState().equals(OnOffType.ON)) {
interpretation.setAnswer(answerFormatter.getRandomAnswer("switch_already_on"));
} else {
eventPublisher.post(ItemEventFactory.createCommandEvent(filteredItems.get(0).getName(), OnOffType.ON));
interpretation.setAnswer(answerFormatter.getRandomAnswer("switch_activated"));
}
} else {
for (Item item : filteredItems) {
eventPublisher.post(ItemEventFactory.createCommandEvent(item.getName(), OnOffType.ON));
}
interpretation.setAnswer(answerFormatter.getRandomAnswer("switches_activated", ImmutableMap.of("count", String.valueOf(filteredItems.size()))));
}
}
return interpretation;
}
Aggregations