diff --git a/bundles/binding/org.openhab.binding.plugwise/src/main/java/org/openhab/binding/plugwise/internal/PlugwiseBinding.java b/bundles/binding/org.openhab.binding.plugwise/src/main/java/org/openhab/binding/plugwise/internal/PlugwiseBinding.java index 8f8f2ae35e3..19322d94a6a 100644 --- a/bundles/binding/org.openhab.binding.plugwise/src/main/java/org/openhab/binding/plugwise/internal/PlugwiseBinding.java +++ b/bundles/binding/org.openhab.binding.plugwise/src/main/java/org/openhab/binding/plugwise/internal/PlugwiseBinding.java @@ -51,8 +51,8 @@ public class PlugwiseBinding extends AbstractActiveBinding implements ManagedService { private static final Logger logger = LoggerFactory.getLogger(PlugwiseBinding.class); - private static final Pattern EXTRACT_PLUGWISE_CONFIG_PATTERN = Pattern.compile("^(.*?)\\.(mac|port)$"); - + private static final Pattern EXTRACT_PLUGWISE_CONFIG_PATTERN = Pattern.compile("^(.*?)\\.(mac|port|interval)$"); + /** the refresh interval which is used to check for changes in the binding configurations */ private static long refreshInterval = 5000; @@ -62,6 +62,8 @@ public class PlugwiseBinding extends AbstractActiveBinding.'"); + + "' does not follow the expected pattern '.'"); continue; } @@ -98,21 +100,8 @@ public void updated(Dictionary config) throws ConfigurationException { if ("port".equals(configKey)) { stick = new Stick(value,this); logger.info("Plugwise added Stick connected to serial port {}",value); - } - else { - throw new ConfigurationException(configKey, - "the given configKey '" + configKey + "' is unknown"); - } - } - - if (stick != null) { - - String configKey = matcher.group(2); - String value = (String) config.get(key); - - if ("interval".equals(configKey)) { - stick.setInterval(Integer.valueOf(value)); - logger.info("Plugwise set the interval to send ZigBee PDUs to {} ms",value); + } else if ("interval".equals(configKey)) { + // do nothing for now. we will set in the second run } else { throw new ConfigurationException(configKey, @@ -150,6 +139,24 @@ public void updated(Dictionary config) throws ConfigurationException { String plugwiseID = matcher.group(1); + if(plugwiseID.equals("stick")) { + + String configKey = matcher.group(2); + String value = (String) config.get(key); + + if ("interval".equals(configKey)) { + stick.setInterval(Integer.valueOf(value)); + logger.info("Plugwise set the interval to send ZigBee PDUs to {} ms",value); + } else if ("port".equals(configKey)) { + //ignore + } + else { + throw new ConfigurationException(configKey, + "the given configKey '" + configKey + "' is unknown"); + } + + } + PlugwiseDevice device = stick.getDeviceByName(plugwiseID); if (device == null && !plugwiseID.equals("stick")) { diff --git a/bundles/binding/org.openhab.binding.plugwise/src/main/java/org/openhab/binding/plugwise/internal/Stick.java b/bundles/binding/org.openhab.binding.plugwise/src/main/java/org/openhab/binding/plugwise/internal/Stick.java index 7787dd0cbb1..35b4d5f538b 100644 --- a/bundles/binding/org.openhab.binding.plugwise/src/main/java/org/openhab/binding/plugwise/internal/Stick.java +++ b/bundles/binding/org.openhab.binding.plugwise/src/main/java/org/openhab/binding/plugwise/internal/Stick.java @@ -70,6 +70,9 @@ public class Stick extends PlugwiseDevice implements SerialPortEventListener{ /** Number of attempts we make at sending a message */ private final static int MAX_ATTEMPTS = 10; + + /** counter to track Quartz Jobs */ + private static int counter=0; // Serial communication fields private String port; @@ -244,12 +247,12 @@ private void initialize() throws PlugwiseInitializationException { map.put("Stick", this); JobDetail job = newJob(SendJob.class) - .withIdentity("Send", "Plugwise") + .withIdentity("Send-0", "Plugwise") .usingJobData(map) .build(); Trigger trigger = newTrigger() - .withIdentity("Send", "Plugwise") + .withIdentity("Send-0", "Plugwise") .startNow() .build(); @@ -782,14 +785,16 @@ public void jobWasExecuted(JobExecutionContext context, JobDataMap map = new JobDataMap(); map.put("Stick", theStick); + + Stick.counter++; JobDetail job = newJob(SendJob.class) - .withIdentity("Send", "Plugwise") + .withIdentity("Send-"+Stick.counter, "Plugwise") .usingJobData(map) .build(); Trigger trigger = newTrigger() - .withIdentity("Send", "Plugwise") + .withIdentity("Send-"+Stick.counter, "Plugwise") .startNow() .build(); @@ -802,7 +807,7 @@ public void jobWasExecuted(JobExecutionContext context, try { sched.scheduleJob(job, trigger); } catch (SchedulerException e) { - logger.error("Error scheduling a job with the Quartz Scheduler"); + logger.error("Error scheduling a job with the Quartz Scheduler : {}",e.getMessage()); } }