Search in sources :

Example 1 with SwitchSensor

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

the class TinkerforgeBinding method updateItemValues.

/**
     * Triggers an update of state values for all devices.
     *
     * @param provider The {@code TinkerforgeBindingProvider} which is bound to the device as
     *            {@code Item}
     * @param itemName The name of the {@code Item} as String
     * @param only_poll_enabled Fetch only the values of devices which do not support callback
     *            listeners. These devices are marked with poll "true" flag.
     */
protected void updateItemValues(TinkerforgeBindingProvider provider, String itemName, boolean only_poll_enabled) {
    if (tinkerforgeEcosystem == null) {
        logger.warn("tinkerforge ecosystem not yet ready");
        return;
    }
    String deviceUid = provider.getUid(itemName);
    Item item = provider.getItem(itemName);
    String deviceSubId = provider.getSubId(itemName);
    String deviceName = provider.getName(itemName);
    if (deviceName != null) {
        String[] ids = getDeviceIdsForDeviceName(deviceName);
        deviceUid = ids[0];
        deviceSubId = ids[1];
    }
    MBaseDevice mDevice = tinkerforgeEcosystem.getDevice(deviceUid, deviceSubId);
    if (mDevice != null && mDevice.getEnabledA().get()) {
        if (only_poll_enabled && !mDevice.isPoll()) {
            // do nothing
            logger.debug("{} omitting fetch value for no poll{}:{}", LoggerConstants.ITEMUPDATE, deviceUid, deviceSubId);
        } else {
            if (mDevice instanceof MSensor) {
                ((MSensor<?>) mDevice).fetchSensorValue();
            } else if (mDevice instanceof SwitchSensor && item instanceof SwitchItem) {
                ((SwitchSensor) mDevice).fetchSwitchState();
            } else if (mDevice instanceof DigitalActor) {
                ((DigitalActor) mDevice).fetchDigitalValue();
            }
        }
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) ColorItem(org.openhab.core.library.items.ColorItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) ContactItem(org.openhab.core.library.items.ContactItem) MSensor(org.openhab.binding.tinkerforge.internal.model.MSensor) DigitalActor(org.openhab.binding.tinkerforge.internal.model.DigitalActor) SwitchSensor(org.openhab.binding.tinkerforge.internal.model.SwitchSensor) MBaseDevice(org.openhab.binding.tinkerforge.internal.model.MBaseDevice) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

DigitalActor (org.openhab.binding.tinkerforge.internal.model.DigitalActor)1 MBaseDevice (org.openhab.binding.tinkerforge.internal.model.MBaseDevice)1 MSensor (org.openhab.binding.tinkerforge.internal.model.MSensor)1 SwitchSensor (org.openhab.binding.tinkerforge.internal.model.SwitchSensor)1 Item (org.openhab.core.items.Item)1 ColorItem (org.openhab.core.library.items.ColorItem)1 ContactItem (org.openhab.core.library.items.ContactItem)1 DimmerItem (org.openhab.core.library.items.DimmerItem)1 NumberItem (org.openhab.core.library.items.NumberItem)1 RollershutterItem (org.openhab.core.library.items.RollershutterItem)1 StringItem (org.openhab.core.library.items.StringItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1