]> git.basschouten.com Git - openhab-addons.git/blob
9057398de3ac303195e25fd76b56097c84177502
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.chatgpt.internal;
14
15 import java.net.URI;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.List;
19 import java.util.Locale;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.config.core.ConfigOptionProvider;
24 import org.openhab.core.config.core.ParameterOption;
25 import org.openhab.core.thing.binding.ThingHandler;
26 import org.openhab.core.thing.binding.ThingHandlerService;
27
28 /**
29  * The {@link ChatGPTModelOptionProvider} provides the available models from OpenAI as options for the channel
30  * configuration.
31  *
32  * @author Kai Kreuzer - Initial contribution
33  */
34 @NonNullByDefault
35 public class ChatGPTModelOptionProvider implements ThingHandlerService, ConfigOptionProvider {
36
37     private @Nullable ThingHandler thingHandler;
38
39     @Override
40     public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
41             @Nullable Locale locale) {
42         if ("model".equals(param)) {
43             List<ParameterOption> options = new ArrayList<>();
44             if (thingHandler instanceof ChatGPTHandler chatGPTHandler) {
45                 chatGPTHandler.getModels().forEach(model -> options.add(new ParameterOption(model, model)));
46             }
47             return options;
48         } else {
49             return null;
50         }
51     }
52
53     @Override
54     public void setThingHandler(ThingHandler handler) {
55         this.thingHandler = handler;
56     }
57
58     @Override
59     public @Nullable ThingHandler getThingHandler() {
60         return thingHandler;
61     }
62
63     @Override
64     public void activate() {
65     }
66 }