List<PlugwiseBindingConfigElement> compiledList = ((PlugwiseBindingProvider)provider).getIntervalList();
Iterator<PlugwiseBindingConfigElement> pbcIterator = compiledList.iterator();
while(pbcIterator.hasNext()) {
PlugwiseBindingConfigElement anElement = pbcIterator.next();
PlugwiseCommandType type = anElement.getCommandType();
// check if the device already exists (via cfg definition of Role Call)
if(stick.getDevice(anElement.getId())==null) {
logger.debug("The Plugwise device with id {} is not yet defined",anElement.getId());
// check if the config string really contains a MAC address
Pattern MAC_PATTERN = Pattern.compile("(\\w{16})");
Matcher matcher = MAC_PATTERN.matcher(anElement.getId());
if(matcher.matches()){
CirclePlus cp = (CirclePlus) stick.getDeviceByName("circleplus");
if(cp!=null) {
if(!cp.getMAC().equals(anElement.getId())) {
//a circleplus has been added/detected and it is not what is in the binding config
PlugwiseDevice device = new Circle(anElement.getId(),stick,anElement.getId());
stick.plugwiseDeviceCache.add(device);
logger.info("Plugwise added Circle with MAC address: {}",anElement.getId());
}
} else {
logger.warn("Plugwise can not guess the device that should be added. Consider defining it in the openHAB configuration file");
}
} else {
logger.warn("Plugwise can not add a valid device without a proper MAC address. {} can not be used",anElement.getId());
}
}
if(stick.getDevice(anElement.getId())!=null) {
boolean jobExists = false;
// enumerate each job group
try {
for(String group: sched.getJobGroupNames()) {
// enumerate each job in group
for(JobKey jobKey : sched.getJobKeys(jobGroupEquals(group))) {
if(jobKey.getName().equals(anElement.getId()+"-"+type.getJobClass().toString())) {
jobExists = true;
break;
}
}
}
} catch (SchedulerException e1) {
logger.error("An exception occurred while quering the Quartz Scheduler ({})",e1.getMessage());
}
if(!jobExists) {
// set up the Quartz jobs
JobDataMap map = new JobDataMap();
map.put("Stick", stick);
map.put("MAC",stick.getDevice(anElement.getId()).MAC);
JobDetail job = newJob(type.getJobClass())
.withIdentity(anElement.getId()+"-"+type.getJobClass().toString(), "Plugwise-"+provider.toString())
.usingJobData(map)
.build();
Trigger trigger = newTrigger()
.withIdentity(anElement.getId()+"-"+type.getJobClass().toString(), "Plugwise-"+provider.toString())
.startNow()
.withSchedule(simpleSchedule()
.repeatForever()
.withIntervalInSeconds(anElement.getInterval()))
.build();
try {
sched.scheduleJob(job, trigger);
} catch (SchedulerException e) {