use of org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig in project openhab1-addons by openhab.
the class OneWireBinding method bindingChanged.
/*
* (non-Javadoc)
*
* @see
* org.openhab.core.binding.AbstractBinding#bindingChanged(org.openhab.core
* .binding.BindingProvider, java.lang.String)
*/
@Override
public void bindingChanged(BindingProvider pvProvider, String pvItemName) {
logger.debug("bindingChanged() for item {} msg received.", pvItemName);
if (pvProvider instanceof OneWireBindingProvider) {
ivCacheItemStates.remove(pvItemName);
OneWireBindingProvider lvBindingProvider = (OneWireBindingProvider) pvProvider;
OneWireBindingConfig lvBindingConfig = lvBindingProvider.getBindingConfig(pvItemName);
// AbstractOneWireControlBindingConfigs
if (lvBindingConfig != null && lvBindingConfig instanceof AbstractOneWireDevicePropertyBindingConfig) {
AbstractOneWireDevicePropertyBindingConfig lvDeviceBindingConfig = (AbstractOneWireDevicePropertyBindingConfig) lvBindingConfig;
logger.debug("Initializing read of item {}.", pvItemName);
int lvAutoRefreshTimeInSecs = lvDeviceBindingConfig.getAutoRefreshInSecs();
if (lvAutoRefreshTimeInSecs > -1) {
ivOneWireReaderScheduler.updateOnce(pvItemName);
}
if (lvAutoRefreshTimeInSecs > 0) {
if (!ivOneWireReaderScheduler.scheduleUpdate(pvItemName, lvAutoRefreshTimeInSecs)) {
logger.warn("Couldn't add to OneWireUpdate scheduler", lvDeviceBindingConfig);
}
} else {
logger.debug("Didn't add to OneWireUpdate scheduler, because refresh is <= 0: {}", lvDeviceBindingConfig);
}
}
}
}
use of org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig in project openhab1-addons by openhab.
the class OneWireBinding method scheduleAllBindings.
/**
* schedule All Bindings to get updated
*
* @param pvProvider
*/
private void scheduleAllBindings(BindingProvider pvProvider) {
if (OneWireConnection.isConnectionEstablished()) {
logger.debug("scheduleAllBindings");
if (pvProvider instanceof OneWireBindingProvider) {
OneWireBindingProvider lvBindingProvider = (OneWireBindingProvider) pvProvider;
ivOneWireReaderScheduler.clear();
ivCacheItemStates.clear();
Map<String, BindingConfig> lvBindigConfigs = lvBindingProvider.getBindingConfigs();
for (String lvItemName : lvBindigConfigs.keySet()) {
logger.debug("scheduleAllBindings, now item {}.", lvItemName);
OneWireBindingConfig lvOneWireBindingConfig = (OneWireBindingConfig) lvBindigConfigs.get(lvItemName);
if (lvOneWireBindingConfig instanceof AbstractOneWireDevicePropertyBindingConfig) {
logger.debug("Initializing read of item {}.", lvItemName);
AbstractOneWireDevicePropertyBindingConfig lvDevicePropertyBindingConfig = (AbstractOneWireDevicePropertyBindingConfig) lvOneWireBindingConfig;
if (lvDevicePropertyBindingConfig != null) {
int lvAutoRefreshTimeInSecs = lvDevicePropertyBindingConfig.getAutoRefreshInSecs();
if (lvAutoRefreshTimeInSecs > -1) {
ivOneWireReaderScheduler.updateOnce(lvItemName);
}
if (lvAutoRefreshTimeInSecs > 0) {
if (!ivOneWireReaderScheduler.scheduleUpdate(lvItemName, lvAutoRefreshTimeInSecs)) {
logger.warn("Couldn't add to OneWireUpdate scheduler", lvDevicePropertyBindingConfig);
}
}
}
} else {
logger.debug("Didn't schedule item {} because it is not a DevicePropertyBinding.", lvItemName);
}
}
}
}
}
use of org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig in project openhab1-addons by openhab.
the class OneWireBinding method updateItemFromOneWire.
/**
* Update an item with value from 1-wire device property
*
* @param pvItemName
*/
public void updateItemFromOneWire(String pvItemName) {
if (OneWireConnection.getConnection() != null) {
AbstractOneWireDevicePropertyBindingConfig pvBindingConfig = (AbstractOneWireDevicePropertyBindingConfig) getBindingConfig(pvItemName);
if (pvBindingConfig == null) {
logger.error("no bindingConfig found for itemName={} cannot update! It will be removed from scheduler", pvItemName);
ivOneWireReaderScheduler.removeItem(pvItemName);
return;
}
String lvReadValue = OneWireConnection.readFromOneWire(pvBindingConfig);
Item lvItem = getItem(pvItemName);
if (lvReadValue != null) {
Type lvNewType = pvBindingConfig.convertReadValueToType(lvReadValue);
if (lvItem != null) {
postUpdate(lvItem, lvNewType);
} else {
logger.error("There is no Item for ItemName={}", pvItemName);
}
} else {
String lvLogText = "Set Item for itemName=" + pvItemName + " to Undefined, because the readvalue is null";
if (pvBindingConfig.isIgnoreReadErrors()) {
logger.debug(lvLogText);
} else {
logger.error(lvLogText);
}
postUpdate(lvItem, UnDefType.UNDEF);
}
}
}
Aggregations