From a49d9f8dc91edc7d623d0fa2a0f3a1f19b42e534 Mon Sep 17 00:00:00 2001 From: Ondrej Pecta Date: Mon, 31 Jul 2017 08:21:00 +0200 Subject: [PATCH] Implemented some improvement suggestions from PR code review #2 Signed-off-by: Ondrej Pecta --- .../org.openhab.binding.somfytahoma/README.md | 4 +- .../handler/SomfyTahomaBridgeHandler.java | 54 +++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/addons/binding/org.openhab.binding.somfytahoma/README.md b/addons/binding/org.openhab.binding.somfytahoma/README.md index d54d97b37835e..917f9e07987b2 100644 --- a/addons/binding/org.openhab.binding.somfytahoma/README.md +++ b/addons/binding/org.openhab.binding.somfytahoma/README.md @@ -34,10 +34,10 @@ Please see the example below. ## Channels -A bridge does not expose and channel. +A bridge does not expose any channel. Gateways expose this read only channel: -- version (this is a firmware version of your Tahoma device) +- version (this is a firmware version of your Tahoma gateway) Roller shutters and awnings expose these channels: - position (a percentual position of the roller shutter, it can have value 0-100). For IO Homecontrol devices only (non RTS)! diff --git a/addons/binding/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/handler/SomfyTahomaBridgeHandler.java b/addons/binding/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/handler/SomfyTahomaBridgeHandler.java index ea51e8a17d1c0..51a321801e55c 100644 --- a/addons/binding/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/handler/SomfyTahomaBridgeHandler.java +++ b/addons/binding/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/handler/SomfyTahomaBridgeHandler.java @@ -96,7 +96,7 @@ public void run() { try { updateTahomaStates(); } catch (Exception e) { - logger.debug("Exception during poll : {}", e); + logger.debug("Exception during poll!", e); } } }, 10, refresh, TimeUnit.SECONDS); @@ -152,10 +152,10 @@ private synchronized void login() { throw new SomfyTahomaException(line); } } catch (MalformedURLException e) { - logger.error("The URL '{}' is malformed: {}", url, e.toString()); + logger.error("The URL '{}' is malformed!", url, e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "The URL '" + url + "' is malformed: "); } catch (Exception e) { - logger.error("Cannot get login cookie: {}", e.toString()); + logger.error("Cannot get login cookie!", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Cannot get login cookie"); } } @@ -220,14 +220,14 @@ private String getGroups() { return readResponse(response); } catch (MalformedURLException e) { - logger.error("The URL '{}' is malformed: {}", url, e.toString()); + logger.error("The URL '{}' is malformed!", url, e); } catch (IOException e) { if (e.toString().contains(UNAUTHORIZED)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Unauthorized"); } - logger.error("Cannot send getActionGroups command: {}", e.toString()); + logger.error("Cannot send getActionGroups command!", e); } catch (Exception e) { - logger.error("Cannot send getActionGroups command: {}", e.toString()); + logger.error("Cannot send getActionGroups command!", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); } return ""; @@ -262,14 +262,14 @@ private void listDevices() { discoveryService.gatewayDiscovered(gateway.getGatewayId()); } } catch (MalformedURLException e) { - logger.error("The URL '{}' is malformed: {}", url, e.toString()); + logger.error("The URL '{}' is malformed!", url, e); } catch (IOException e) { if (e.toString().contains(UNAUTHORIZED)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Unauthorized"); } - logger.error("Cannot send listDevices command: {}", e.toString()); + logger.error("Cannot send listDevices command!", e); } catch (Exception e) { - logger.error("Cannot send listDevices command: {}", e.toString()); + logger.error("Cannot send listDevices command!", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); } @@ -309,14 +309,14 @@ private State getState(SomfyTahomaThingHandler handler, String deviceUrl) { return UnDefType.UNDEF; } } catch (MalformedURLException e) { - logger.error("The URL '{}' is malformed: {}", url, e.toString()); + logger.error("The URL '{}' is malformed!", url, e); } catch (IOException e) { if (e.toString().contains(UNAUTHORIZED)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Unauthorized"); return UnDefType.NULL; } } catch (Exception e) { - logger.error("Cannot send getStates command: {}", e.toString()); + logger.error("Cannot send getStates command!", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); } @@ -327,7 +327,7 @@ private void updateTahomaStates() { logger.debug("Updating Tahoma States..."); for (Thing thing : getThing().getThings()) { logger.debug("Updating thing {} with UID {}", thing.getLabel(), thing.getThingTypeUID()); - if(thing.getThingTypeUID().equals(THING_TYPE_GATEWAY)) { + if (thing.getThingTypeUID().equals(THING_TYPE_GATEWAY)) { String id = thing.getConfiguration().get("id").toString(); updateGatewayState(thing, id); } else { @@ -380,7 +380,7 @@ private void logout() { sendToTahomaWithCookie(TAHOMA_URL + "logout"); cookie = ""; } catch (Exception e) { - logger.error("Cannot send logout command!"); + logger.error("Cannot send logout command!", e); } } @@ -467,14 +467,14 @@ public void sendCommand(String io, String command, String params) { throw new SomfyTahomaException(line); } } catch (MalformedURLException e) { - logger.error("The URL '{}' is malformed: {}", url, e.toString()); + logger.error("The URL '{}' is malformed!", url, e); } catch (IOException e) { if (e.toString().contains(UNAUTHORIZED)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Unauthorized"); } - logger.error("Cannot send apply command: {}", e.toString()); + logger.error("Cannot send apply command!", e); } catch (Exception e) { - logger.error("Cannot send apply command: {]", e.toString()); + logger.error("Cannot send apply command!", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); } } @@ -503,14 +503,14 @@ public String getCurrentExecutions(String type) { } return null; } catch (MalformedURLException e) { - logger.error("The URL '{}' is malformed: {}", url, e.toString()); + logger.error("The URL '{}' is malformed!", url, e); } catch (IOException e) { if (e.toString().contains(UNAUTHORIZED)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Unauthorized"); } - logger.error("Cannot send getCurrentExecutions command: {}", e.toString()); + logger.error("Cannot send getCurrentExecutions command!", e); } catch (Exception e) { - logger.error("Cannot send getCurrentExecutions command: {}", e.toString()); + logger.error("Cannot send getCurrentExecutions command!", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); } @@ -525,14 +525,14 @@ public void cancelExecution(String executionId) { sendDeleteToTahomaWithCookie(url); } catch (MalformedURLException e) { - logger.error("The URL '{}' is malformed: {}", url, e.toString()); + logger.error("The URL '{}' is malformed!", e); } catch (IOException e) { if (e.toString().contains(UNAUTHORIZED)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Unauthorized"); } - logger.error("Cannot cancel execution: {}", e.toString()); + logger.error("Cannot cancel execution!", e); } catch (Exception e) { - logger.error("Cannot cancel execution: {}", e.toString()); + logger.error("Cannot cancel execution!", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); } } @@ -551,13 +551,13 @@ public ArrayList getTahomaActions(String actionGroup) { } private void updateGatewayState(Thing thing, String id) { - if(thing.getChannels().size() == 0) { + if (thing.getChannels().size() == 0) { return; } String version = getTahomaVersion(id); - for(Channel channel : thing.getChannels()) { - if(channel.getUID().getId().equals(VERSION)) { - logger.info("Updating channel version!"); + for (Channel channel : thing.getChannels()) { + if (channel.getUID().getId().equals(VERSION)) { + logger.debug("Updating version channel"); updateState(channel.getUID(), new StringType(version)); } } @@ -574,7 +574,7 @@ public String getTahomaVersion(String gatewayId) { return data.getResult(); } catch (Exception e) { - logger.error("Cannot get Tahoma gateway version!"); + logger.error("Cannot get Tahoma gateway version!", e); } return ""; }