Skip to content

Commit

Permalink
[homekit] fix potential null pointer exceptions (openhab#13122)
Browse files Browse the repository at this point in the history
* fix potential null pointer exceptions
* use contains key

Signed-off-by: Eugen Freiter <freiter@gmx.de>
  • Loading branch information
yfre authored and psmedley committed Feb 23, 2023
1 parent a19b32e commit 430c665
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ protected synchronized void modified(Map<String, Object> config) {
try {
HomekitSettings oldSettings = settings;
settings = processConfig(config);
if ((oldSettings == null) || (settings == null))
return;
changeListener.updateSettings(settings);
if (!oldSettings.networkInterface.equals(settings.networkInterface) || oldSettings.port != settings.port
|| oldSettings.useOHmDNS != settings.useOHmDNS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,17 @@ public class HomekitAccessoryFactory {
};

private static List<HomekitCharacteristicType> getRequiredCharacteristics(HomekitTaggedItem taggedItem) {
final List<HomekitCharacteristicType> characteristics = new ArrayList<>();
if (MANDATORY_CHARACTERISTICS.containsKey(taggedItem.getAccessoryType())) {
characteristics.addAll(Arrays.asList(MANDATORY_CHARACTERISTICS.get(taggedItem.getAccessoryType())));
}
if (taggedItem.getAccessoryType() == BATTERY) {
final String isChargeable = taggedItem.getConfiguration(HomekitBatteryImpl.BATTERY_TYPE, "false");
if ("true".equalsIgnoreCase(isChargeable) || "yes".equalsIgnoreCase(isChargeable)) {
final List<HomekitCharacteristicType> characteristics = new ArrayList<>();
characteristics.addAll(Arrays.asList(MANDATORY_CHARACTERISTICS.get(taggedItem.getAccessoryType())));
characteristics.add(BATTERY_CHARGING_STATE);
return characteristics;
}
}
return Arrays.asList(MANDATORY_CHARACTERISTICS.get(taggedItem.getAccessoryType()));
return characteristics;
}

/**
Expand Down

0 comments on commit 430c665

Please sign in to comment.