2 * Copyright (c) 2010-2024 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.pushsafer.internal.config;
15 import static org.openhab.binding.pushsafer.internal.PushsaferBindingConstants.*;
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.pushsafer.internal.dto.Icon;
27 import org.openhab.binding.pushsafer.internal.dto.Sound;
28 import org.openhab.binding.pushsafer.internal.handler.PushsaferAccountHandler;
29 import org.openhab.core.config.core.ConfigOptionProvider;
30 import org.openhab.core.config.core.ParameterOption;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerService;
33 import org.osgi.service.component.annotations.Component;
36 * The {@link PushsaferConfigOptionProvider} class contains fields mapping thing configuration parameters.
38 * @author Kevin Siml - Initial contribution, forked from Christoph Weitkamp
40 @Component(service = ConfigOptionProvider.class)
42 public class PushsaferConfigOptionProvider implements ConfigOptionProvider, ThingHandlerService {
44 private @Nullable PushsaferAccountHandler accountHandler;
47 public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
48 @Nullable Locale locale) {
49 PushsaferAccountHandler localAccountHandler = accountHandler;
50 if (localAccountHandler != null) {
51 if (PUSHSAFER_ACCOUNT.getAsString().equals(uri.getSchemeSpecificPart()) && CONFIG_SOUND.equals(param)) {
52 List<Sound> sounds = localAccountHandler.getSounds();
53 if (!sounds.isEmpty()) {
54 return sounds.stream().map(Sound::getAsParameterOption)
55 .sorted(Comparator.comparing(ParameterOption::getLabel))
56 .collect(Collectors.toUnmodifiableList());
59 if (PUSHSAFER_ACCOUNT.getAsString().equals(uri.getSchemeSpecificPart()) && CONFIG_ICON.equals(param)) {
60 List<Icon> icons = localAccountHandler.getIcons();
61 if (!icons.isEmpty()) {
62 return icons.stream().map(Icon::getAsParameterOption)
63 .sorted(Comparator.comparing(ParameterOption::getLabel))
64 .collect(Collectors.toUnmodifiableList());
72 public void setThingHandler(@Nullable ThingHandler handler) {
73 this.accountHandler = (PushsaferAccountHandler) handler;
77 public @Nullable ThingHandler getThingHandler() {
78 return accountHandler;