Search in sources :

Example 1 with MSubDevice

use of org.openhab.binding.tinkerforge.internal.model.MSubDevice in project openhab1-addons by openhab.

the class TinkerforgeBinding method initializeTFDevices.

/**
     * Adds or removes a device to / from the Ecosystem. Notifications from {@link MBrickd} are used
     * for adding devices (not sub devices) and removing of devices and their corresponding sub
     * devices.
     *
     * Notifications from {@link MSubDeviceHolder} for adding sub devices.
     *
     * @param notification The {@link Notification} for add and remove events to the {@link Ecosystem}
     *            .
     */
private void initializeTFDevices(Notification notification) {
    logger.trace("{} notifier {}", LoggerConstants.TFINIT, notification.getNotifier());
    if (notification.getNotifier() instanceof MBrickd) {
        logger.debug("{} notifier is Brickd", LoggerConstants.TFINIT);
        int featureID = notification.getFeatureID(MBrickd.class);
        if (featureID == ModelPackage.MBRICKD__MDEVICES) {
            if (notification.getEventType() == Notification.ADD) {
                MDevice<?> mDevice = (MDevice<?>) notification.getNewValue();
                addMDevice(mDevice, mDevice.getUid(), null);
            } else if (notification.getEventType() == Notification.ADD_MANY) {
                logger.debug("{} Notifier: add many called: ", LoggerConstants.TFINIT);
            } else if (notification.getEventType() == Notification.REMOVE) {
                logger.debug("{} Notifier: remove called: ", LoggerConstants.TFINIT);
                if (notification.getOldValue() instanceof MBaseDevice) {
                    logger.debug("{} Notifier: remove called for MBaseDevice", LoggerConstants.TFINIT);
                    MBaseDevice mDevice = (MBaseDevice) notification.getOldValue();
                    String uid = mDevice.getUid();
                    String subId = null;
                    if (searchConfiguredItemName(uid, subId) != null) {
                        logger.debug("{} Notifier: removing device: uid {} subid {}", LoggerConstants.TFINIT, uid, subId);
                        postUpdate(uid, subId, UnDefValue.UNDEF);
                    }
                } else {
                    logger.debug("{} unknown notification from mdevices {}", LoggerConstants.TFINIT, notification);
                }
            }
        } else {
            logger.debug("{} Notifier: unknown feature {}", LoggerConstants.TFINIT, notification.getFeature());
        }
    } else if (notification.getNotifier() instanceof MSubDeviceHolder<?>) {
        int featureID = notification.getFeatureID(MSubDeviceHolder.class);
        if (featureID == ModelPackage.MSUB_DEVICE_HOLDER__MSUBDEVICES) {
            logger.debug("{} MSubdevices Notifier called", LoggerConstants.TFINITSUB);
            if (notification.getEventType() == Notification.ADD) {
                MSubDevice<?> mSubDevice = (MSubDevice<?>) notification.getNewValue();
                addMDevice(mSubDevice, mSubDevice.getUid(), mSubDevice.getSubId());
            }
            if (notification.getEventType() == Notification.REMOVE) {
                logger.debug("{} remove notification from subdeviceholder", LoggerConstants.TFINIT);
                logger.debug("{} Notifier: remove called for MSubDevice", LoggerConstants.TFINIT);
                MSubDevice<?> mDevice = (MSubDevice<?>) notification.getOldValue();
                String uid = mDevice.getUid();
                String subId = mDevice.getSubId();
                if (searchConfiguredItemName(uid, subId) != null) {
                    logger.debug("{} Notifier: removing device: uid {} subid {}", LoggerConstants.TFINIT, uid, subId);
                    postUpdate(uid, subId, UnDefValue.UNDEF);
                }
            }
        }
    } else {
        logger.debug("{} unhandled notifier {}", LoggerConstants.TFINIT, notification.getNotifier());
    }
}
Also used : MSubDeviceHolder(org.openhab.binding.tinkerforge.internal.model.MSubDeviceHolder) MBrickd(org.openhab.binding.tinkerforge.internal.model.MBrickd) MBaseDevice(org.openhab.binding.tinkerforge.internal.model.MBaseDevice) MSubDevice(org.openhab.binding.tinkerforge.internal.model.MSubDevice) MDevice(org.openhab.binding.tinkerforge.internal.model.MDevice)

Example 2 with MSubDevice

use of org.openhab.binding.tinkerforge.internal.model.MSubDevice in project openhab1-addons by openhab.

the class TinkerforgeBinding method processValue.

/**
     * Processes changed device values to post them to the openHAB event bus.
     *
     * @param device The {@link MBaseDevice} device, which has a changed value.
     * @param notification The {@link Notification} about changes to the {@link Ecosystem}.
     */
private void processValue(MBaseDevice device, Notification notification) {
    TinkerforgeValue newValue = (TinkerforgeValue) notification.getNewValue();
    String uid = device.getUid();
    String subId = null;
    if (device instanceof MSubDevice<?>) {
        subId = ((MSubDevice<?>) device).getSubId();
        logger.trace("{} Notifier found MSubDevice sensor value for: {}", LoggerConstants.TFMODELUPDATE, subId);
    } else {
        logger.trace("{} Notifier found mDevice sensor value for: {}", LoggerConstants.TFMODELUPDATE, uid);
    }
    postUpdate(uid, subId, newValue);
}
Also used : TinkerforgeValue(org.openhab.binding.tinkerforge.internal.types.TinkerforgeValue) MSubDevice(org.openhab.binding.tinkerforge.internal.model.MSubDevice)

Example 3 with MSubDevice

use of org.openhab.binding.tinkerforge.internal.model.MSubDevice 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)

Aggregations

MSubDevice (org.openhab.binding.tinkerforge.internal.model.MSubDevice)3 MBaseDevice (org.openhab.binding.tinkerforge.internal.model.MBaseDevice)2 MBrickd (org.openhab.binding.tinkerforge.internal.model.MBrickd)2 MSubDeviceHolder (org.openhab.binding.tinkerforge.internal.model.MSubDeviceHolder)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 GenericDevice (org.openhab.binding.tinkerforge.internal.model.GenericDevice)1 MDevice (org.openhab.binding.tinkerforge.internal.model.MDevice)1 TinkerforgeValue (org.openhab.binding.tinkerforge.internal.types.TinkerforgeValue)1