mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
Avoiding reads of Energy data for Security channels (#16543)
Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
+10
-1
@@ -18,6 +18,7 @@ import java.util.Optional;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.netatmo.internal.api.ApiResponse;
|
||||
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
|
||||
import org.openhab.binding.netatmo.internal.deserialization.NAObjectMap;
|
||||
|
||||
/**
|
||||
@@ -31,7 +32,7 @@ public class NAHomeStatus {
|
||||
public class NAHomeStatusResponse extends ApiResponse<NAHomeStatus> {
|
||||
}
|
||||
|
||||
public class HomeStatus extends NAThing {
|
||||
public class HomeStatus extends NAObject {
|
||||
private @Nullable NAObjectMap<HomeStatusModule> modules;
|
||||
private @Nullable NAObjectMap<Room> rooms;
|
||||
private @Nullable NAObjectMap<HomeStatusPerson> persons;
|
||||
@@ -50,6 +51,14 @@ public class NAHomeStatus {
|
||||
NAObjectMap<HomeStatusPerson> local = persons;
|
||||
return local != null ? local : new NAObjectMap<>();
|
||||
}
|
||||
|
||||
public boolean appliesTo(FeatureArea area) {
|
||||
return switch (area) {
|
||||
case ENERGY -> (rooms != null || modules != null);
|
||||
case SECURITY -> persons != null;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable HomeStatus home;
|
||||
|
||||
+6
-4
@@ -17,9 +17,11 @@ import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toRawT
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeData;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeDataPerson;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusPerson;
|
||||
@@ -51,12 +53,12 @@ public class SecurityChannelHelper extends ChannelHelper {
|
||||
super.setNewData(data);
|
||||
if (data instanceof HomeData.Security securityData) {
|
||||
knownIds = securityData.getKnownPersons().stream().map(HomeDataPerson::getId).toList();
|
||||
} else if (data instanceof HomeStatus securityStatus) {
|
||||
List<HomeStatusPerson> present = securityStatus.getPersons().values().stream()
|
||||
.filter(HomeStatusPerson::atHome).toList();
|
||||
} else if (data instanceof HomeStatus status && status.appliesTo(FeatureArea.SECURITY)) {
|
||||
List<String> present = status.getPersons().values().stream().filter(HomeStatusPerson::atHome)
|
||||
.map(HomeStatusPerson::getId).toList();
|
||||
|
||||
persons = present.size();
|
||||
unknowns = present.stream().filter(person -> !knownIds.contains(person.getId())).count();
|
||||
unknowns = present.stream().filter(Predicate.not(knownIds::contains)).count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user