]> git.basschouten.com Git - openhab-addons.git/blob
f0964ce18407d018b50cb37221f41b6f5848aa18
[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         String accountParameterUrl = "thing-type:" + ChatGPTBindingConstants.THING_TYPE_ACCOUNT.getAsString();
43         if (accountParameterUrl.equals(uri.toString())) {
44             if ("model".equals(param)) {
45                 List<ParameterOption> options = new ArrayList<>();
46                 if (thingHandler instanceof ChatGPTHandler chatGPTHandler) {
47                     chatGPTHandler.getModels().forEach(model -> options.add(new ParameterOption(model, model)));
48                 }
49                 return options;
50             }
51         }
52         return null;
53     }
54
55     @Override
56     public void setThingHandler(ThingHandler handler) {
57         this.thingHandler = handler;
58     }
59
60     @Override
61     public @Nullable ThingHandler getThingHandler() {
62         return thingHandler;
63     }
64
65     @Override
66     public void activate() {
67     }
68 }