diff --git a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDatapointGroup.java b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDatapointGroup.java index b3223083a24ce..edd7bbdaef951 100644 --- a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDatapointGroup.java +++ b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDatapointGroup.java @@ -100,20 +100,25 @@ boolean addDatapointToGroup(int direction, int neededPairingId, String channelId public void applyChangesForVirtualDevice() { // The input and output datapoints are ment from the device point of view. Because the virtual dvices are // outside of the free@home system the input and output datapoint must be switched - FreeAtHomeDatapoint localDatapoint = inputDatapoint; inputDatapoint = outputDatapoint; outputDatapoint = localDatapoint; - // if the datapoint was a ouput only, the inout part must be added here - if (outputDatapoint == null) { - outputDatapoint = inputDatapoint; + if (inputDatapoint != null && outputDatapoint != null) { + datapointGroupDirection = DATAPOINTGROUP_DIRECTION_INPUTOUTPUT; + } else { + if (inputDatapoint == null && outputDatapoint != null) { + datapointGroupDirection = DATAPOINTGROUP_DIRECTION_OUTPUT; + } else { + if (inputDatapoint != null && outputDatapoint == null) { + datapointGroupDirection = DATAPOINTGROUP_DIRECTION_INPUT; + } else { + datapointGroupDirection = DATAPOINTGROUP_DIRECTION_UNDEFINED; + } + } } - // Only input or output is not possible, therefore patch the direction also - datapointGroupDirection = DATAPOINTGROUP_DIRECTION_INPUTOUTPUT; - return; } diff --git a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDeviceChannel.java b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDeviceChannel.java index 4dbd9c1039e00..a22ae7cb81c1f 100644 --- a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDeviceChannel.java +++ b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDeviceChannel.java @@ -261,7 +261,7 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO case FID_BRIGHTNESS_SENSOR: { this.channelId = channelId; - logger.info("Shutter actuator channel - Channel FID: {}", channelFunctionID); + logger.info("Brightnes sensor channel - Channel FID: {}", channelFunctionID); FreeAtHomeDatapointGroup newDatapointGroup = new FreeAtHomeDatapointGroup(); newDatapointGroup.addDatapointToGroup(DATAPOINT_DIRECTION_OUTPUT, 1026, channelId, channelObject); @@ -276,7 +276,7 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO case FID_RAIN_SENSOR: { this.channelId = channelId; - logger.info("Shutter actuator channel - Channel FID: {}", channelFunctionID); + logger.info("Rain sensor channel - Channel FID: {}", channelFunctionID); FreeAtHomeDatapointGroup newDatapointGroup = new FreeAtHomeDatapointGroup(); newDatapointGroup.addDatapointToGroup(DATAPOINT_DIRECTION_OUTPUT, 39, channelId, channelObject); @@ -295,7 +295,7 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO case FID_TEMPERATURE_SENSOR: { this.channelId = channelId; - logger.info("Shutter actuator channel - Channel FID: {}", channelFunctionID); + logger.info("Temperature sensor channel - Channel FID: {}", channelFunctionID); FreeAtHomeDatapointGroup newDatapointGroup = new FreeAtHomeDatapointGroup(); newDatapointGroup.addDatapointToGroup(DATAPOINT_DIRECTION_OUTPUT, 38, channelId, channelObject); @@ -310,7 +310,7 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO case FID_WIND_SENSOR: { this.channelId = channelId; - logger.info("Shutter actuator channel - Channel FID: {}", channelFunctionID); + logger.info("Wind sensor channel - Channel FID: {}", channelFunctionID); FreeAtHomeDatapointGroup newDatapointGroup = new FreeAtHomeDatapointGroup(); newDatapointGroup.addDatapointToGroup(DATAPOINT_DIRECTION_OUTPUT, 37, channelId, channelObject); diff --git a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDeviceDescription.java b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDeviceDescription.java index c42d83a8ac17c..76cf591de74a5 100644 --- a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDeviceDescription.java +++ b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/datamodel/FreeAtHomeDeviceDescription.java @@ -133,6 +133,10 @@ public boolean isScene() { return sceneIsDetected; } + public boolean isVirtual() { + return (interfaceType == DEVICE_INTERFACE_VIRTUAL_TYPE) ? true : false; + } + public int getNumberOfChannels() { return listOfChannels.size(); } diff --git a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/ChannelUpdateHandler.java b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/ChannelUpdateHandler.java index fec1d7fc650a7..3e128ce6f408d 100644 --- a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/ChannelUpdateHandler.java +++ b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/ChannelUpdateHandler.java @@ -92,7 +92,15 @@ public boolean updateChannelByDatapointEvent(String eventDatapointID, String val if (datapointElement != null) { State state = datapointElement.valueStateConverter.convertToState(valueString); - datapointElement.thingHandler.handleEventBasedUpdate(datapointElement.channelUID, state); + FreeAtHomeDeviceHandler deviceHandler = (FreeAtHomeDeviceHandler) datapointElement.thingHandler; + + // Handle state change + deviceHandler.handleEventBasedUpdate(datapointElement.channelUID, state); + + // if it is virtual device, give a feedback to free@home also + if (deviceHandler.isThingHandlesVirtualDevice()) { + deviceHandler.feedbackForVirtualDevice(datapointElement.channelUID, valueString); + } ret = true; } diff --git a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/FreeAtHomeDeviceHandler.java b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/FreeAtHomeDeviceHandler.java index c6b69d5ab66c8..a7a0d9f29c2e3 100644 --- a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/FreeAtHomeDeviceHandler.java +++ b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/FreeAtHomeDeviceHandler.java @@ -126,9 +126,16 @@ public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { FreeAtHomeDatapointGroup dpg = mapChannelUID.get(channelUID); + String valueStr = "0"; - String valueStr = freeAtHomeBridge.getDatapoint(deviceID, dpg.getOutputDatapoint().channelId, - dpg.getOutputDatapoint().getDatapointId()); + // Check whether it is a INPUT only datapoint group + if (dpg.getDirection() == FreeAtHomeDatapointGroup.DATAPOINTGROUP_DIRECTION_INPUT) { + valueStr = freeAtHomeBridge.getDatapoint(deviceID, dpg.getInputDatapoint().channelId, + dpg.getInputDatapoint().getDatapointId()); + } else { + valueStr = freeAtHomeBridge.getDatapoint(deviceID, dpg.getOutputDatapoint().channelId, + dpg.getOutputDatapoint().getDatapointId()); + } ValueStateConverter vsc = dpg.getValueStateConverter(); @@ -171,8 +178,48 @@ public void handleCommand(ChannelUID channelUID, Command command) { }); } - logger.debug("Handle command switch {} - at channel {} - full command {}", deviceID, channelUID.getAsString(), - command.toFullString()); + logger.debug("Handle command for device {} - at channel {} - full command {}", deviceID, + channelUID.getAsString(), command.toFullString()); + } + + public void handleEventBasedUpdate(ChannelUID channelUID, State state) { + this.updateState(channelUID, state); + } + + public void feedbackForVirtualDevice(ChannelUID channelUID, String valueString) { + FreeAtHomeBridgeHandler freeAtHomeBridge = null; + + FreeAtHomeDatapointGroup dpg = mapChannelUID.get(channelUID); + + Bridge bridge = this.getBridge(); + + if (bridge != null) { + ThingHandler handler = bridge.getHandler(); + + if (handler instanceof FreeAtHomeBridgeHandler) { + freeAtHomeBridge = (FreeAtHomeBridgeHandler) handler; + } + } + + if (freeAtHomeBridge != null) { + updateStatus(ThingStatus.ONLINE); + } else { + updateStatus(ThingStatus.OFFLINE); + return; + } + + if ((dpg.getDirection() == FreeAtHomeDatapointGroup.DATAPOINTGROUP_DIRECTION_INPUT) + || (dpg.getDirection() == FreeAtHomeDatapointGroup.DATAPOINTGROUP_DIRECTION_INPUTOUTPUT)) { + freeAtHomeBridge.setDatapoint(deviceID, dpg.getInputDatapoint().channelId, + dpg.getInputDatapoint().getDatapointId(), valueString); + + logger.debug("Handle feedback for virtual device {} - at channel {} - value {}", deviceID, + channelUID.getAsString(), valueString); + + } else { + logger.debug("Handle feedback for virtual device {} - at channel {} - but only ubout DPG", deviceID, + channelUID.getAsString()); + } } public ChannelTypeUID createChannelTypeForDatapointgroup(FreeAtHomeDatapointGroup dpg, @@ -407,4 +454,8 @@ public void removeChannels() { mapChannelUID.clear(); } + + public boolean isThingHandlesVirtualDevice() { + return device.isVirtual(); + } } diff --git a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/FreeAtHomeSystemBaseHandler.java b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/FreeAtHomeSystemBaseHandler.java index f147bd3d9e88a..95a0a372c00b3 100644 --- a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/FreeAtHomeSystemBaseHandler.java +++ b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/handler/FreeAtHomeSystemBaseHandler.java @@ -18,7 +18,6 @@ import org.openhab.core.thing.Thing; import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.types.Command; -import org.openhab.core.types.State; /** * The {@link FreeAtHomeSystemBaseHandler} is the base class because state updates @@ -43,8 +42,4 @@ public void initialize() { public void handleCommand(ChannelUID channelUID, Command command) { // method stub } - - public void handleEventBasedUpdate(ChannelUID channelUID, State state) { - this.updateState(channelUID, state); - } } diff --git a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/util/PidTranslationUtils.java b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/util/PidTranslationUtils.java index 28149262d3c4c..725f8a747337c 100644 --- a/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/util/PidTranslationUtils.java +++ b/bundles/org.openhab.binding.freeathomesystem/src/main/java/org/openhab/binding/freeathomesystem/internal/util/PidTranslationUtils.java @@ -81,7 +81,7 @@ private static PIdContainerClass createFreeAtHomePairingIdTranslation(String p1, "Absolute Set Value", "Absolute control of the set value")); mapDescObj.put("0x0012", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_INTEGER, CATEGORY_UNDEFINED, "", "", "Night", "Toggle between day and night (where day = 0 / night = 1)")); - mapDescObj.put("0x0013", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_ENUM, CATEGORY_UNDEFINED, "", "", + mapDescObj.put("0x0013", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_INTEGER, CATEGORY_UNDEFINED, "", "", "invalid string id", "Resets load failures / short circuits / etc")); mapDescObj.put("0x0015", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_UNKNOWN, CATEGORY_UNDEFINED, "", "", "RGB color", "RGB Color coded in three bytes")); @@ -111,7 +111,7 @@ private static PIdContainerClass createFreeAtHomePairingIdTranslation(String p1, "Rain Alarm", "State of the rain sensor (sent cyclically and on COV)")); mapDescObj.put("0x0028", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_BOOLEAN, CATEGORY_UNDEFINED, "", "", "Force-position blind", "Forces value dependent high priority up or down state")); - mapDescObj.put("0x0029", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_ENUM, CATEGORY_UNDEFINED, "", "", + mapDescObj.put("0x0029", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_INTEGER, CATEGORY_UNDEFINED, "", "", "Window/Door position", "Delivers position for Window/Door (Open / Tilted / Closed)")); mapDescObj.put("0x0030", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_INTEGER, CATEGORY_UNDEFINED, "", "", "Actuating Value Heating", "Determines the through flow volume of the control valve")); @@ -123,7 +123,7 @@ private static PIdContainerClass createFreeAtHomePairingIdTranslation(String p1, "30", "Set Value Temperature", "Defines the displayed set point temperature of the system")); mapDescObj.put("0x0034", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_DECIMAL, CATEGORY_TEMPERATURE, "7", "30", "Relative Set Point Temperature", "Defines the relative set point temperature of the system")); - mapDescObj.put("0x0035", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_ENUM, CATEGORY_UNDEFINED, "", "", + mapDescObj.put("0x0035", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_INTEGER, CATEGORY_UNDEFINED, "", "", "Window/Door", "Open = 1 / closed = 0")); mapDescObj.put("0x0036", createFreeAtHomePairingIdTranslation(PID_VALUETYPE_INTEGER, CATEGORY_TEMPERATURE, "", "", "Status indication", "states: on/off heating/cooling; eco/comfort; frost/not frost"));