Search in sources :

Example 1 with GenericDevice

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;
}
Also used : MSubDeviceHolder(org.openhab.binding.tinkerforge.internal.model.MSubDeviceHolder) BasicEList(org.eclipse.emf.common.util.BasicEList) EObjectContainmentWithInverseEList(org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList) EList(org.eclipse.emf.common.util.EList) InternalEList(org.eclipse.emf.ecore.util.InternalEList) GenericDevice(org.openhab.binding.tinkerforge.internal.model.GenericDevice) BasicEList(org.eclipse.emf.common.util.BasicEList) MBrickd(org.openhab.binding.tinkerforge.internal.model.MBrickd) MBaseDevice(org.openhab.binding.tinkerforge.internal.model.MBaseDevice) MSubDevice(org.openhab.binding.tinkerforge.internal.model.MSubDevice) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 2 with GenericDevice

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);
        }
    }
}
Also used : IO4Device(org.openhab.binding.tinkerforge.internal.model.IO4Device) GenericDevice(org.openhab.binding.tinkerforge.internal.model.GenericDevice) MTFConfigConsumer(org.openhab.binding.tinkerforge.internal.model.MTFConfigConsumer) MDevice(org.openhab.binding.tinkerforge.internal.model.MDevice) IODevice(org.openhab.binding.tinkerforge.internal.model.IODevice) TFConfig(org.openhab.binding.tinkerforge.internal.model.TFConfig)

Aggregations

GenericDevice (org.openhab.binding.tinkerforge.internal.model.GenericDevice)2 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EList (org.eclipse.emf.common.util.EList)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 EObjectContainmentWithInverseEList (org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList)1 InternalEList (org.eclipse.emf.ecore.util.InternalEList)1 IO4Device (org.openhab.binding.tinkerforge.internal.model.IO4Device)1 IODevice (org.openhab.binding.tinkerforge.internal.model.IODevice)1 MBaseDevice (org.openhab.binding.tinkerforge.internal.model.MBaseDevice)1 MBrickd (org.openhab.binding.tinkerforge.internal.model.MBrickd)1 MDevice (org.openhab.binding.tinkerforge.internal.model.MDevice)1 MSubDevice (org.openhab.binding.tinkerforge.internal.model.MSubDevice)1 MSubDeviceHolder (org.openhab.binding.tinkerforge.internal.model.MSubDeviceHolder)1 MTFConfigConsumer (org.openhab.binding.tinkerforge.internal.model.MTFConfigConsumer)1 TFConfig (org.openhab.binding.tinkerforge.internal.model.TFConfig)1