use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.impl.DeviceConsumptionSensorJob in project smarthome by eclipse.
the class DeviceStatusManagerImpl method sendComandsToDSS.
@Override
public synchronized void sendComandsToDSS(Device device, DeviceStateUpdate deviceStateUpdate) {
boolean requestSuccsessful = false;
boolean commandHasNoEffect = false;
if (deviceStateUpdate != null) {
if (deviceStateUpdate.isSensorUpdateType()) {
SensorEnum sensorType = deviceStateUpdate.getTypeAsSensorEnum();
if (deviceStateUpdate.getValueAsInteger() == 0) {
updateSensorData(new DeviceConsumptionSensorJob(device, sensorType), device.getPowerSensorRefreshPriority(sensorType));
return;
} else if (deviceStateUpdate.getValueAsInteger() < 0) {
removeSensorJob(device, deviceStateUpdate);
return;
} else {
int consumption = this.digitalSTROMClient.getDeviceSensorValue(connMan.getSessionToken(), device.getDSID(), null, null, device.getSensorIndex(sensorType));
if (consumption >= 0) {
device.setDeviceSensorDsValueBySensorJob(sensorType, consumption);
requestSuccsessful = true;
}
}
} else {
switch(deviceStateUpdate.getType()) {
case DeviceStateUpdate.OUTPUT_DECREASE:
case DeviceStateUpdate.SLAT_DECREASE:
if (checkIsAllreadyMinMax(device) != 0) {
requestSuccsessful = digitalSTROMClient.decreaseValue(connMan.getSessionToken(), device.getDSID(), null, null);
if (requestSuccsessful) {
sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.DECREMENT.getSceneNumber());
}
} else {
commandHasNoEffect = true;
}
break;
case DeviceStateUpdate.OUTPUT_INCREASE:
case DeviceStateUpdate.SLAT_INCREASE:
if (checkIsAllreadyMinMax(device) != 1) {
requestSuccsessful = digitalSTROMClient.increaseValue(connMan.getSessionToken(), device.getDSID(), null, null);
if (requestSuccsessful) {
sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.INCREMENT.getSceneNumber());
}
} else {
commandHasNoEffect = true;
}
break;
case DeviceStateUpdate.OUTPUT:
if (device.getOutputValue() != deviceStateUpdate.getValueAsInteger()) {
requestSuccsessful = digitalSTROMClient.setDeviceValue(connMan.getSessionToken(), device.getDSID(), null, null, deviceStateUpdate.getValueAsInteger());
} else {
commandHasNoEffect = true;
}
break;
case DeviceStateUpdate.OPEN_CLOSE:
case DeviceStateUpdate.ON_OFF:
if (deviceStateUpdate.getValueAsInteger() > 0) {
if (checkIsAllreadyMinMax(device) != 1) {
requestSuccsessful = digitalSTROMClient.turnDeviceOn(connMan.getSessionToken(), device.getDSID(), null, null);
if (requestSuccsessful) {
sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.MAXIMUM.getSceneNumber());
}
} else {
commandHasNoEffect = true;
}
} else {
if (checkIsAllreadyMinMax(device) != 0) {
requestSuccsessful = digitalSTROMClient.turnDeviceOff(connMan.getSessionToken(), device.getDSID(), null, null);
if (requestSuccsessful) {
sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.MINIMUM.getSceneNumber());
}
} else {
commandHasNoEffect = true;
}
}
break;
case DeviceStateUpdate.SLATPOSITION:
if (device.getSlatPosition() != deviceStateUpdate.getValueAsInteger()) {
requestSuccsessful = digitalSTROMClient.setDeviceOutputValue(connMan.getSessionToken(), device.getDSID(), null, null, DeviceConstants.DEVICE_SENSOR_SLAT_POSITION_OUTPUT, deviceStateUpdate.getValueAsInteger());
} else {
commandHasNoEffect = true;
}
break;
case DeviceStateUpdate.SLAT_STOP:
this.sendStopComandsToDSS(device);
break;
case DeviceStateUpdate.SLAT_MOVE:
if (deviceStateUpdate.getValueAsInteger() > 0) {
requestSuccsessful = digitalSTROMClient.turnDeviceOn(connMan.getSessionToken(), device.getDSID(), null, null);
if (requestSuccsessful) {
sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.MAXIMUM.getSceneNumber());
}
} else {
requestSuccsessful = digitalSTROMClient.turnDeviceOff(connMan.getSessionToken(), device.getDSID(), null, null);
if (requestSuccsessful) {
sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.MINIMUM.getSceneNumber());
}
if (sensorJobExecutor != null) {
sensorJobExecutor.removeSensorJobs(device);
}
}
break;
case DeviceStateUpdate.UPDATE_CALL_SCENE:
if (SceneEnum.getScene((short) deviceStateUpdate.getValue()) != null) {
requestSuccsessful = digitalSTROMClient.callDeviceScene(connMan.getSessionToken(), device.getDSID(), null, null, SceneEnum.getScene((short) deviceStateUpdate.getValue()), true);
}
break;
case DeviceStateUpdate.UPDATE_UNDO_SCENE:
if (SceneEnum.getScene((short) deviceStateUpdate.getValue()) != null) {
requestSuccsessful = digitalSTROMClient.undoDeviceScene(connMan.getSessionToken(), device.getDSID(), null, null, SceneEnum.getScene((short) deviceStateUpdate.getValue()));
}
break;
case DeviceStateUpdate.SLAT_ANGLE_DECREASE:
// By UPDATE_SLAT_ANGLE_DECREASE, UPDATE_SLAT_ANGLE_INCREASE with value unequal 1 which will
// handled in the pollingRunnable and UPDATE_OPEN_CLOSE_ANGLE the value will be set without
// checking, because it was triggered by setting the slat position.
requestSuccsessful = true;
break;
case DeviceStateUpdate.SLAT_ANGLE_INCREASE:
requestSuccsessful = true;
break;
case DeviceStateUpdate.OPEN_CLOSE_ANGLE:
requestSuccsessful = true;
break;
case DeviceStateUpdate.SLAT_ANGLE:
if (device.getAnglePosition() != deviceStateUpdate.getValueAsInteger()) {
requestSuccsessful = digitalSTROMClient.setDeviceOutputValue(connMan.getSessionToken(), device.getDSID(), null, null, DeviceConstants.DEVICE_SENSOR_SLAT_ANGLE_OUTPUT, deviceStateUpdate.getValueAsInteger());
} else {
commandHasNoEffect = true;
}
break;
case DeviceStateUpdate.REFRESH_OUTPUT:
readOutputValue(device);
logger.debug("Inizalize output value reading for device with dSID {}.", device.getDSID().getValue());
return;
default:
return;
}
}
if (commandHasNoEffect) {
logger.debug("Command {} for device with dSID {} not send to dSS, because it has no effect!", deviceStateUpdate.getType(), device.getDSID().getValue());
return;
}
if (requestSuccsessful) {
logger.debug("Send {} command to dSS and updateInternalDeviceState for device with dSID {}.", deviceStateUpdate.getType(), device.getDSID().getValue());
device.updateInternalDeviceState(deviceStateUpdate);
} else {
logger.debug("Can't send {} command for device with dSID {} to dSS!", deviceStateUpdate.getType(), device.getDSID().getValue());
}
}
}
Aggregations