use of org.openhab.binding.mios.MiosBindingProvider 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.binding.mios.MiosBindingProvider 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;
}
}
use of org.openhab.binding.mios.MiosBindingProvider in project openhab1-addons by openhab.
the class MiosBinding method internalReceiveCommand.
/**
* {@inheritDoc}
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
try {
logger.debug("internalReceiveCommand: itemName '{}', command '{}'", itemName, command);
// Lookup the MiOS Unit name and property for this item
String unitName = getMiosUnitName(itemName);
MiosUnitConnector connector = getMiosConnector(unitName);
if (connector == null) {
logger.warn("Received command ({}) for item '{}' but no connector found for MiOS Unit '{}', ignoring", new Object[] { command.toString(), itemName, unitName });
return;
}
if (!connector.isConnected()) {
logger.warn("Received command ({}) for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", new Object[] { command.toString(), itemName, unitName });
return;
}
for (BindingProvider provider : providers) {
if (provider instanceof MiosBindingProvider) {
MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
if (config != null) {
ItemRegistry reg = miosProvider.getItemRegistry();
if (reg != null) {
Item item = reg.getItem(config.getItemName());
State state = item.getState();
connector.invokeCommand(config, command, state);
} else {
logger.warn("internalReceiveCommand: Missing ItemRegistry for item '{}' command '{}'", itemName, command);
}
} else {
logger.trace("internalReceiveCommand: Missing BindingConfig for item '{}' command '{}'", itemName, command);
}
}
}
} catch (Exception e) {
logger.error("Error handling command", e);
}
}
use of org.openhab.binding.mios.MiosBindingProvider in project openhab1-addons by openhab.
the class MiosBinding method internalPropertyUpdate.
private void internalPropertyUpdate(String property, State value, boolean incremental) throws Exception {
int bound = 0;
if (value == null) {
logger.trace("internalPropertyUpdate: Value is null for Property '{}', ignored.", property);
return;
}
for (BindingProvider provider : providers) {
if (provider instanceof MiosBindingProvider) {
MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
for (String itemName : miosProvider.getItemNamesForProperty(property)) {
MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
if (config != null) {
// Transform whatever value we have, based upon the
// Transformation Service specified in the Binding
// Config.
State newValue = config.transformIn(value);
if (newValue != value) {
logger.trace("internalPropertyUpdate: transformation performed, from '{}' to '{}'", value, newValue);
}
//
if (incremental) {
logger.debug("internalPropertyUpdate: BOUND (Incr) Updating '{} {mios=\"{}\"}' to '{}'", itemName, property, newValue);
eventPublisher.postUpdate(itemName, newValue);
} else {
ItemRegistry reg = miosProvider.getItemRegistry();
State oldValue = reg.getItem(itemName).getState();
if ((oldValue == null && newValue != null) || (UnDefType.UNDEF.equals(oldValue) && !UnDefType.UNDEF.equals(newValue)) || !oldValue.equals(newValue)) {
logger.debug("internalPropertyUpdate: BOUND (Full) Updating '{} {mios=\"{}\"}' to '{}', was '{}'", new Object[] { itemName, property, newValue, oldValue });
eventPublisher.postUpdate(itemName, newValue);
} else {
logger.trace("internalPropertyUpdate: BOUND (Full) Ignoring '{} {mios=\"{}\"}' to '{}', was '{}'", new Object[] { itemName, property, newValue, oldValue });
}
}
bound++;
} else {
logger.trace("internalPropertyUpdate: Found null BindingConfig for item '{}' property '{}'", itemName, property);
}
}
}
}
if (bound == 0) {
logger.trace("internalPropertyUpdate: NOT BOUND {mios=\"{}\"}, value={}", property, value);
} else {
logger.trace("internalPropertyUpdate: BOUND {mios=\"{}\"}, value={}, bound {} time(s)", new Object[] { property, value, bound });
}
}
Aggregations