Skip to content

Commit

Permalink
improvments
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
  • Loading branch information
J-N-K committed Oct 6, 2020
1 parent 5c5571b commit 89f8a64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
@Component(service = { ThingHandlerFactory.class }, configurationPid = "binding.tr064")
public class Tr064HandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
.concat(org.openhab.binding.tr064.internal.Tr064RootHandler.SUPPORTED_THING_TYPES.stream(),
Tr064SubHandler.SUPPORTED_THING_TYPES.stream())
.concat(Tr064RootHandler.SUPPORTED_THING_TYPES.stream(), Tr064SubHandler.SUPPORTED_THING_TYPES.stream())
.collect(Collectors.toSet());

private final HttpClient httpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -89,18 +90,28 @@ public void unregisterPhonebookProvider(PhonebookProvider phonebookProvider) {
}
}

private Stream<ParameterOption> createPhonebookList(Map.Entry<ThingUID, PhonebookProvider> entry) {
String thingUid = UIDUtils.encode(entry.getKey().toString());
String thingName = entry.getValue().getFriendlyName();

Stream<ParameterOption> parameterOptions = entry.getValue().getPhonebooks().stream()
.map(phonebook -> new ParameterOption(thingUid + ":" + UIDUtils.encode(phonebook.getName()),
thingName + " " + phonebook.getName()));

if (parameterOptions.count() > 0) {
return Stream.concat(Stream.of(new ParameterOption(thingUid, thingName)), parameterOptions);
}

return parameterOptions;
}

@Override
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String s, @Nullable String s1,
@Nullable Locale locale) {
if (uri.getSchemeSpecificPart().equals(PhonebookProfile.PHONEBOOK_PROFILE_TYPE_UID.toString())
&& s.equals(PhonebookProfile.PHONEBOOK_PARAM)) {
return phonebookProviders.entrySet().stream().flatMap(e -> {
String thingUid = UIDUtils.encode(e.getKey().toString());
String thingName = e.getValue().getFriendlyName();
return e.getValue().getPhonebooks().stream()
.map(phonebook -> new ParameterOption(thingUid + ":" + UIDUtils.encode(phonebook.getName()),
thingName + " " + phonebook.getName()));
}).collect(Collectors.toSet());
return phonebookProviders.entrySet().stream().flatMap(this::createPhonebookList)
.collect(Collectors.toSet());
}
return null;
}
Expand Down

0 comments on commit 89f8a64

Please sign in to comment.