use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum in project smarthome by eclipse.
the class DeviceHandler method checkSensorChannel.
private void checkSensorChannel() {
List<Channel> channelList = new LinkedList<Channel>(this.getThing().getChannels());
boolean channelListChanged = false;
// if sensor channels with priority never are loaded delete these channels
if (!channelList.isEmpty()) {
Iterator<Channel> channelInter = channelList.iterator();
while (channelInter.hasNext()) {
Channel channel = channelInter.next();
String channelID = channel.getUID().getId();
if (channelID.startsWith(DsChannelTypeProvider.BINARY_INPUT_PRE)) {
DeviceBinarayInputEnum devBinInput = getBinaryInput(channelID);
if (device.getBinaryInput(devBinInput) != null) {
addLoadedSensorChannel(channelID);
} else {
logger.debug("remove {} binary input channel", channelID);
channelInter.remove();
channelListChanged = removeLoadedSensorChannel(channelID);
}
} else {
SensorEnum sensorType = getSensorEnum(channelID);
if (sensorType != null) {
if (SensorEnum.isPowerSensor(sensorType)) {
if (device.checkPowerSensorRefreshPriorityNever(sensorType)) {
logger.debug("remove {} sensor channel", channelID);
channelInter.remove();
channelListChanged = removeLoadedSensorChannel(channelID);
} else {
addLoadedSensorChannel(channelID);
}
} else {
if (device.supportsSensorType(sensorType)) {
addLoadedSensorChannel(channelID);
} else {
logger.debug("remove {} sensor channel", channelID);
channelInter.remove();
removeLoadedSensorChannel(channelID);
channelListChanged = true;
}
}
}
}
}
}
for (SensorEnum sensorType : device.getPowerSensorTypes()) {
if (!device.checkPowerSensorRefreshPriorityNever(sensorType) && !isSensorChannelLoaded(getSensorChannelID(sensorType))) {
logger.debug("create {} sensor channel", sensorType.toString());
channelList.add(getSensorChannel(sensorType));
channelListChanged = addLoadedSensorChannel(getSensorChannelID(sensorType));
}
}
if (device.hasClimateSensors()) {
for (SensorEnum sensorType : device.getClimateSensorTypes()) {
if (!isSensorChannelLoaded(getSensorChannelID(sensorType))) {
logger.debug("create {} sensor channel", sensorType.toString());
channelList.add(getSensorChannel(sensorType));
channelListChanged = addLoadedSensorChannel(getSensorChannelID(sensorType));
}
}
}
if (device.isBinaryInputDevice()) {
for (DeviceBinaryInput binInput : device.getBinaryInputs()) {
DeviceBinarayInputEnum binInputType = DeviceBinarayInputEnum.getdeviceBinarayInput(binInput.getInputType());
if (binInputType != null && !isSensorChannelLoaded(getBinaryInputChannelID(binInputType))) {
logger.debug("create {} sensor channel", binInputType.toString());
channelList.add(getBinaryChannel(binInputType));
channelListChanged = addLoadedSensorChannel(getBinaryInputChannelID(binInputType));
}
}
}
if (channelListChanged) {
logger.debug("load new channel list");
ThingBuilder thingBuilder = editThing();
thingBuilder.withChannels(channelList);
updateThing(thingBuilder.build());
}
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum 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);
}
}
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum in project smarthome by eclipse.
the class DeviceHandler method channelLinked.
@Override
public void channelLinked(ChannelUID channelUID) {
if (device != null) {
SensorEnum sensorType = getSensorEnum(channelUID.getId());
if (sensorType != null) {
Float val = device.getFloatSensorValue(sensorType);
if (val != null) {
updateState(channelUID, new DecimalType(val));
}
}
Short val = device.getBinaryInputState(getBinaryInput(channelUID.getId()));
if (val != null) {
if (val == 1) {
updateState(channelUID, OnOffType.ON);
} else {
updateState(channelUID, OnOffType.OFF);
}
}
if (channelUID.getId().contains(DsChannelTypeProvider.DIMMER)) {
if (device.isOn()) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getOutputValue(), device.getMaxOutputValue())));
} else {
updateState(channelUID, new PercentType(0));
}
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.SWITCH)) {
if (device.isOn()) {
updateState(channelUID, OnOffType.ON);
} else {
updateState(channelUID, OnOffType.OFF);
}
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getSlatPosition(), device.getMaxSlatPosition())));
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getAnglePosition(), device.getMaxSlatAngle())));
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.STAGE)) {
if (channelUID.getId().contains(TWO_STAGE_SWITCH_IDENTICATOR)) {
updateState(channelUID, new StringType(convertStageValue((short) 2, device.getOutputValue())));
return;
}
if (channelUID.getId().contains(THREE_STAGE_SWITCH_IDENTICATOR)) {
updateState(channelUID, new StringType(convertStageValue((short) 3, device.getOutputValue())));
return;
}
}
}
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum in project smarthome by eclipse.
the class BaseSensorValues method addSensorValue.
/**
* Adds a sensor value through the digitalSTROM-API response as {@link JsonObject}. The boolean outdoor has to be
* set to indicate that it is an outdoor or indoor value (needed to choose the right sensor type).
*
* @param jObject must not be null
* @param outdoor (true = outdoor; false = indoor)
*/
protected void addSensorValue(JsonObject jObject, boolean outdoor) {
if (jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE.getKey()) != null) {
SensorEnum sensorType = SensorEnum.TEMPERATURE_INDOORS;
if (outdoor) {
sensorType = SensorEnum.TEMPERATURE_OUTDOORS;
}
addSensorValue(new CachedSensorValue(sensorType, jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE.getKey()).getAsFloat(), jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE_TIME.getKey()).getAsString()));
}
if (jObject.get(JSONApiResponseKeysEnum.HUMIDITY_VALUE.getKey()) != null) {
SensorEnum sensorType = SensorEnum.RELATIVE_HUMIDITY_INDOORS;
if (outdoor) {
sensorType = SensorEnum.RELATIVE_HUMIDITY_OUTDOORS;
}
addSensorValue(new CachedSensorValue(sensorType, jObject.get(JSONApiResponseKeysEnum.HUMIDITY_VALUE.getKey()).getAsFloat(), jObject.get(JSONApiResponseKeysEnum.HUMIDITY_VALUE_TIME.getKey()).getAsString()));
}
if (jObject.get(JSONApiResponseKeysEnum.CO2_CONCENTRATION_VALUE.getKey()) != null) {
addSensorValue(new CachedSensorValue(SensorEnum.CARBON_DIOXIDE, jObject.get(JSONApiResponseKeysEnum.CO2_CONCENTRATION_VALUE.getKey()).getAsFloat(), jObject.get(JSONApiResponseKeysEnum.CO2_CONCENTRATION_VALUE_TIME.getKey()).getAsString()));
}
if (jObject.get(JSONApiResponseKeysEnum.BRIGHTNESS_VALUE.getKey()) != null) {
SensorEnum sensorType = SensorEnum.BRIGHTNESS_INDOORS;
if (outdoor) {
sensorType = SensorEnum.BRIGHTNESS_OUTDOORS;
}
addSensorValue(new CachedSensorValue(sensorType, jObject.get(JSONApiResponseKeysEnum.BRIGHTNESS_VALUE.getKey()).getAsFloat(), jObject.get(JSONApiResponseKeysEnum.BRIGHTNESS_VALUE_TIME.getKey()).getAsString()));
}
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum 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