2 * Copyright (c) 2010-2023 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.solaredge.internal.command;
15 import static org.openhab.binding.solaredge.internal.SolarEdgeBindingConstants.*;
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;
26 * checks validity of the api key by accessing the webinterface
28 * @author Alexander Friese - initial contribution
31 public class PublicApiKeyCheck extends AbstractCommand implements SolarEdgeCommand {
33 public PublicApiKeyCheck(SolarEdgeHandler handler, StatusUpdateListener listener) {
34 super(handler.getConfiguration(), listener);
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);
44 return requestToPrepare;
48 protected String getURL() {
49 return PUBLIC_DATA_API_URL + config.getSolarId() + PUBLIC_DATA_API_URL_LIVE_DATA_SUFFIX;
53 public void onComplete(@Nullable Result result) {
54 updateListenerStatus();