From 455d15ae77966e900eb7bb6c1dd76359bf8f2dda Mon Sep 17 00:00:00 2001 From: mod42 Date: Tue, 30 Sep 2014 00:13:22 +0200 Subject: [PATCH 1/2] Fix for #881 Telnet connection is now only opened if a password is set and if there is an item configured which uses the telnet connect on the standard port. --- .../fritzbox/internal/FritzboxBinding.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/bundles/binding/org.openhab.binding.fritzbox/src/main/java/org/openhab/binding/fritzbox/internal/FritzboxBinding.java b/bundles/binding/org.openhab.binding.fritzbox/src/main/java/org/openhab/binding/fritzbox/internal/FritzboxBinding.java index 44cada4b687..716298f59aa 100644 --- a/bundles/binding/org.openhab.binding.fritzbox/src/main/java/org/openhab/binding/fritzbox/internal/FritzboxBinding.java +++ b/bundles/binding/org.openhab.binding.fritzbox/src/main/java/org/openhab/binding/fritzbox/internal/FritzboxBinding.java @@ -145,7 +145,8 @@ public void deactivate() { @Override public void internalReceiveCommand(String itemName, Command command) { - if (password != null) { + if (password != null && !password.isEmpty()) { + logger.warn("Fritzbox password: "+password); String type = null; for (FritzboxBindingProvider provider : providers) { type = provider.getType(itemName); @@ -575,13 +576,14 @@ public void execute(JobExecutionContext arg0) @Override protected void execute() { + if (password == null) + return; + else if (password.trim().isEmpty()) + return; + try { - TelnetClient client = new TelnetClient(); - client.connect(ip); - - receive(client); - send(client, password); - receive(client); + TelnetClient client = null ; + for (FritzboxBindingProvider provider : providers) { for (String item : provider.getItemNames()) { @@ -598,6 +600,14 @@ protected void execute() { }else continue; + if (client == null){ + client = new TelnetClient(); + client.connect(ip); + receive(client); + send(client, password); + receive(client); + } + send(client, query); String answer = receive(client); @@ -627,10 +637,10 @@ protected void execute() { } } - - client.disconnect(); + if (client != null) + client.disconnect(); } catch (Exception e) { - logger.warn("Could not get item state", e); + logger.warn("Could not get item state ", e); } } From d08419d644512b500d398253fa22475d00f71eb9 Mon Sep 17 00:00:00 2001 From: mod42 Date: Fri, 10 Oct 2014 21:42:45 +0200 Subject: [PATCH 2/2] removed password log message --- .../org/openhab/binding/fritzbox/internal/FritzboxBinding.java | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/binding/org.openhab.binding.fritzbox/src/main/java/org/openhab/binding/fritzbox/internal/FritzboxBinding.java b/bundles/binding/org.openhab.binding.fritzbox/src/main/java/org/openhab/binding/fritzbox/internal/FritzboxBinding.java index 716298f59aa..c125cd6b5b8 100644 --- a/bundles/binding/org.openhab.binding.fritzbox/src/main/java/org/openhab/binding/fritzbox/internal/FritzboxBinding.java +++ b/bundles/binding/org.openhab.binding.fritzbox/src/main/java/org/openhab/binding/fritzbox/internal/FritzboxBinding.java @@ -146,7 +146,6 @@ public void deactivate() { public void internalReceiveCommand(String itemName, Command command) { if (password != null && !password.isEmpty()) { - logger.warn("Fritzbox password: "+password); String type = null; for (FritzboxBindingProvider provider : providers) { type = provider.getType(itemName);