use of org.openhab.core.binding.BindingProvider 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.BindingProvider in project openhab1-addons by openhab.
the class MiosBinding method invokeMiosAction.
/**
* {@inheritDoc}
*/
@Override
public boolean invokeMiosAction(String itemName, String actionName, List<Entry<String, Object>> params) {
try {
logger.debug("invokeMiosAction item {}, action {}, params {}", new Object[] { itemName, actionName, Integer.valueOf((params == null) ? 0 : params.size()) });
boolean sent = false;
// Lookup the MiOS Unit name and property for this item
String unitName = getMiosUnitName(itemName);
MiosUnitConnector connector = getMiosConnector(unitName);
if (connector == null) {
logger.warn("invokeMiosAction: Action call for item '{}' but no connector found for MiOS Unit '{}', ignoring", itemName, unitName);
return false;
}
if (!connector.isConnected()) {
logger.warn("invokeMiosAction: Action call for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", itemName, unitName);
return false;
}
for (BindingProvider provider : providers) {
if (provider instanceof MiosBindingProvider) {
MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
if ((config != null) && (config instanceof DeviceBindingConfig)) {
connector.invokeAction((DeviceBindingConfig) config, actionName, params);
sent = true;
} else {
logger.error("invokeMiosAction: Missing BindingConfig for item '{}', or not bound to a MiOS Device.", itemName);
}
}
}
return sent;
} catch (Exception e) {
logger.error("invokeMiosScene: Error handling command", e);
return false;
}
}
use of org.openhab.core.binding.BindingProvider 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.BindingProvider 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);
}
use of org.openhab.core.binding.BindingProvider in project openhab1-addons by openhab.
the class MiosBinding method invokeMiosScene.
/**
* {@inheritDoc}
*/
@Override
public boolean invokeMiosScene(String itemName) {
try {
logger.debug("invokeMiosScene item {}", itemName);
boolean sent = false;
// Lookup the MiOS Unit name and property for this item
String unitName = getMiosUnitName(itemName);
MiosUnitConnector connector = getMiosConnector(unitName);
if (connector == null) {
logger.warn("invokeMiosScene: Scene call for item '{}' but no connector found for MiOS Unit '{}', ignoring", itemName, unitName);
return false;
}
if (!connector.isConnected()) {
logger.warn("invokeMiosScene: Scene call for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", itemName, unitName);
return false;
}
for (BindingProvider provider : providers) {
if (provider instanceof MiosBindingProvider) {
MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
if ((config != null) && (config instanceof SceneBindingConfig)) {
connector.invokeScene((SceneBindingConfig) config);
sent = true;
} else {
logger.error("invokeMiosScene: Missing BindingConfig for item '{}', or not bound to a MiOS Scene.", itemName);
}
}
}
return sent;
} catch (Exception e) {
logger.error("invokeMiosScene: Error handling command", e);
return false;
}
}
Aggregations