Skip to content

Commit

Permalink
[surepetcare] Check for null before updating pet location channels (o…
Browse files Browse the repository at this point in the history
…penhab#11235)

fixes openhab#11234

Signed-off-by: Maarten Blokker <maarten.blokker@outlook.com>
  • Loading branch information
maarten-blokker authored Sep 19, 2021
1 parent 89ef3b7 commit 68dfd81
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ protected void updateThing() {
if (loc.since != null) {
updateState(PET_CHANNEL_LOCATION_CHANGED, new DateTimeType(loc.since));
}

if (loc.deviceId != null) {
SurePetcareDevice device = petcareAPI.getDevice(loc.deviceId.toString());
if (device != null) {
updateState(PET_CHANNEL_LOCATION_CHANGED_THROUGH, new StringType(device.name));
}
} else if (loc.userId != null) {
SurePetcareHousehold household = petcareAPI.getHousehold(pet.householdId.toString());
if (household != null) {
Long userId = loc.userId;
household.users.stream().map(user -> user.user).filter(user -> userId.equals(user.userId))
.forEach(user -> updateState(PET_CHANNEL_LOCATION_CHANGED_THROUGH,
new StringType(user.userName)));
}
}
}
updateState(PET_CHANNEL_DATE_OF_BIRTH, pet.dateOfBirth == null ? UnDefType.UNDEF
: new DateTimeType(pet.dateOfBirth.atStartOfDay(ZoneId.systemDefault())));
Expand All @@ -175,20 +190,6 @@ protected void updateThing() {
updateState(PET_CHANNEL_TAG_IDENTIFIER, new StringType(tag.tag));
}
}
if (pet.status.activity.deviceId != null) {
SurePetcareDevice device = petcareAPI.getDevice(pet.status.activity.deviceId.toString());
if (device != null) {
updateState(PET_CHANNEL_LOCATION_CHANGED_THROUGH, new StringType(device.name));
}
} else if (pet.status.activity.userId != null) {
SurePetcareHousehold household = petcareAPI.getHousehold(pet.householdId.toString());
if (household != null) {
Long userId = pet.status.activity.userId;
household.users.stream().map(user -> user.user).filter(user -> userId.equals(user.userId))
.forEach(user -> updateState(PET_CHANNEL_LOCATION_CHANGED_THROUGH,
new StringType(user.userName)));
}
}
SurePetcarePetFeeding feeding = pet.status.feeding;
if (feeding != null) {
SurePetcareDevice device = petcareAPI.getDevice(feeding.deviceId.toString());
Expand Down

0 comments on commit 68dfd81

Please sign in to comment.