Skip to content

Commit

Permalink
minor auto review
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
  • Loading branch information
GiviMAD committed Dec 3, 2023
1 parent 3d2a036 commit b5fc996
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Expand Up @@ -64,9 +64,9 @@
@NonNullByDefault
@Component(service = HumanLanguageInterpreter.class)
public class StandardInterpreter extends AbstractRuleBasedInterpreter {
public static final String VOICE_SYSTEM_NAMESPACE = "voice-system";
private Logger logger = LoggerFactory.getLogger(StandardInterpreter.class);
private final ItemRegistry itemRegistry;
private final String metadataNamespace = "voice-system";
private final MetadataRegistry metadataRegistry;

@Activate
Expand Down Expand Up @@ -462,7 +462,7 @@ private List<Rule> createItemDescriptionRules(CreateItemDescriptionRule creator,
}

private List<Rule> createItemMetadataRules(Locale locale, Item item) {
var interpreterMetadata = metadataRegistry.get(new MetadataKey(metadataNamespace, item.getName()));
var interpreterMetadata = metadataRegistry.get(new MetadataKey(VOICE_SYSTEM_NAMESPACE, item.getName()));
if (interpreterMetadata == null) {
return List.of();
}
Expand Down
Expand Up @@ -825,8 +825,8 @@ protected String executeSingle(ResourceBundle language, String[] labelFragments,
*
* @param language resource bundle used for producing localized response texts
* @param itemCommandSupplier the rule command supplier.
* @param itemFilter to filter compatible items
* @param itemCommandSupplier allows resolve command value
* @param itemFilter to filter compatible items.
* @param context to propagate the interpretation context.
* @return response text
* @throws InterpretationException in case that there is no or more than on item matching the fragments
*/
Expand Down Expand Up @@ -1572,7 +1572,7 @@ public static ItemFilter forItems(Set<Item> item) {

public static ItemFilter forSimilarItem(Item item, @Nullable Metadata semantic) {
return new ItemFilter(Set.of(), Set.of(item.getName()), item.getTags(),
semantic != null && semantic.getValue() != null ? Set.of(semantic.getValue()) : Set.of());
semantic != null ? Set.of(semantic.getValue()) : Set.of());
}
}
}
Expand Up @@ -17,6 +17,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.openhab.core.voice.internal.text.StandardInterpreter.VOICE_SYSTEM_NAMESPACE;
import static org.openhab.core.voice.text.AbstractRuleBasedInterpreter.IS_SILENT_CONFIGURATION;
import static org.openhab.core.voice.text.AbstractRuleBasedInterpreter.IS_TEMPLATE_CONFIGURATION;

Expand Down Expand Up @@ -139,7 +140,8 @@ public void allowUseItemSynonyms() throws InterpretationException {
MetadataKey computerMetadataKey = new MetadataKey("synonyms", computerItem.getName());
when(metadataRegistryMock.get(computerMetadataKey))
.thenReturn(new Metadata(computerMetadataKey, "PC,Bedroom PC", null));
when(metadataRegistryMock.get(new MetadataKey("voice-system", computerItem.getName()))).thenReturn(null);
when(metadataRegistryMock.get(new MetadataKey(VOICE_SYSTEM_NAMESPACE, computerItem.getName())))
.thenReturn(null);
List<Item> items = List.of(computerItem);
when(itemRegistryMock.getItems()).thenReturn(items);
assertEquals(OK_RESPONSE, standardInterpreter.interpret(Locale.ENGLISH, "turn off computer"));
Expand Down Expand Up @@ -203,7 +205,7 @@ public void allowUseCustomItemCommands() throws InterpretationException {
}
};
tvItem.setLabel("tv");
MetadataKey voiceMetadataKey = new MetadataKey("voice-system", tvItem.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, tvItem.getName());
when(metadataRegistryMock.get(voiceMetadataKey))
.thenReturn(new Metadata(voiceMetadataKey, "watch|play $cmd$ on|at the? $name$", null));
List<Item> items = List.of(tvItem);
Expand All @@ -227,7 +229,7 @@ public void allowUseCustomCommandCommands() throws InterpretationException {
return getCommandDescription();
}
};
MetadataKey voiceMetadataKey = new MetadataKey("voice-system", tvItem.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, tvItem.getName());
when(metadataRegistryMock.get(voiceMetadataKey))
.thenReturn(new Metadata(voiceMetadataKey, "watch|play $cmd$ on|at the? tv", null));
List<Item> items = List.of(tvItem);
Expand All @@ -242,7 +244,7 @@ public void allowUseCustomCommandCommands() throws InterpretationException {
public void allowUseCustomItemDynamicCommands() throws InterpretationException {
var tvItem = new StringItem("tv");
tvItem.setLabel("tv");
MetadataKey voiceMetadataKey = new MetadataKey("voice-system", tvItem.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, tvItem.getName());
when(metadataRegistryMock.get(voiceMetadataKey))
.thenReturn(new Metadata(voiceMetadataKey, "watch|play $*$ on|at the? $name$", null));
List<Item> items = List.of(tvItem);
Expand All @@ -257,7 +259,7 @@ public void allowUseCustomItemDynamicCommands() throws InterpretationException {
public void allowUseCommandsWithoutAnswer() throws InterpretationException {
var tvItem = new StringItem("tv");
tvItem.setLabel("tv");
MetadataKey voiceMetadataKey = new MetadataKey("voice-system", tvItem.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, tvItem.getName());
HashMap<String, Object> configuration = new HashMap<>();
configuration.put(IS_SILENT_CONFIGURATION, true);
when(metadataRegistryMock.get(voiceMetadataKey))
Expand All @@ -278,7 +280,7 @@ public void allowUseCommandsFromTemplate() throws InterpretationException {
var tvItem = new StringItem("tv");
tvItem.setLabel("tv");
virtualItem.addTag("tv");
MetadataKey voiceMetadataKey = new MetadataKey("voice-system", virtualItem.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, virtualItem.getName());
HashMap<String, Object> configuration = new HashMap<>();
configuration.put(IS_TEMPLATE_CONFIGURATION, true);
when(metadataRegistryMock.get(voiceMetadataKey))
Expand All @@ -294,7 +296,7 @@ public void allowUseCommandsFromTemplate() throws InterpretationException {
@Test
public void allowUseCustomDynamicCommands() throws InterpretationException {
var virtualItem = new StringItem("tv");
MetadataKey voiceMetadataKey = new MetadataKey("voice-system", virtualItem.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, virtualItem.getName());
when(metadataRegistryMock.get(voiceMetadataKey))
.thenReturn(new Metadata(voiceMetadataKey, "watch|play $*$", null));
List<Item> items = List.of(virtualItem);
Expand Down Expand Up @@ -324,7 +326,7 @@ public List<CommandOption> getCommandOptions() {
return getCommandDescription();
}
};
MetadataKey voiceMetadataKey = new MetadataKey("voice-system", virtualItem.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, virtualItem.getName());
when(metadataRegistryMock.get(voiceMetadataKey))
.thenReturn(new Metadata(voiceMetadataKey, "watch|play $*$ on|at? the? tv", null));
List<Item> items = List.of(virtualItem);
Expand Down

0 comments on commit b5fc996

Please sign in to comment.