Skip to content

Commit

Permalink
Fix virtual device feedback, fix window sensor
Browse files Browse the repository at this point in the history
Fix virtual device feedback, fix window sensor
  • Loading branch information
andrasU committed Jan 16, 2023
1 parent 365c0c6 commit 9f9f44a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -407,4 +454,8 @@ public void removeChannels() {

mapChannelUID.clear();
}

public boolean isThingHandlesVirtualDevice() {
return device.isVirtual();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));
Expand All @@ -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"));
Expand Down

0 comments on commit 9f9f44a

Please sign in to comment.