use of org.cups4j.WhichJobsEnum in project openhab1-addons by openhab.
the class CupsBinding method execute.
/**
* @{inheritDoc}
*/
@Override
public void execute() {
if (client == null) {
logger.warn("CupsClient is null => refresh cycle aborted!");
return;
}
for (CupsBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
String printerName = provider.getPrinterName(itemName);
WhichJobsEnum whichJobs = provider.getWhichJobs(itemName);
if (printerName == null) {
logger.warn("printerName isn't defined for itemName '{}'" + " => querying bus for values aborted!", itemName);
continue;
}
State value = UnDefType.UNDEF;
try {
URL printerUrl = null;
CupsPrinter printer = null;
try {
printerUrl = new URL(printerName);
} catch (MalformedURLException e) {
try {
printerUrl = new URL("http://" + host + ":" + port + "/printers/" + printerName);
} catch (MalformedURLException e1) {
logger.warn("Failed to construct URL for printer name: {}", printerName);
}
}
if (printerUrl == null) {
// try to find printer by name
for (CupsPrinter pr : client.getPrinters()) {
if (pr.getName().equalsIgnoreCase(printerName)) {
printer = pr;
break;
}
}
} else {
printer = client.getPrinter(printerUrl);
}
if (printer != null) {
value = new DecimalType(client.getJobs(printer, whichJobs, "", false).size());
logger.debug("Found printer {}#{} with value {}", printerUrl, whichJobs, value);
} else {
logger.info("There is no printer for path {}", printerUrl);
}
} catch (IOException ioe) {
logger.warn("Couldn't establish network connection for printer '{}'", printerName, ioe);
} catch (Exception e) {
logger.error("Couldn't get printer '{}' from cups server", printerName, e);
} finally {
eventPublisher.postUpdate(itemName, value);
}
}
}
}
Aggregations