Search in sources :

Example 1 with DeviceStateUpdateImpl

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

the class DeviceHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    BridgeHandler dssBridgeHandler = getDssBridgeHandler();
    if (dssBridgeHandler == null) {
        logger.debug("BridgeHandler not found. Cannot handle command without bridge.");
        return;
    }
    if (device == null) {
        logger.debug("Device not known on StructureManager or DeviceStatusListener is not registerd. Cannot handle command.");
        return;
    }
    if (command instanceof RefreshType) {
        try {
            SensorEnum sensorType = SensorEnum.valueOf(channelUID.getId());
            dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(sensorType, 1));
        } catch (IllegalArgumentException e) {
            dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(DeviceStateUpdate.REFRESH_OUTPUT, 0));
        }
    } else if (!device.isShade()) {
        if (DsChannelTypeProvider.isOutputChannel(channelUID.getId())) {
            if (command instanceof PercentType) {
                device.setOutputValue((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxOutputValue()));
            } else if (command instanceof OnOffType) {
                if (OnOffType.ON.equals(command)) {
                    device.setIsOn(true);
                } else {
                    device.setIsOn(false);
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (IncreaseDecreaseType.INCREASE.equals(command)) {
                    device.increase();
                } else {
                    device.decrease();
                }
            } else if (command instanceof StringType) {
                device.setOutputValue(Short.parseShort(((StringType) command).toString()));
            }
        } else {
            logger.debug("Command sent to an unknown channel id: {}", channelUID);
        }
    } else {
        if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
            if (command instanceof PercentType) {
                device.setAnglePosition((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxSlatAngle()));
            } else if (command instanceof OnOffType) {
                if (OnOffType.ON.equals(command)) {
                    device.setAnglePosition(device.getMaxSlatAngle());
                } else {
                    device.setAnglePosition(device.getMinSlatAngle());
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (IncreaseDecreaseType.INCREASE.equals(command)) {
                    device.increaseSlatAngle();
                } else {
                    device.decreaseSlatAngle();
                }
            }
        } else if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
            if (command instanceof PercentType) {
                int percent = ((PercentType) command).intValue();
                if (!device.getHWinfo().equals("GR-KL200")) {
                    percent = 100 - percent;
                }
                device.setSlatPosition(fromPercentToValue(percent, device.getMaxSlatPosition()));
                this.lastComand = command;
            } else if (command instanceof StopMoveType) {
                if (StopMoveType.MOVE.equals(command)) {
                    handleCommand(channelUID, this.lastComand);
                } else {
                    dssBridgeHandler.stopOutputValue(device);
                }
            } else if (command instanceof UpDownType) {
                if (UpDownType.UP.equals(command)) {
                    device.setIsOpen(true);
                    this.lastComand = command;
                } else {
                    device.setIsOpen(false);
                    this.lastComand = command;
                }
            }
        } else {
            logger.debug("Command sent to an unknown channel id: {}", channelUID);
        }
    }
}
Also used : SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) UpDownType(org.eclipse.smarthome.core.library.types.UpDownType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) StopMoveType(org.eclipse.smarthome.core.library.types.StopMoveType)

Example 2 with DeviceStateUpdateImpl

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

the class DeviceHandler method onDeviceStateChanged.

@Override
public synchronized void onDeviceStateChanged(DeviceStateUpdate deviceStateUpdate) {
    if (device != null) {
        if (deviceStateUpdate != null) {
            if (sensorChannelsLoaded()) {
                if (deviceStateUpdate.isSensorUpdateType()) {
                    updateState(getSensorChannelID(deviceStateUpdate.getTypeAsSensorEnum()), new DecimalType(deviceStateUpdate.getValueAsFloat()));
                    logger.debug("Update ESH-State");
                    return;
                }
                if (deviceStateUpdate.isBinarayInputType()) {
                    if (deviceStateUpdate.getValueAsShort() == 1) {
                        updateState(getBinaryInputChannelID(deviceStateUpdate.getTypeAsDeviceBinarayInputEnum()), OnOffType.ON);
                    } else {
                        updateState(getBinaryInputChannelID(deviceStateUpdate.getTypeAsDeviceBinarayInputEnum()), OnOffType.OFF);
                    }
                }
            }
            if (!device.isShade()) {
                if (currentChannel != null) {
                    switch(deviceStateUpdate.getType()) {
                        case DeviceStateUpdate.OUTPUT_DECREASE:
                        case DeviceStateUpdate.OUTPUT_INCREASE:
                        case DeviceStateUpdate.OUTPUT:
                            if (currentChannel.contains(DsChannelTypeProvider.DIMMER)) {
                                if (deviceStateUpdate.getValueAsInteger() > 0) {
                                    updateState(currentChannel, new PercentType(fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxOutputValue())));
                                } else {
                                    updateState(currentChannel, OnOffType.OFF);
                                }
                            } else if (currentChannel.contains(DsChannelTypeProvider.STAGE)) {
                                if (currentChannel.contains(TWO_STAGE_SWITCH_IDENTICATOR)) {
                                    updateState(currentChannel, new StringType(convertStageValue((short) 2, device.getOutputValue())));
                                } else {
                                    updateState(currentChannel, new StringType(convertStageValue((short) 3, device.getOutputValue())));
                                }
                            }
                            break;
                        case DeviceStateUpdate.ON_OFF:
                            if (currentChannel.contains(DsChannelTypeProvider.STAGE)) {
                                onDeviceStateChanged(new DeviceStateUpdateImpl(DeviceStateUpdate.OUTPUT, device.getOutputValue()));
                            }
                            if (deviceStateUpdate.getValueAsInteger() > 0) {
                                updateState(currentChannel, OnOffType.ON);
                            } else {
                                updateState(currentChannel, OnOffType.OFF);
                            }
                            break;
                        default:
                            return;
                    }
                }
            } else {
                int percent = 0;
                switch(deviceStateUpdate.getType()) {
                    case DeviceStateUpdate.SLAT_DECREASE:
                    case DeviceStateUpdate.SLAT_INCREASE:
                    case DeviceStateUpdate.SLATPOSITION:
                        percent = fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxSlatPosition());
                        break;
                    case DeviceStateUpdate.OPEN_CLOSE:
                        if (deviceStateUpdate.getValueAsInteger() > 0) {
                            percent = 100;
                        }
                        break;
                    case DeviceStateUpdate.OPEN_CLOSE_ANGLE:
                        if (device.isBlind() && currentChannel != null) {
                            if (deviceStateUpdate.getValueAsInteger() > 0) {
                                updateState(currentChannel, PercentType.HUNDRED);
                            } else {
                                updateState(currentChannel, PercentType.ZERO);
                            }
                        }
                        return;
                    case DeviceStateUpdate.SLAT_ANGLE_DECREASE:
                    case DeviceStateUpdate.SLAT_ANGLE_INCREASE:
                    case DeviceStateUpdate.SLAT_ANGLE:
                        if (device.isBlind() && currentChannel != null) {
                            updateState(currentChannel, new PercentType(fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxSlatAngle())));
                        }
                        return;
                    default:
                        return;
                }
                if (!device.getHWinfo().equals("GR-KL210")) {
                    percent = 100 - percent;
                }
                updateState(DsChannelTypeProvider.SHADE, new PercentType(percent));
            }
            logger.debug("Update ESH-State");
        }
    }
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 3 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 setCachedMeterData.

