Search in sources :

Example 1 with DigitalActor

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

Example 2 with DigitalActor

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

the class TinkerforgeBinding method processTFDeviceValues.

/**
     * Processes change events from the {@link Ecosystem}. Sensor values from {@link MSensor} are
     * handled by {@link #processSensorValue(MSensor, Notification) processSensorValue}, actor values
     * from {@link MSwitchActore} are handled by
     * {@link #processSwitchActorValue(MSwitchActor, Notification) processSwitchActorValue}. (no add
     * or remove events, these are handled in {@link #initializeTFDevices(Notification)
     * initializeTFDevices}).
     *
     *
     * @param notification The {@link Notification} about changes to the {@link Ecosystem}.
     */
private void processTFDeviceValues(Notification notification) {
    if (notification.getNotifier() instanceof MSensor) {
        MSensor<?> sensor = (MSensor<?>) notification.getNotifier();
        int featureID = notification.getFeatureID(MSensor.class);
        if (featureID == ModelPackage.MSENSOR__SENSOR_VALUE) {
            processValue((MBaseDevice) sensor, notification);
        }
    } else if (notification.getNotifier() instanceof SetPointActor<?>) {
        SetPointActor<?> actor = (SetPointActor<?>) notification.getNotifier();
        int setpointFeatureID = notification.getFeatureID(SetPointActor.class);
        if (setpointFeatureID == ModelPackage.SET_POINT_ACTOR__PERCENT_VALUE) {
            processValue((MBaseDevice) actor, notification);
        }
    } else if (notification.getNotifier() instanceof MoveActor) {
        MoveActor actor = (MoveActor) notification.getNotifier();
        int moveFeatureID = notification.getFeatureID(MoveActor.class);
        if (moveFeatureID == ModelPackage.MOVE_ACTOR__DIRECTION) {
            processValue((MBaseDevice) actor, notification);
        }
    } else if (notification.getNotifier() instanceof MSwitchActor) {
        MSwitchActor switchActor = (MSwitchActor) notification.getNotifier();
        int featureID = notification.getFeatureID(MSwitchActor.class);
        if (featureID == ModelPackage.MSWITCH_ACTOR__SWITCH_STATE) {
            processValue((MBaseDevice) switchActor, notification);
        }
    } else if (notification.getNotifier() instanceof ProgrammableSwitchActor) {
        logger.trace("notification {}", notification);
        logger.trace("notifier {}", notification.getNotifier());
        ProgrammableSwitchActor switchActor = (ProgrammableSwitchActor) notification.getNotifier();
        // use the super type class for getting the featureID. Should not be necessary according to
        // the docs or I misunderstand it. But this approach works.
        int featureID = notification.getFeatureID(SwitchSensor.class);
        logger.trace("notification ProgrammableSwitchActor id {}", featureID);
        if (featureID == ModelPackage.PROGRAMMABLE_SWITCH_ACTOR__SWITCH_STATE) {
            logger.trace("ProgrammableSwitchActor switch state changed sending notification");
            processValue((MBaseDevice) switchActor, notification);
        }
    } else if (notification.getNotifier() instanceof DigitalActor) {
        DigitalActor actor = (DigitalActor) notification.getNotifier();
        int featureID = notification.getFeatureID(DigitalActor.class);
        if (featureID == ModelPackage.DIGITAL_ACTOR__DIGITAL_STATE) {
            processValue((MBaseDevice) actor, notification);
        }
    } else if (notification.getNotifier() instanceof ColorActor) {
        ColorActor actor = (ColorActor) notification.getNotifier();
        int featureID = notification.getFeatureID(ColorActor.class);
        if (featureID == ModelPackage.COLOR_ACTOR__COLOR) {
            processValue((MBaseDevice) actor, notification);
        }
    } else if (notification.getNotifier() instanceof DimmableActor<?>) {
        DimmableActor<?> actor = (DimmableActor<?>) notification.getNotifier();
        processValue((MBaseDevice) actor, notification);
    } else if (notification.getNotifier() instanceof MBrickd) {
        MBrickd brickd = (MBrickd) notification.getNotifier();
        int featureID = notification.getFeatureID(MBrickd.class);
        if (featureID == ModelPackage.MBRICKD__CONNECTED_COUNTER) {
            String subId = "connected_counter";
            processValue(brickd, notification, subId);
        } else if (featureID == ModelPackage.MBRICKD__IS_CONNECTED) {
            String subId = "isconnected";
            processValue(brickd, notification, subId);
        }
    } else // TODO hier muss noch was fuer die dimmer und rollershutter rein
    {
        logger.trace("{} ignored notifier {}", LoggerConstants.TFMODELUPDATE, notification.getNotifier());
    }
}
Also used : MSwitchActor(org.openhab.binding.tinkerforge.internal.model.MSwitchActor) MSensor(org.openhab.binding.tinkerforge.internal.model.MSensor) MBaseDevice(org.openhab.binding.tinkerforge.internal.model.MBaseDevice) MBrickd(org.openhab.binding.tinkerforge.internal.model.MBrickd) SetPointActor(org.openhab.binding.tinkerforge.internal.model.SetPointActor) ColorActor(org.openhab.binding.tinkerforge.internal.model.ColorActor) ProgrammableColorActor(org.openhab.binding.tinkerforge.internal.model.ProgrammableColorActor) SimpleColorActor(org.openhab.binding.tinkerforge.internal.model.SimpleColorActor) DigitalActor(org.openhab.binding.tinkerforge.internal.model.DigitalActor) MoveActor(org.openhab.binding.tinkerforge.internal.model.MoveActor) DimmableActor(org.openhab.binding.tinkerforge.internal.model.DimmableActor) ProgrammableSwitchActor(org.openhab.binding.tinkerforge.internal.model.ProgrammableSwitchActor)

