use of org.openhab.binding.tinkerforge.internal.model.GenericDevice in project openhab1-addons by openhab.
the class EcosystemImpl method getDevices4GenericId.
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
@Override
public EList<MSubDevice<?>> getDevices4GenericId(String uid, String genericId) {
EList<MSubDevice<?>> genericDevicesList = new BasicEList<MSubDevice<?>>();
EList<MBrickd> _mbrickds = getMbrickds();
for (final MBrickd mbrickd : _mbrickds) {
{
final MBaseDevice mDevice = mbrickd.getDevice(uid);
if (mDevice != null) {
if (mDevice instanceof MSubDeviceHolder) {
final MSubDeviceHolder<?> mBrick = ((MSubDeviceHolder<?>) mDevice);
EList<?> _msubdevices = mBrick.getMsubdevices();
for (final Object mg : _msubdevices) {
if (mg instanceof GenericDevice) {
final GenericDevice mgenericdevice = ((GenericDevice) mg);
String _genericId = mgenericdevice.getGenericDeviceId();
if (_genericId.equals(genericId)) {
genericDevicesList.add(((MSubDevice<?>) mgenericdevice));
}
}
}
}
}
}
}
return genericDevicesList;
}
use of org.openhab.binding.tinkerforge.internal.model.GenericDevice 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