use of org.openhab.core.binding.BindingChangeListener in project openhab1-addons by openhab.
the class DmxGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
if (dmxService == null) {
logger.error("DMX Service unavailable. Cannot process item configuration for {}", item.getName());
return;
}
super.processBindingConfiguration(context, item, bindingConfig);
String config = (bindingConfig == null) ? "" : bindingConfig.replaceAll(" ", "").toUpperCase();
logger.trace("Binding item: {} with configuration {}", item.getName(), config);
DmxItem itemBinding = null;
if (item instanceof ColorItem) {
itemBinding = new DmxColorItem(item.getName(), config, this);
} else if (item instanceof DimmerItem) {
itemBinding = new DmxDimmerItem(item.getName(), config, this);
} else if (item instanceof SwitchItem) {
itemBinding = new DmxSwitchItem(item.getName(), config, this);
} else {
throw new BindingConfigParseException("Unsupported item type " + item.getClass().getSimpleName());
}
if (itemBinding.isStatusListener()) {
final DmxStatusUpdateListener dmxStatusListener = itemBinding;
final String itemName = item.getName();
logger.trace("Registering status listener for item {} ", item.getName());
dmxService.registerStatusListener(dmxStatusListener);
// add binding change listener to clean up status listeners on item
// removal
addBindingChangeListener(new BindingChangeListener() {
@Override
public void bindingChanged(BindingProvider provider, String changedItemName) {
if (itemName.equals(changedItemName) && !provider.providesBindingFor(itemName)) {
logger.trace("Removing status listener for item {}", itemName);
dmxService.unregisterStatusListener(dmxStatusListener);
}
}
@Override
public void allBindingsChanged(BindingProvider provider) {
if (!provider.providesBindingFor(itemName)) {
logger.trace("Removing status listener for item {}", itemName);
dmxService.unregisterStatusListener(dmxStatusListener);
}
}
});
}
addBindingConfig(item, itemBinding);
}
use of org.openhab.core.binding.BindingChangeListener in project openhab1-addons by openhab.
the class MaxCulGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
final String itemName = item.getName();
logger.debug("Processing item " + itemName);
final MaxCulBindingConfig config = new MaxCulBindingConfig(bindingConfig);
addBindingConfig(item, config);
addBindingChangeListener(new BindingChangeListener() {
@Override
public void bindingChanged(BindingProvider provider, String itemName) {
/* binding changed so update the association map */
associationsMapBuilt = false;
// TODO check if config temperatures are set and flag that they
// should be sent the device because they might have changed?
}
@Override
public void allBindingsChanged(BindingProvider provider) {
if (!provider.providesBindingFor(itemName)) {
// TODO get serial number of itemName
// then check if we still interact with that device, if not
// then
// deassociate and send a reset to it
}
}
});
}
use of org.openhab.core.binding.BindingChangeListener in project openhab1-addons by openhab.
the class MqttGenericBindingProvider method processBindingConfiguration.
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
final String itemName = item.getName();
logger.trace("Starting to load MQTT config for item {}", itemName);
if (StringUtils.isEmpty(bindingConfig)) {
throw new BindingConfigParseException("Missing mqtt binding configuration for item " + itemName);
}
final MqttItemConfig itemConfig = new MqttItemConfig(item, bindingConfig);
// register all message consumers
for (MqttMessageSubscriber subscriber : itemConfig.getMessageSubscribers()) {
subscriber.setItemName(item.getName());
mqttService.registerMessageConsumer(subscriber.getBroker(), subscriber);
}
// add binding change listener to clean up message consumers on item removal
addBindingChangeListener(new BindingChangeListener() {
@Override
public void bindingChanged(BindingProvider provider, String changedItemName) {
if (itemName.equals(changedItemName) && !provider.providesBindingFor(itemName)) {
logger.debug("Removing message consumers for item {}", itemName);
for (MqttMessageSubscriber subscriber : itemConfig.getMessageSubscribers()) {
mqttService.unregisterMessageConsumer(subscriber.getBroker(), subscriber);
}
removeBindingChangeListener(this);
}
}
@Override
public void allBindingsChanged(BindingProvider provider) {
if (!provider.providesBindingFor(itemName)) {
logger.debug("Removing message consumers for item {}", itemName);
for (MqttMessageSubscriber subscriber : itemConfig.getMessageSubscribers()) {
mqttService.unregisterMessageConsumer(subscriber.getBroker(), subscriber);
}
removeBindingChangeListener(this);
}
}
});
// register all message producers
for (MqttMessagePublisher publisher : itemConfig.getMessagePublishers()) {
publisher.setItemName(item.getName());
mqttService.registerMessageProducer(publisher.getBroker(), publisher);
}
// add binding change listener to clean up message publishers on item
// removal
addBindingChangeListener(new BindingChangeListener() {
@Override
public void bindingChanged(BindingProvider provider, String changedItemName) {
if (itemName.equals(changedItemName) && !provider.providesBindingFor(itemName)) {
logger.debug("Removing message publishers for item {}", itemName);
for (MqttMessagePublisher publisher : itemConfig.getMessagePublishers()) {
mqttService.unregisterMessageProducer(publisher.getBroker(), publisher);
}
removeBindingChangeListener(this);
}
}
@Override
public void allBindingsChanged(BindingProvider provider) {
if (!provider.providesBindingFor(itemName)) {
logger.debug("Removing message publishers for item {}", itemName);
for (MqttMessagePublisher publisher : itemConfig.getMessagePublishers()) {
mqttService.unregisterMessageProducer(publisher.getBroker(), publisher);
}
removeBindingChangeListener(this);
}
}
});
addBindingConfig(item, itemConfig);
}
Aggregations