diff --git a/bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexAuthServlet.java b/bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexAuthServlet.java index 4ee3318163562..f1c6440e0979d 100644 --- a/bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexAuthServlet.java +++ b/bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexAuthServlet.java @@ -121,7 +121,7 @@ private void handleRedirect(Map replaceMap, String servletBaseUR replaceMap.put(KEY_PAGE_REFRESH, params.isEmpty() ? "" : String.format(HTML_META_REFRESH_CONTENT, servletBaseURL)); - if (!reqError.isBlank()) { + if (reqError != null && !reqError.isBlank()) { logger.debug("Webex redirected with an error: {}", reqError); replaceMap.put(KEY_ERROR, String.format(HTML_ERROR, reqError)); } else if (!reqState.isBlank()) { @@ -172,12 +172,12 @@ private String formatAccount(String accountTemplate, WebexTeamsHandler handler, map.put(ACCOUNT_SHWOMSG, "u-show"); map.put(ACCOUNT_MSG, "Configure account."); } else if (handler.isAuthorized()) { - map.put(ACCOUNT_USER_ID, String.format(" (Authorized user: %s)", webexUser)); + map.put(ACCOUNT_USER_ID, String.format("Authorized user: %s", webexUser)); map.put(ACCOUNT_SHOWBTN, "u-hide"); map.put(ACCOUNT_SHWOMSG, "u-show"); map.put(ACCOUNT_MSG, "Authorized."); - } else if (!webexUser.isBlank()) { - map.put(ACCOUNT_USER_ID, String.format(" (Unauthorized user: %s)", webexUser)); + } else if (webexUser.isBlank()) { + map.put(ACCOUNT_USER_ID, "Unauthorized user"); map.put(ACCOUNT_SHOWBTN, "u-show"); map.put(ACCOUNT_SHWOMSG, "u-hide"); map.put(ACCOUNT_MSG, ""); diff --git a/bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexTeamsHandler.java b/bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexTeamsHandler.java index d5922259b98bb..4339b938f508b 100644 --- a/bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexTeamsHandler.java +++ b/bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexTeamsHandler.java @@ -70,7 +70,7 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe private @Nullable OAuthClientService authService; - private boolean configured = false; // is the handler instance properly configured? + private boolean configured; // is the handler instance properly configured? private volatile boolean active; // is the handler instance active? String accountType = ""; // bot or person? @@ -97,6 +97,7 @@ public Collection> getServices() { public void initialize() { logger.debug("Initializing thing {}", this.getThing().getUID()); active = true; + this.configured = false; config = getConfigAs(WebexTeamsConfiguration.class); final String token = config.token; @@ -210,6 +211,9 @@ protected String authorize(String redirectUri, String reqCode) throws WebexTeams public boolean isAuthorized() { final AccessTokenResponse accessTokenResponse = getAccessTokenResponse(); + if (accessTokenResponse == null) { + return false; + } if ("person".equals(this.accountType)) { return accessTokenResponse != null && accessTokenResponse.getAccessToken() != null @@ -287,7 +291,7 @@ private boolean refresh() { updateStatus(ThingStatus.ONLINE); return true; } catch (WebexTeamsException e) { - logger.warn("Failed to refresh: {}", e.getMessage()); + logger.warn("Failed to refresh: {}. Did you authorize?", e.getMessage()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); } return false; diff --git a/bundles/org.openhab.binding.webexteams/src/main/resources/templates/account.html b/bundles/org.openhab.binding.webexteams/src/main/resources/templates/account.html index 0a741c227e294..8e0b6cdbcb62b 100644 --- a/bundles/org.openhab.binding.webexteams/src/main/resources/templates/account.html +++ b/bundles/org.openhab.binding.webexteams/src/main/resources/templates/account.html @@ -1,6 +1,6 @@
-
${account.type}:
-
${account.name}${account.user}
+
${account.name}:
+
${account.user} (${account.type})