use of org.eclipse.smarthome.core.items.Item in project habot by ghys.
the class HistoryWeeklyGraphSkill 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("answer_nothing_found"));
interpretation.setHint(answerFormatter.getStandardTagHint(intent.getEntities()));
} else {
interpretation.setMatchedItems(matchedItems);
String period = "W";
if (intent.getEntities().containsKey("period")) {
period = intent.getEntities().get("period").concat(period);
}
interpretation.setCard(this.cardBuilder.buildChartCard(intent, matchedItems, period));
}
interpretation.setAnswer(answerFormatter.getRandomAnswer("info_found_simple"));
return interpretation;
}
use of org.eclipse.smarthome.core.items.Item in project habot by ghys.
the class CardBuilder method buildChartCard.
/**
* Builds a card with a chart from an intent and matched items
*
* @param intent the intent
* @param matchedItems the matched items
* @param period the chart period
* @return the card
*/
public Card buildChartCard(Intent intent, Collection<Item> matchedItems, String period) {
Set<String> tags = intent.getEntities().entrySet().stream().map(e -> e.getKey() + ":" + e.getValue()).collect(Collectors.toSet());
Card card = new Card("HbCard");
card.addTags(tags);
card.setEphemeral(true);
card.addConfig("bigger", true);
card.updateTimestamp();
if (matchedItems.size() == 1) {
Item item = matchedItems.stream().findFirst().get();
card.setTitle(item.getLabel());
card.setSubtitle(item.getName());
} else {
card.setTitle(getCardTitleFromGroupLabels(tags));
// TODO: i18n
card.setSubtitle(matchedItems.size() + " items");
}
Component chart = new Component("HbChartImage");
chart.addConfig("items", matchedItems.stream().map(i -> i.getName()).collect(Collectors.toList()).toArray(new String[0]));
chart.addConfig("period", period);
Component analyzeButton = new Component("HbAnalyzeActionButton");
analyzeButton.addConfig("items", chart.getConfig().get("items"));
analyzeButton.addConfig("period", chart.getConfig().get("period"));
card.addComponent("media", chart);
card.addComponent("actions", analyzeButton);
cardRegistry.add(card);
return card;
}
use of org.eclipse.smarthome.core.items.Item in project habot by ghys.
the class SetValueSkill 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("answer_nothing_found"));
interpretation.setHint(answerFormatter.getStandardTagHint(intent.getEntities()));
} else {
interpretation.setMatchedItems(matchedItems);
if (intent.getEntities().containsKey("color")) {
interpretSetColor(intent, language, interpretation, matchedItems);
} else if (intent.getEntities().containsKey("value")) {
interpretSetValue(intent, language, interpretation, matchedItems);
} else {
interpretation.setAnswer(answerFormatter.getRandomAnswer("value_misunderstood"));
}
}
return interpretation;
}
use of org.eclipse.smarthome.core.items.Item in project habot by ghys.
the class HistoryMonthlyGraphSkill 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("answer_nothing_found"));
interpretation.setHint(answerFormatter.getStandardTagHint(intent.getEntities()));
} else {
interpretation.setMatchedItems(matchedItems);
String period = "M";
if (intent.getEntities().containsKey("period")) {
period = intent.getEntities().get("period").concat(period);
}
interpretation.setCard(this.cardBuilder.buildChartCard(intent, matchedItems, period));
}
interpretation.setAnswer(answerFormatter.getRandomAnswer("info_found_simple"));
return interpretation;
}
use of org.eclipse.smarthome.core.items.Item in project habot by ghys.
the class SetValueSkill method interpretSetColor.
private void interpretSetColor(Intent intent, String language, IntentInterpretation interpretation, Set<Item> matchedItems) {
String colorString = intent.getEntities().get("color");
// filter out the items which can't receive an HSB command
List<Item> filteredItems = matchedItems.stream().filter(i -> i.getAcceptedCommandTypes().contains(HSBType.class)).collect(Collectors.toList());
String hsbValue;
try {
ResourceBundle colors = ResourceBundle.getBundle("colors", new Locale(language));
hsbValue = colors.getString("color_" + colorString);
} catch (MissingResourceException e) {
interpretation.setAnswer(answerFormatter.getRandomAnswer("set_color_unknown", ImmutableMap.of("color", colorString)));
return;
}
if (filteredItems.isEmpty()) {
interpretation.setAnswer(answerFormatter.getRandomAnswer("set_color_no_item", ImmutableMap.of("color", colorString)));
interpretation.setHint(answerFormatter.getStandardTagHint(intent.getEntities()));
} else if (filteredItems.size() == 1) {
interpretation.setCard(cardBuilder.buildCard(intent, filteredItems));
eventPublisher.post(ItemEventFactory.createCommandEvent(filteredItems.get(0).getName(), new HSBType(hsbValue)));
interpretation.setAnswer(answerFormatter.getRandomAnswer("set_color_single", ImmutableMap.of("color", colorString)));
} else {
interpretation.setCard(cardBuilder.buildCard(intent, filteredItems));
for (Item item : filteredItems) {
eventPublisher.post(ItemEventFactory.createCommandEvent(item.getName(), new HSBType(hsbValue)));
}
interpretation.setAnswer(answerFormatter.getRandomAnswer("set_color_multiple", ImmutableMap.of("count", String.valueOf(filteredItems.size()), "color", colorString)));
}
}
Aggregations