Search in sources :

Example 11 with DeviceStateUpdateImpl

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl in project smarthome by eclipse.

the class DeviceImpl method updateInternalDeviceState.

@Override
public synchronized void updateInternalDeviceState(DeviceStateUpdate deviceStateUpdate) {
    if (deviceStateUpdate != null) {
        logger.debug("internal set outputvalue");
        switch(deviceStateUpdate.getType()) {
            case DeviceStateUpdate.OUTPUT_DECREASE:
                deviceStateUpdate = new DeviceStateUpdateImpl(DeviceStateUpdate.OUTPUT_DECREASE, internalSetOutputValue(outputValue - getDimmStep()));
                break;
            case DeviceStateUpdate.OUTPUT_INCREASE:
                deviceStateUpdate = new DeviceStateUpdateImpl(DeviceStateUpdate.OUTPUT_INCREASE, internalSetOutputValue(outputValue + getDimmStep()));
                break;
            case DeviceStateUpdate.OUTPUT:
                internalSetOutputValue(deviceStateUpdate.getValueAsInteger());
                break;
            case DeviceStateUpdate.ON_OFF:
                if (deviceStateUpdate.getValueAsInteger() < 0) {
                    internalSetOutputValue(0);
                } else {
                    internalSetOutputValue(maxOutputValue);
                }
                break;
            case DeviceStateUpdate.OPEN_CLOSE:
                if (deviceStateUpdate.getValueAsInteger() < 0) {
                    internalSetOutputValue(0);
                } else {
                    internalSetOutputValue(maxSlatPosition);
                }
                break;
            case DeviceStateUpdate.OPEN_CLOSE_ANGLE:
                if (deviceStateUpdate.getValueAsInteger() < 0) {
                    internalSetAngleValue(0);
                } else {
                    internalSetAngleValue(maxSlatAngle);
                }
                break;
            case DeviceStateUpdate.SLAT_DECREASE:
                deviceStateUpdate = new DeviceStateUpdateImpl(DeviceStateUpdate.SLAT_DECREASE, internalSetOutputValue(slatPosition - getDimmStep()));
                break;
            case DeviceStateUpdate.SLAT_INCREASE:
                deviceStateUpdate = new DeviceStateUpdateImpl(DeviceStateUpdate.SLAT_INCREASE, internalSetOutputValue(slatPosition + getDimmStep()));
            case DeviceStateUpdate.SLATPOSITION:
                internalSetOutputValue(deviceStateUpdate.getValueAsInteger());
                break;
            case DeviceStateUpdate.SLAT_ANGLE_DECREASE:
                deviceStateUpdate = new DeviceStateUpdateImpl(DeviceStateUpdate.SLAT_ANGLE_DECREASE, internalSetAngleValue(slatAngle - DeviceConstants.ANGLE_STEP_SLAT));
                break;
            case DeviceStateUpdate.SLAT_ANGLE_INCREASE:
                deviceStateUpdate = new DeviceStateUpdateImpl(DeviceStateUpdate.SLAT_ANGLE_INCREASE, internalSetAngleValue(slatAngle + DeviceConstants.ANGLE_STEP_SLAT));
                break;
            case DeviceStateUpdate.SLAT_ANGLE:
                internalSetAngleValue(deviceStateUpdate.getValueAsInteger());
                break;
            case DeviceStateUpdate.UPDATE_CALL_SCENE:
                this.internalCallScene(deviceStateUpdate.getValueAsShort());
                return;
            case DeviceStateUpdate.UPDATE_UNDO_SCENE:
                this.internalUndoScene();
                return;
            default:
                if (deviceStateUpdate.isSensorUpdateType()) {
                    SensorEnum sensorType = deviceStateUpdate.getTypeAsSensorEnum();
                    setFloatSensorValue(sensorType, deviceStateUpdate.getValueAsFloat());
                }
                return;
        }
    }
    if (activeScene != null) {
        Integer[] sceneOutput = getStandartSceneOutput(activeScene.getSceneID());
        if (sceneOutput == null) {
            sceneOutput = sceneOutputMap.get(activeScene.getSceneID());
        }
        if (sceneOutput != null) {
            boolean outputChanged = false;
            if (isShade()) {
                if (isBlind() && sceneOutput[1] != slatAngle) {
                    logger.debug("Scene output angle: {} setted output value {}", sceneOutput[1], slatAngle);
                    outputChanged = true;
                }
                if (sceneOutput[0] != slatPosition) {
                    logger.debug("Scene output value: {} setted output value {}", sceneOutput[0], slatPosition);
                    outputChanged = true;
                }
            } else {
                if (sceneOutput[0] != outputValue) {
                    logger.debug("Scene output value: {} setted output value {}", sceneOutput[0], outputValue);
                    outputChanged = true;
                }
            }
            if (outputChanged) {
                logger.debug("Device output from Device with dSID {} changed deactivate scene {}", dsid.getValue(), activeScene.getID());
                activeScene.deviceSceneChanged((short) -1);
                lastScene = null;
                activeScene = null;
            }
        } else {
            lastScene = null;
        }
    }
    informListenerAboutStateUpdate(deviceStateUpdate);
}
Also used : SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)

