2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.pushover.internal.config;
15 import static org.openhab.binding.pushover.internal.PushoverBindingConstants.*;
18 import java.util.Collection;
19 import java.util.Comparator;
20 import java.util.List;
21 import java.util.Locale;
22 import java.util.stream.Collectors;
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.openhab.binding.pushover.internal.dto.Sound;
27 import org.openhab.binding.pushover.internal.handler.PushoverAccountHandler;
28 import org.openhab.core.config.core.ConfigOptionProvider;
29 import org.openhab.core.config.core.ParameterOption;
30 import org.openhab.core.thing.binding.ThingHandler;
31 import org.openhab.core.thing.binding.ThingHandlerService;
32 import org.osgi.service.component.annotations.Component;
35 * The {@link PushoverConfigOptionProvider} class contains fields mapping thing configuration parameters.
37 * @author Christoph Weitkamp - Initial contribution
40 @Component(service = ConfigOptionProvider.class)
41 public class PushoverConfigOptionProvider implements ConfigOptionProvider, ThingHandlerService {
43 private @Nullable PushoverAccountHandler accountHandler;
46 public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
47 @Nullable Locale locale) {
48 PushoverAccountHandler localAccountHandler = accountHandler;
49 if (localAccountHandler != null && PUSHOVER_ACCOUNT.getAsString().equals(uri.getSchemeSpecificPart())
50 && CONFIG_SOUND.equals(param)) {
51 List<Sound> sounds = localAccountHandler.getSounds();
52 if (!sounds.isEmpty()) {
53 return sounds.stream().map(Sound::getAsParameterOption)
54 .sorted(Comparator.comparing(ParameterOption::getLabel))
55 .collect(Collectors.toUnmodifiableList());
62 public void setThingHandler(@Nullable ThingHandler handler) {
63 this.accountHandler = (PushoverAccountHandler) handler;
67 public @Nullable ThingHandler getThingHandler() {
68 return accountHandler;