Skip to content

Commit

Permalink
Implemented some improvement suggestions from PR code review #2
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Pecta <[email protected]>
  • Loading branch information
octa22 committed May 16, 2018
1 parent 5497ebe commit a49d9f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions addons/binding/org.openhab.binding.somfytahoma/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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 "";
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand All @@ -551,13 +551,13 @@ public ArrayList<SomfyTahomaAction> 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));
}
}
Expand All @@ -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 "";
}
Expand Down

0 comments on commit a49d9f8

Please sign in to comment.