Fixed null pointer exeption
This commit is contained in:
parent
41dfcd0e4f
commit
b30248d973
2 changed files with 11 additions and 4 deletions
|
|
@ -200,11 +200,15 @@ public class SmartHomeImpl extends SmartHomeApp implements TokenRegistrationList
|
|||
DeviceTrait[] traits = DeviceTraitFactory.getTraits(device);
|
||||
Map<String, Object> deviceState = new HashMap<>();
|
||||
|
||||
for (DeviceTrait trait : traits) {
|
||||
deviceState.putAll(trait.generateQueryResponse(device.getDeviceData()));
|
||||
}
|
||||
if (traits != null) {
|
||||
for (DeviceTrait trait : traits) {
|
||||
deviceState.putAll(trait.generateQueryResponse(device.getDeviceData()));
|
||||
}
|
||||
|
||||
deviceState.put("status", "SUCCESS");
|
||||
deviceState.put("status", "SUCCESS");
|
||||
} else {
|
||||
deviceState.put("status", "UNKNOWN");
|
||||
}
|
||||
deviceStates.put(deviceRequest.getId(), deviceState);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Query request failed for sensor: " + deviceRequest.getId(), e);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ public class DeviceTraitFactory {
|
|||
|
||||
|
||||
public static DeviceTrait[] getTraits(HalAbstractDevice device) {
|
||||
if (device == null || device.getDeviceData() == null)
|
||||
return null;
|
||||
|
||||
switch (device.getDeviceData().getClass().getName()) {
|
||||
case "se.hal.struct.devicedata.DimmerEventData":
|
||||
case "se.hal.struct.devicedata.OnOffEventData":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue