Skip to content

Commit

Permalink
Bugfix - handling invalid channel
Browse files Browse the repository at this point in the history
Bugfix - handling invalid channel
  • Loading branch information
andrasU committed Feb 5, 2023
1 parent 7457a58 commit 409d61f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO

channelFunctionID = channelObject.get("functionID").getAsString();

if (isScene) {
channelFunctionID = channelFunctionID.substring(0, channelFunctionID.length() - 1) + "0";
// check whether this is a valid channel
if (channelFunctionID.isEmpty()) {
// invalid channel found
logger.info("Invalid channel fucntion ID found - Devicelabel: {} Channel: {}", deviceLabel, channelId);

return false;
}

if (!channelFunctionID.isEmpty()) {
Expand All @@ -63,7 +67,12 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO
}
}

if (isScene) {
channelFunctionID = channelFunctionID.substring(0, channelFunctionID.length() - 1) + "0";
}

switch (HexUtils.getIntegerFromHex(channelFunctionID)) {
case FID_PANEL_SWITCH_SENSOR:
case FID_SWITCH_SENSOR: {
this.channelId = channelId;

Expand All @@ -76,6 +85,7 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO

break;
}
case FID_PANEL_DIMMING_SENSOR:
case FID_DIMMING_SENSOR: {
this.channelId = channelId;

Expand Down Expand Up @@ -185,6 +195,8 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO
case FID_WINDOW_DOOR_SENSOR: {
this.channelId = channelId;

logger.info("Window/Door position sensor channel created - Channel FID: {}", channelFunctionID);

FreeAtHomeDatapointGroup newDatapointGroup = new FreeAtHomeDatapointGroup();
newDatapointGroup.addDatapointToGroup(DATAPOINT_DIRECTION_OUTPUT, 53, channelId, channelObject);
datapointGroups.add(newDatapointGroup);
Expand All @@ -193,8 +205,6 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO
newDatapointGroup.addDatapointToGroup(DATAPOINT_DIRECTION_OUTPUT, 41, channelId, channelObject);
datapointGroups.add(newDatapointGroup);

logger.info("Window/Door position sensor channel created - Channel FID: {}", channelFunctionID);

break;
}
case FID_SCENE_TRIGGER: {
Expand Down Expand Up @@ -486,7 +496,7 @@ public boolean createChannelFromJson(String deviceLabel, String channelId, JsonO
default: {
logger.info("Unknown channel found - Channel FID: {}", channelFunctionID);

break;
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ public FreeAtHomeDeviceDescription(JsonObject jsonObject, String id) {
for (String nextChannel : jsonObjectOfChannels.keySet()) {
FreeAtHomeDeviceChannel newChannel = new FreeAtHomeDeviceChannel();

newChannel.createChannelFromJson(deviceLabel, nextChannel, jsonObjectOfChannels, sceneIsDetected,
ruleIsDetected);
if (newChannel.createChannelFromJson(deviceLabel, nextChannel, jsonObjectOfChannels, sceneIsDetected,
ruleIsDetected) == true) {
if (interfaceType == DEVICE_INTERFACE_VIRTUAL_TYPE) {
newChannel.applyChangesForVirtualDevice();
}

if (interfaceType == DEVICE_INTERFACE_VIRTUAL_TYPE) {
newChannel.applyChangesForVirtualDevice();
listOfChannels.add(newChannel);
}

listOfChannels.add(newChannel);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
* @author Andras Uhrin
*
*/
@SuppressWarnings("deprecation")
public @Nullable List<String> getDeviceDeviceList() {
boolean ret = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,55 +549,55 @@ private static PIdContainerClass createFreeAtHomePairingIdTranslation(String p1,
public static String getShortTextForPairingId(String Key) {
PIdContainerClass desc = MAP_TRANSLATOR.get(Key);

return desc.label;
return (desc != null) ? desc.label : "Unknown label";
}

@SuppressWarnings("null")
public static String getDescriptionTextForPairingId(String Key) {
PIdContainerClass desc = MAP_TRANSLATOR.get(Key);

return desc.descprition;
return (desc != null) ? desc.descprition : "Unknown description";
}

@SuppressWarnings("null")
public static String getValueTypeForPairingId(String Key) {
PIdContainerClass desc = MAP_TRANSLATOR.get(Key);

return desc.valueType;
return (desc != null) ? desc.valueType : PID_VALUETYPE_DECIMAL;
}

@SuppressWarnings("null")
public static String getItemTypeForPairingId(String Key) {
PIdContainerClass desc = MAP_TRANSLATOR.get(Key);

return desc.category;
return (desc != null) ? desc.category : CATEGORY_UNDEFINED;
}

@SuppressWarnings("null")
public static String getCategoryForPairingId(String Key) {
PIdContainerClass desc = MAP_TRANSLATOR.get(Key);

return desc.category;
return (desc != null) ? desc.category : CATEGORY_UNDEFINED;
}

@SuppressWarnings("null")
public static String getPatternForPairingId(String Key) {
PIdContainerClass desc = MAP_TRANSLATOR.get(Key);

return desc.category;
return (desc != null) ? desc.category : CATEGORY_UNDEFINED;
}

@SuppressWarnings("null")
public static int getMax(String Key) {
PIdContainerClass desc = MAP_TRANSLATOR.get(Key);

return desc.max;
return (desc != null) ? desc.max : 1;
}

@SuppressWarnings("null")
public static int getMin(String Key) {
PIdContainerClass desc = MAP_TRANSLATOR.get(Key);

return desc.min;
return (desc != null) ? desc.min : 0;
}
}

0 comments on commit 409d61f

Please sign in to comment.