]> git.basschouten.com Git - openhab-addons.git/blob
ed956a60f491af4a1c48d9c3635b97d58321ea36
[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.solaredge.internal.command;
14
15 import static org.openhab.binding.solaredge.internal.SolarEdgeBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.api.Request;
20 import org.eclipse.jetty.client.api.Result;
21 import org.eclipse.jetty.http.HttpMethod;
22 import org.openhab.binding.solaredge.internal.callback.AbstractCommandCallback;
23 import org.openhab.binding.solaredge.internal.connector.StatusUpdateListener;
24 import org.openhab.binding.solaredge.internal.handler.SolarEdgeHandler;
25
26 /**
27  * checks validity of the api key by accessing the webinterface
28  *
29  * @author Alexander Friese - initial contribution
30  */
31 @NonNullByDefault
32 public class PublicApiKeyCheck extends AbstractCommandCallback implements SolarEdgeCommand {
33
34     public PublicApiKeyCheck(SolarEdgeHandler handler, StatusUpdateListener listener) {
35         super(handler.getConfiguration(), listener);
36     }
37
38     @Override
39     protected Request prepareRequest(Request requestToPrepare) {
40         // as a key is used no real login is to be done here. It is just checked if a protected page can be retrieved
41         // and therefore the key is valid.
42         requestToPrepare.followRedirects(false);
43         requestToPrepare.method(HttpMethod.GET);
44
45         return requestToPrepare;
46     }
47
48     @Override
49     protected String getURL() {
50         return PUBLIC_DATA_API_URL + config.getSolarId() + PUBLIC_DATA_API_URL_LIVE_DATA_SUFFIX;
51     }
52
53     @Override
54     public void onComplete(@Nullable Result result) {
55         updateListenerStatus();
56     }
57 }