use of org.openhab.binding.tinkerforge.internal.model.IODevice in project openhab1-addons by openhab.
the class TinkerforgeBinding method addMDevice.
/**
* Configures and enables newly found devices. For sub devices the master device is also enabled.
* Configuration is only added if there is a configuration from openhab.cfg available and the
* device is configurable which is the case for {@link MTFConfigConsumer}. Devices of type
* {@link IODevice} are only enabled if they are configured in openhab.cfg, all other devices are
* always enabled.
*
* @param device A device object as {@link MBaseDevice}.
* @param uid The device uid as String.
* @param subId The device subid as String or <code>null</code> if the device is not a sub device.
*/
@SuppressWarnings("unchecked")
private synchronized void addMDevice(MBaseDevice device, String uid, String subId) {
String logId = subId == null ? uid : uid + " " + subId;
OHTFDevice<?, ?> deviceConfig = ohConfig.getConfigByTFId(uid, subId);
if (deviceConfig == null) {
logger.debug("{} found no device configuration for uid \"{}\" subid \"{}\"", LoggerConstants.TFINITSUB, uid, subId);
}
if (device.getEnabledA().compareAndSet(false, true)) {
if (subId != null) {
MDevice<?> masterDevice = (MDevice<?>) device.eContainer();
// recursion for adding the master device
if (!masterDevice.getEnabledA().get()) {
logger.debug("{} enabling masterDevice {}", LoggerConstants.TFINITSUB, masterDevice.getUid());
addMDevice(masterDevice, uid, null);
}
}
if (device instanceof MTFConfigConsumer<?> && deviceConfig != null) {
logger.debug("{} found MTFConfigConsumer id {}", LoggerConstants.TFINIT, logId);
if (device instanceof GenericDevice && checkDuplicateGenericDevice((GenericDevice) device, uid, subId)) {
logger.error("{} ignoring duplicate device uid: {}, subId {}, genericId {}. Fix your openhab.cfg!", LoggerConstants.CONFIG, uid, subId);
device.getEnabledA().compareAndSet(true, false);
} else {
TFConfig deviceTfConfig = EcoreUtil.copy(deviceConfig.getTfConfig());
logger.debug("{} setting tfConfig for {}", LoggerConstants.TFINIT, logId);
logger.debug("{} adding/enabling device {} with config: {}", LoggerConstants.TFINIT, logId, deviceTfConfig);
((MTFConfigConsumer<EObject>) device).setTfConfig(deviceTfConfig);
device.enable();
}
} else if (device instanceof IODevice || device instanceof IO4Device) {
logger.debug("{} ignoring unconfigured IODevice: {}", LoggerConstants.TFINIT, logId);
// set the device disabled, this is needed for not getting
// states
// through execute method
device.getEnabledA().compareAndSet(true, false);
} else {
device.enable();
logger.debug("{} adding/enabling device: {}", LoggerConstants.TFINIT, logId);
}
}
}
Aggregations