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