Example 3 with DigitalActor

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

the class TinkerforgeBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     *
     * Searches the item with the given {@code itemName} in the {@link TinkerforgeBindingProvider}
     * collection and gets the uid and subid of the device. The appropriate device is searched in the
     * ecosystem and the command is executed on the device.
     *
     * {@code OnOffType} commands are executed on {@link MInSwitchActor} objects. {@code StringType}
     * commands are executed on {@link MTextActor} objects.
     *
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    logger.debug("received command {} for item {}", command, itemName);
    for (TinkerforgeBindingProvider provider : providers) {
        for (String itemNameP : provider.getItemNames()) {
            if (itemNameP.equals(itemName)) {
                String deviceUid = provider.getUid(itemName);
                String deviceSubId = provider.getSubId(itemName);
                String deviceName = provider.getName(itemName);
                if (deviceName != null) {
                    String[] ids = getDeviceIdsForDeviceName(deviceName);
                    deviceUid = ids[0];
                    deviceSubId = ids[1];
                }
                logger.trace("{} found item for command: uid: {}, subid: {}", LoggerConstants.COMMAND, deviceUid, deviceSubId);
                MBaseDevice mDevice = tinkerforgeEcosystem.getDevice(deviceUid, deviceSubId);
                if (mDevice != null && mDevice.getEnabledA().get()) {
                    if (command instanceof OnOffType) {
                        logger.trace("{} found onoff command", LoggerConstants.COMMAND);
                        OnOffType cmd = (OnOffType) command;
                        if (mDevice instanceof MSwitchActor) {
                            OnOffValue state = cmd == OnOffType.OFF ? OnOffValue.OFF : OnOffValue.ON;
                            ((MSwitchActor) mDevice).turnSwitch(state);
                        } else if (mDevice instanceof DigitalActor) {
                            HighLowValue state = cmd == OnOffType.OFF ? HighLowValue.LOW : HighLowValue.HIGH;
                            ((DigitalActor) mDevice).turnDigital(state);
                        } else if (mDevice instanceof ProgrammableSwitchActor) {
                            OnOffValue state = cmd == OnOffType.OFF ? OnOffValue.OFF : OnOffValue.ON;
                            ((ProgrammableSwitchActor) mDevice).turnSwitch(state, provider.getDeviceOptions(itemName));
                        } else {
                            logger.error("{} received OnOff command for non-SwitchActor", LoggerConstants.COMMAND);
                        }
                    } else if (command instanceof StringType) {
                        logger.trace("{} found string command", LoggerConstants.COMMAND);
                        if (mDevice instanceof MTextActor) {
                            ((MTextActor) mDevice).write(command.toString());
                        }
                    } else if (command instanceof DecimalType) {
                        logger.debug("{} found number command", LoggerConstants.COMMAND);
                        if (command instanceof HSBType) {
                            logger.debug("{} found HSBType command", LoggerConstants.COMMAND);
                            if (mDevice instanceof ProgrammableColorActor) {
                                logger.debug("{} found ProgrammableColorActor {}", itemName);
                                ((ProgrammableColorActor) mDevice).setSelectedColor((HSBType) command, provider.getDeviceOptions(itemName));
                            } else if (mDevice instanceof SimpleColorActor) {
                                logger.debug("{} found SimpleColorActor {}", itemName);
                                ((SimpleColorActor) mDevice).setSelectedColor((HSBType) command);
                            }
                        } else if (command instanceof PercentType) {
                            if (mDevice instanceof SetPointActor) {
                                ((SetPointActor<?>) mDevice).setValue(((PercentType) command), provider.getDeviceOptions(itemName));
                                logger.debug("found SetpointActor");
                            } else if (mDevice instanceof PercentTypeActor) {
                                ((PercentTypeActor) mDevice).setValue(((PercentType) command), provider.getDeviceOptions(itemName));
                                logger.debug("found PercentType actor");
                            } else {
                                logger.error("found no percenttype actor");
                            }
                        } else {
                            if (mDevice instanceof NumberActor) {
                                ((NumberActor) mDevice).setNumber(((DecimalType) command).toBigDecimal());
                            } else if (mDevice instanceof SetPointActor) {
                                ((SetPointActor<?>) mDevice).setValue(((DecimalType) command).toBigDecimal(), provider.getDeviceOptions(itemName));
                            } else {
                                logger.error("found no number actor");
                            }
                        }
                    } else if (command instanceof UpDownType) {
                        UpDownType cmd = (UpDownType) command;
                        logger.debug("{} UpDownType command {}", itemName, cmd);
                        if (mDevice instanceof MoveActor) {
                            ((MoveActor) mDevice).move((UpDownType) command, provider.getDeviceOptions(itemName));
                        }
                    } else if (command instanceof StopMoveType) {
                        StopMoveType cmd = (StopMoveType) command;
                        if (mDevice instanceof MoveActor) {
                            if (cmd == StopMoveType.STOP) {
                                ((MoveActor) mDevice).stop();
                            } else {
                                ((MoveActor) mDevice).moveon(provider.getDeviceOptions(itemName));
                            }
                        }
                        logger.debug("{} StopMoveType command {}", itemName, cmd);
                    } else if (command instanceof IncreaseDecreaseType) {
                        IncreaseDecreaseType cmd = (IncreaseDecreaseType) command;
                        if (mDevice instanceof DimmableActor) {
                            ((DimmableActor<?>) mDevice).dimm((IncreaseDecreaseType) command, provider.getDeviceOptions(itemName));
                        }
                        logger.debug("{} IncreaseDecreaseType command {}", itemName, cmd);
                    } else {
                        logger.error("{} got unknown command type: {}", LoggerConstants.COMMAND, command.toString());
                    }
                } else {
                    logger.error("{} no tinkerforge device found for command for item uid: {} subId: {}", LoggerConstants.COMMAND, deviceUid, deviceSubId);
                }
            }
        }
    }
}
Also used : MSwitchActor(org.openhab.binding.tinkerforge.internal.model.MSwitchActor) StringType(org.openhab.core.library.types.StringType) PercentTypeActor(org.openhab.binding.tinkerforge.internal.model.PercentTypeActor) MBaseDevice(org.openhab.binding.tinkerforge.internal.model.MBaseDevice) ProgrammableColorActor(org.openhab.binding.tinkerforge.internal.model.ProgrammableColorActor) StopMoveType(org.openhab.core.library.types.StopMoveType) TinkerforgeBindingProvider(org.openhab.binding.tinkerforge.TinkerforgeBindingProvider) HighLowValue(org.openhab.binding.tinkerforge.internal.types.HighLowValue) HSBType(org.openhab.core.library.types.HSBType) ProgrammableSwitchActor(org.openhab.binding.tinkerforge.internal.model.ProgrammableSwitchActor) OnOffValue(org.openhab.binding.tinkerforge.internal.types.OnOffValue) SetPointActor(org.openhab.binding.tinkerforge.internal.model.SetPointActor) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) DigitalActor(org.openhab.binding.tinkerforge.internal.model.DigitalActor) OnOffType(org.openhab.core.library.types.OnOffType) MoveActor(org.openhab.binding.tinkerforge.internal.model.MoveActor) DimmableActor(org.openhab.binding.tinkerforge.internal.model.DimmableActor) MTextActor(org.openhab.binding.tinkerforge.internal.model.MTextActor) DecimalType(org.openhab.core.library.types.DecimalType) NumberActor(org.openhab.binding.tinkerforge.internal.model.NumberActor) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) SimpleColorActor(org.openhab.binding.tinkerforge.internal.model.SimpleColorActor)

