mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-30 00:51:58 +01:00
fix code violation
Signed-off-by: Laurent ARNAL <laurent@clae.net>
This commit is contained in:
parent
6f8b6a621a
commit
a84023ee3c
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
* Copyright (c) 2010-2024 Contributors to the openHAB project
|
||||||
*
|
*
|
||||||
* See the NOTICE file(s) distributed with this work for additional
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
* information.
|
* information.
|
||||||
@ -22,7 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
public interface LinkyAccountHandler {
|
public interface LinkyAccountHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns true if the Spotify Bridge is authorized.
|
* @return Returns true if the Linky Bridge is authorized.
|
||||||
*/
|
*/
|
||||||
boolean isAuthorized();
|
boolean isAuthorized();
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
* Copyright (c) 2010-2024 Contributors to the openHAB project
|
||||||
*
|
*
|
||||||
* See the NOTICE file(s) distributed with this work for additional
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
* information.
|
* information.
|
||||||
@ -51,8 +51,6 @@ public class LinkyAuthService {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(LinkyAuthService.class);
|
private final Logger logger = LoggerFactory.getLogger(LinkyAuthService.class);
|
||||||
|
|
||||||
// private final List<SpotifyAccountHandler> handlers = new ArrayList<>();
|
|
||||||
|
|
||||||
private @NonNullByDefault({}) HttpService httpService;
|
private @NonNullByDefault({}) HttpService httpService;
|
||||||
private @NonNullByDefault({}) BundleContext bundleContext;
|
private @NonNullByDefault({}) BundleContext bundleContext;
|
||||||
private @Nullable LinkyAccountHandler accountHandler;
|
private @Nullable LinkyAccountHandler accountHandler;
|
||||||
@ -66,7 +64,7 @@ public class LinkyAuthService {
|
|||||||
httpService.registerResources(LinkyBindingConstants.LINKY_ALIAS + LinkyBindingConstants.LINKY_IMG_ALIAS,
|
httpService.registerResources(LinkyBindingConstants.LINKY_ALIAS + LinkyBindingConstants.LINKY_IMG_ALIAS,
|
||||||
"web", null);
|
"web", null);
|
||||||
} catch (NamespaceException | ServletException | IOException e) {
|
} catch (NamespaceException | ServletException | IOException e) {
|
||||||
logger.warn("Error during spotify servlet startup", e);
|
logger.warn("Error during linky servlet startup", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +75,7 @@ public class LinkyAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link SpotifyAuthServlet}.
|
* Creates a new {@link LinkyAuthServlet}.
|
||||||
*
|
*
|
||||||
* @return the newly created servlet
|
* @return the newly created servlet
|
||||||
* @throws IOException thrown when an HTML template could not be read
|
* @throws IOException thrown when an HTML template could not be read
|
||||||
@ -107,13 +105,13 @@ public class LinkyAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call with Spotify redirect uri returned State and Code values to get the refresh and access tokens and persist
|
* Call with Linky redirect uri returned State and Code values to get the refresh and access tokens and persist
|
||||||
* these values
|
* these values
|
||||||
*
|
*
|
||||||
* @param servletBaseURL the servlet base, which will be the Spotify redirect url
|
* @param servletBaseURL the servlet base, which will be the Linky redirect url
|
||||||
* @param state The Spotify returned state value
|
* @param state The Linky returned state value
|
||||||
* @param code The Spotify returned code value
|
* @param code The Linky returned code value
|
||||||
* @return returns the name of the Spotify user that is authorized
|
* @return returns the name of the Linky user that is authorized
|
||||||
*/
|
*/
|
||||||
public String authorize(String servletBaseURL, String state, String code) {
|
public String authorize(String servletBaseURL, String state, String code) {
|
||||||
LinkyAccountHandler accountHandler = getLinkyAccountHandler();
|
LinkyAccountHandler accountHandler = getLinkyAccountHandler();
|
||||||
@ -148,49 +146,6 @@ public class LinkyAuthService {
|
|||||||
return this.accountHandler;
|
return this.accountHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param listener Adds the given handler
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* public void addSpotifyAccountHandler(SpotifyAccountHandler listener) {
|
|
||||||
* if (!handlers.contains(listener)) {
|
|
||||||
* handlers.add(listener);
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param handler Removes the given handler
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* public void removeSpotifyAccountHandler(SpotifyAccountHandler handler) {
|
|
||||||
* handlers.remove(handler);
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Returns all {@link SpotifyAccountHandler}s.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* public List<SpotifyAccountHandler> getSpotifyAccountHandlers() {
|
|
||||||
* return handlers;
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the {@link SpotifyAccountHandler} that matches the given thing UID.
|
|
||||||
*
|
|
||||||
* @param thingUID UID of the thing to match the handler with
|
|
||||||
* @return the {@link SpotifyAccountHandler} matching the thing UID or null
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* private @Nullable SpotifyAccountHandler getSpotifyAuthListener(String thingUID) {
|
|
||||||
* final Optional<SpotifyAccountHandler> maybeListener = handlers.stream().filter(l -> l.equalsThingUID(thingUID))
|
|
||||||
* .findFirst();
|
|
||||||
* return maybeListener.isPresent() ? maybeListener.get() : null;
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Reference
|
@Reference
|
||||||
protected void setHttpService(HttpService httpService) {
|
protected void setHttpService(HttpService httpService) {
|
||||||
this.httpService = httpService;
|
this.httpService = httpService;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
* Copyright (c) 2010-2024 Contributors to the openHAB project
|
||||||
*
|
*
|
||||||
* See the NOTICE file(s) distributed with this work for additional
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
* information.
|
* information.
|
||||||
@ -105,13 +105,13 @@ public class LinkyAuthServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a possible call from Enedis to the redirect_uri. If that is the case Spotify will pass the authorization
|
* Handles a possible call from Enedis to the redirect_uri. If that is the case Linky will pass the authorization
|
||||||
* codes via the url and these are processed. In case of an error this is shown to the user. If the user was
|
* codes via the url and these are processed. In case of an error this is shown to the user. If the user was
|
||||||
* authorized this is passed on to the handler. Based on all these different outcomes the HTML is generated to
|
* authorized this is passed on to the handler. Based on all these different outcomes the HTML is generated to
|
||||||
* inform the user.
|
* inform the user.
|
||||||
*
|
*
|
||||||
* @param replaceMap a map with key String values that will be mapped in the HTML templates.
|
* @param replaceMap a map with key String values that will be mapped in the HTML templates.
|
||||||
* @param servletBaseURL the servlet base, which should be used as the Spotify redirect_uri value
|
* @param servletBaseURL the servlet base, which should be used as the Linky redirect_uri value
|
||||||
* @param queryString the query part of the GET request this servlet is processing
|
* @param queryString the query part of the GET request this servlet is processing
|
||||||
*/
|
*/
|
||||||
private void handleLinkyRedirect(Map<String, String> replaceMap, String servletBaseURL,
|
private void handleLinkyRedirect(Map<String, String> replaceMap, String servletBaseURL,
|
||||||
@ -132,7 +132,7 @@ public class LinkyAuthServlet extends HttpServlet {
|
|||||||
// params.isEmpty() ? "" : String.format(HTML_META_REFRESH_CONTENT, servletBaseURL)
|
// params.isEmpty() ? "" : String.format(HTML_META_REFRESH_CONTENT, servletBaseURL)
|
||||||
|
|
||||||
if (!StringUtil.isBlank(reqError)) {
|
if (!StringUtil.isBlank(reqError)) {
|
||||||
logger.debug("Spotify redirected with an error: {}", reqError);
|
logger.debug("Linky redirected with an error: {}", reqError);
|
||||||
replaceMap.put(KEY_ERROR, String.format(HTML_ERROR, reqError));
|
replaceMap.put(KEY_ERROR, String.format(HTML_ERROR, reqError));
|
||||||
} else if (!StringUtil.isBlank(reqState)) {
|
} else if (!StringUtil.isBlank(reqState)) {
|
||||||
try {
|
try {
|
||||||
|
@ -73,7 +73,7 @@ public class LinkyBindingConstants {
|
|||||||
"r:locations:*", "w:locations:*", "x:locations:*", "r:scenes:*", "x:scenes:*", "r:rules:*", "w:rules:*",
|
"r:locations:*", "w:locations:*", "x:locations:*", "r:scenes:*", "x:scenes:*", "r:rules:*", "w:rules:*",
|
||||||
"r:installedapps", "w:installedapps").collect(Collectors.joining(" "));
|
"r:installedapps", "w:installedapps").collect(Collectors.joining(" "));
|
||||||
|
|
||||||
// List of Spotify services related urls, information
|
// List of Linky services related urls, information
|
||||||
public static final String LINKY_ACCOUNT_URL = "https://www.myelectricaldata.fr/";
|
public static final String LINKY_ACCOUNT_URL = "https://www.myelectricaldata.fr/";
|
||||||
public static final String LINKY_AUTHORIZE_URL = LINKY_ACCOUNT_URL + "v1/oauth2/authorize";
|
public static final String LINKY_AUTHORIZE_URL = LINKY_ACCOUNT_URL + "v1/oauth2/authorize";
|
||||||
public static final String LINKY_API_TOKEN_URL = LINKY_ACCOUNT_URL + "token";
|
public static final String LINKY_API_TOKEN_URL = LINKY_ACCOUNT_URL + "token";
|
||||||
|
@ -220,7 +220,7 @@ public class LinkyHandlerFactory extends BaseThingHandlerFactory implements Link
|
|||||||
else {
|
else {
|
||||||
String token = EnedisHttpApi.getToken(httpClient, clientId, reqCode);
|
String token = EnedisHttpApi.getToken(httpClient, clientId, reqCode);
|
||||||
|
|
||||||
logger.debug("token:" + token);
|
logger.debug("token: {}", token);
|
||||||
|
|
||||||
Collection<Thing> col = this.thingRegistry.getAll();
|
Collection<Thing> col = this.thingRegistry.getAll();
|
||||||
for (Thing thing : col) {
|
for (Thing thing : col) {
|
||||||
@ -244,18 +244,6 @@ public class LinkyHandlerFactory extends BaseThingHandlerFactory implements Link
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String updateProperties(AccessTokenResponse credentials) {
|
private String updateProperties(AccessTokenResponse credentials) {
|
||||||
/*
|
|
||||||
* if (spotifyApi != null) {
|
|
||||||
*
|
|
||||||
* final Me me = spotifyApi.getMe();
|
|
||||||
* final String user = me.getDisplayName() == null ? me.getId() : me.getDisplayName();
|
|
||||||
* final Map<String, String> props = editProperties();
|
|
||||||
*
|
|
||||||
* props.put(PROPERTY_SPOTIFY_USER, user);
|
|
||||||
* updateProperties(props);
|
|
||||||
* return user;
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user