Example 12 with DeviceStateUpdateImpl

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl in project smarthome by eclipse.

the class DeviceImpl method informListenerAboutStateUpdate.

/**
 * if an {@link DeviceStatusListener} is registered inform him about the new state otherwise do nothing.
 *
 * @param deviceStateUpdate
 */
private void informListenerAboutStateUpdate(DeviceStateUpdate deviceStateUpdate) {
    if (listener != null) {
        if (isSwitch() && deviceStateUpdate.getType().equals(DeviceStateUpdate.OUTPUT)) {
            if (deviceStateUpdate.getValueAsInteger() >= switchPercentOff) {
                deviceStateUpdate = new DeviceStateUpdateImpl(DeviceStateUpdate.ON_OFF, DeviceStateUpdate.ON_VALUE);
            } else {
                deviceStateUpdate = new DeviceStateUpdateImpl(DeviceStateUpdate.ON_OFF, DeviceStateUpdate.OFF_VALUE);
            }
        }
        logger.debug("Inform listener about device state changed: type: {}", deviceStateUpdate.getType() + ", value: " + deviceStateUpdate.getValue());
        listener.onDeviceStateChanged(deviceStateUpdate);
    }
}
Also used : DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)

Example 13 with DeviceStateUpdateImpl

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl in project smarthome by eclipse.

the class DeviceOutputValueSensorJob method execute.

@Override
public void execute(DsAPI digitalSTROM, String token) {
    int value = digitalSTROM.getDeviceOutputValue(token, this.device.getDSID(), null, null, index);
    logger.debug("Device output value on Demand : {}, dSID: {}", value, this.device.getDSID().getValue());
    if (value != 1) {
        switch(this.index) {
            case 0:
                this.device.updateInternalDeviceState(new DeviceStateUpdateImpl(DeviceStateUpdate.OUTPUT, value));
                return;
            case 2:
                this.device.updateInternalDeviceState(new DeviceStateUpdateImpl(DeviceStateUpdate.SLATPOSITION, value));
                if (device.isBlind()) {
                    value = digitalSTROM.getDeviceOutputValue(token, this.device.getDSID(), null, null, DeviceConstants.DEVICE_SENSOR_SLAT_ANGLE_OUTPUT);
                    logger.debug("Device angle output value on Demand : {}, dSID: {}", value, this.device.getDSID().getValue());
                    if (value != 1) {
                        this.device.updateInternalDeviceState(new DeviceStateUpdateImpl(DeviceStateUpdate.SLAT_ANGLE, value));
                    }
                }
                return;
            default:
                return;
        }
    }
}
Also used : DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)

Aggregations

DeviceStateUpdateImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)13 SensorEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum)3 PercentType (org.eclipse.smarthome.core.library.types.PercentType)2 StringType (org.eclipse.smarthome.core.library.types.StringType)2 DeviceBinaryInput (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceBinaryInput)1 DeviceSensorValue (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceSensorValue)1 JSONDeviceSceneSpecImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.JSONDeviceSceneSpecImpl)1 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)1 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1 StopMoveType (org.eclipse.smarthome.core.library.types.StopMoveType)1 UpDownType (org.eclipse.smarthome.core.library.types.UpDownType)1 RefreshType (org.eclipse.smarthome.core.types.RefreshType)1