Aggregations

DigitalActor (org.openhab.binding.tinkerforge.internal.model.DigitalActor)3 MBaseDevice (org.openhab.binding.tinkerforge.internal.model.MBaseDevice)3 DimmableActor (org.openhab.binding.tinkerforge.internal.model.DimmableActor)2 MSensor (org.openhab.binding.tinkerforge.internal.model.MSensor)2 MSwitchActor (org.openhab.binding.tinkerforge.internal.model.MSwitchActor)2 MoveActor (org.openhab.binding.tinkerforge.internal.model.MoveActor)2 ProgrammableColorActor (org.openhab.binding.tinkerforge.internal.model.ProgrammableColorActor)2 ProgrammableSwitchActor (org.openhab.binding.tinkerforge.internal.model.ProgrammableSwitchActor)2 SetPointActor (org.openhab.binding.tinkerforge.internal.model.SetPointActor)2 SimpleColorActor (org.openhab.binding.tinkerforge.internal.model.SimpleColorActor)2 TinkerforgeBindingProvider (org.openhab.binding.tinkerforge.TinkerforgeBindingProvider)1 ColorActor (org.openhab.binding.tinkerforge.internal.model.ColorActor)1 MBrickd (org.openhab.binding.tinkerforge.internal.model.MBrickd)1 MTextActor (org.openhab.binding.tinkerforge.internal.model.MTextActor)1 NumberActor (org.openhab.binding.tinkerforge.internal.model.NumberActor)1 PercentTypeActor (org.openhab.binding.tinkerforge.internal.model.PercentTypeActor)1 SwitchSensor (org.openhab.binding.tinkerforge.internal.model.SwitchSensor)1 HighLowValue (org.openhab.binding.tinkerforge.internal.types.HighLowValue)1 OnOffValue (org.openhab.binding.tinkerforge.internal.types.OnOffValue)1 Item (org.openhab.core.items.Item)1