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());
}
}
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);
}
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;
}
Aggregations