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.callback.AbstractCommandCallback;
23 import org.openhab.binding.solaredge.internal.connector.StatusUpdateListener;
24 import org.openhab.binding.solaredge.internal.handler.SolarEdgeHandler;
27 * checks validity of the token by accessing the webinterface
29 * @author Alexander Friese - initial contribution
32 public class PrivateApiTokenCheck extends AbstractCommandCallback implements SolarEdgeCommand {
34 public PrivateApiTokenCheck(SolarEdgeHandler handler, StatusUpdateListener listener) {
35 super(handler.getConfiguration(), listener);
39 protected Request prepareRequest(Request requestToPrepare) {
40 // as a token 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 token is valid.
42 requestToPrepare.followRedirects(false);
43 requestToPrepare.method(HttpMethod.GET);
45 return requestToPrepare;
49 protected String getURL() {
50 return PRIVATE_DATA_API_URL + config.getSolarId() + PRIVATE_DATA_API_URL_LIVE_DATA_SUFFIX;
54 public void onComplete(@Nullable Result result) {
55 updateListenerStatus();