private void setCachedMeterData() {
    logger.debug("load cached sensor data device with dsid {}", dsid.getValue());
    Integer[] cachedSensorData = this.cachedSensorPowerValues.get(this.getOutputValue());
    if (cachedSensorData != null) {
        if (cachedSensorData[ACTIVE_POWER_ARRAY_FIELD] != null && !checkPowerSensorRefreshPriorityNever(SensorEnum.ACTIVE_POWER)) {
            informListenerAboutStateUpdate(new DeviceStateUpdateImpl(SensorEnum.ACTIVE_POWER, (float) cachedSensorData[ACTIVE_POWER_ARRAY_FIELD]));
        }
        if (cachedSensorData[OUTPUT_CURRENT_ARRAY_FIELD] != null && !checkPowerSensorRefreshPriorityNever(SensorEnum.OUTPUT_CURRENT)) {
            if (cachedSensorData[OUTPUT_CURRENT_ARRAY_FIELD] == SensorEnum.OUTPUT_CURRENT.getMax().intValue() && devicePowerSensorTypes.contains(SensorEnum.OUTPUT_CURRENT_H)) {
                informListenerAboutStateUpdate(new DeviceStateUpdateImpl(SensorEnum.OUTPUT_CURRENT, cachedSensorData[OUTPUT_CURRENT_HIGH_ARRAY_FIELD]));
            } else {
                informListenerAboutStateUpdate(new DeviceStateUpdateImpl(SensorEnum.OUTPUT_CURRENT, cachedSensorData[OUTPUT_CURRENT_ARRAY_FIELD]));
            }
        }
        if (cachedSensorData[ACTIVE_POWER_ARRAY_FIELD] != null && !checkPowerSensorRefreshPriorityNever(SensorEnum.POWER_CONSUMPTION)) {
            informListenerAboutStateUpdate(new DeviceStateUpdateImpl(SensorEnum.ACTIVE_POWER, cachedSensorData[ACTIVE_POWER_ARRAY_FIELD]));
        }
    }
}
Also used : DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)

Example 4 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 setBinaryInputState.

@Override
public boolean setBinaryInputState(DeviceBinarayInputEnum binaryInputType, Short newState) {
    DeviceBinaryInput devBinInput = getBinaryInput(binaryInputType);
    if (devBinInput != null) {
        devBinInput.setState(newState);
        informListenerAboutStateUpdate(new DeviceStateUpdateImpl(binaryInputType, newState));
        return true;
    }
    return false;
}
Also used : DeviceBinaryInput(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceBinaryInput) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)

Example 5 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 isPowerSensorUpToDate.

@Override
public boolean isPowerSensorUpToDate(SensorEnum powerSensorType) {
    if (powerSensorType != null && SensorEnum.isPowerSensor(powerSensorType)) {
        boolean isUpToDate = true;
        if (powerSensorType.equals(SensorEnum.ACTIVE_POWER)) {
            isUpToDate = (outputMode != null && outputMode.equals(OutputModeEnum.WIPE) && !isOn) || (isOn && !isShade()) && !checkPowerSensorRefreshPriorityNever(powerSensorType) ? checkSensorRefreshTime(powerSensorType) : true;
        }
        if (powerSensorType.equals(SensorEnum.ELECTRIC_METER)) {
            isUpToDate = (isOn || getDeviceSensorValue(powerSensorType).getDsValue() == 0) && !isShade() && !checkPowerSensorRefreshPriorityNever(powerSensorType) ? checkSensorRefreshTime(powerSensorType) : true;
        }
        isUpToDate = isOn && !isShade() && !checkPowerSensorRefreshPriorityNever(powerSensorType) ? checkSensorRefreshTime(powerSensorType) : true;
        if (!isUpToDate) {
            if (!getSensorDataReadingInitialized(powerSensorType)) {
                deviceStateUpdates.add(new DeviceStateUpdateImpl(powerSensorType, 0));
                setSensorDataReadingInitialized(powerSensorType, true);
            }
            return false;
        }
        return true;
    }
    throw new IllegalArgumentException("powerSensorType is null or not a power sensor type.");
}
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