[netatmo] Solving IAE in CameraCapability (#20254)

* Solving UAE

Signed-off-by: gael@lhopital.org <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital
2026-02-26 07:30:07 +01:00
committed by GitHub
parent 1b6731f6bd
commit 21a8aefeee
7 changed files with 15 additions and 22 deletions
@@ -58,7 +58,7 @@ public abstract class Event extends NAObject {
@Override
public @Nullable String getName() {
String localMessage = super.getName();
return localMessage != null ? localMessage.replace("<b>", "").replace("</b>", "") : "";
return localMessage != null ? localMessage.replace("<b>", "").replace("</b>", "") : null;
}
public Optional<EventSubType> getSubTypeDescription() {
@@ -50,9 +50,7 @@ public class AlarmEventCapability extends HomeSecurityThingCapability {
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
final String message = event.getName();
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE,
message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE, toStringType(event.getName()));
}
@Override
@@ -73,8 +73,8 @@ public class CameraCapability extends HomeSecurityThingCapability {
List<ChannelHelper> channelHelpers) {
super(handler, descriptionProvider, channelHelpers);
this.personChannelUID = new ChannelUID(thingUID, GROUP_LAST_EVENT, CHANNEL_EVENT_PERSON_ID);
this.cameraHelper = (CameraChannelHelper) channelHelpers.stream().filter(CameraChannelHelper.class::isInstance)
.findFirst().orElseThrow(() -> new IllegalArgumentException(
this.cameraHelper = channelHelpers.stream().filter(CameraChannelHelper.class::isInstance)
.map(CameraChannelHelper.class::cast).findFirst().orElseThrow(() -> new IllegalArgumentException(
"CameraCapability must find a CameraChannelHelper, please file a bug report."));
}
@@ -132,20 +132,19 @@ public class CameraCapability extends HomeSecurityThingCapability {
updatePictureIfUrlPresent(event.getVignetteUrl(), group, CHANNEL_EVENT_VIGNETTE, CHANNEL_EVENT_VIGNETTE_URL);
handler.updateState(group, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
final String message = event.getName();
handler.updateState(group, CHANNEL_EVENT_MESSAGE,
message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
handler.updateState(group, CHANNEL_EVENT_MESSAGE, toStringType(event.getName()));
State personId = event.getPersons().isEmpty() ? UnDefType.NULL
: toStringType(event.getPersons().values().iterator().next().getId());
handler.updateState(personChannelUID, personId);
}
private void updatePictureIfUrlPresent(@Nullable String snapShotUrl, String group, String pictureChannel,
private void updatePictureIfUrlPresent(@Nullable String url, String group, String pictureChannel,
String urlChannel) {
if (snapShotUrl != null) {
handler.updateState(group, pictureChannel, toRawType(snapShotUrl));
handler.updateState(group, urlChannel, toStringType(snapShotUrl));
if (url == null || url.isBlank()) {
return;
}
handler.updateState(group, pictureChannel, toRawType(url));
handler.updateState(group, urlChannel, toStringType(url));
}
@Override
@@ -185,9 +184,9 @@ public class CameraCapability extends HomeSecurityThingCapability {
public @Nullable String ping(String vpnUrl) {
return getSecurityCapability().map(cap -> {
UriBuilder builder = UriBuilder.fromPath(cap.ping(vpnUrl));
URI apiLocalUrl = null;
try {
UriBuilder builder = UriBuilder.fromPath(cap.ping(vpnUrl));
apiLocalUrl = builder.build();
if (apiLocalUrl.getHost().startsWith("169.254.")) {
logger.warn("Suspicious local IP address received: {}", apiLocalUrl);
@@ -83,10 +83,7 @@ public class PersonCapability extends HomeSecurityThingCapability {
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
final String message = event.getName();
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE,
message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE, toStringType(event.getName()));
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_TIME, toDateTimeType(event.getTime()));
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SNAPSHOT, toRawType(event.getSnapshotUrl()));
handler.updateState(cameraChannelUID, toStringType(event.getCameraId()));
@@ -102,9 +102,8 @@ public class RefreshCapability extends Capability {
if (Math.abs(ChronoUnit.SECONDS.between(expectedExecution, scheduledExecution)) <= 3) {
logger.debug("'{}' refresh as already pending roughly as the same time, will not reschedule", thingUID);
return;
} else {
stopJob();
}
stopJob();
}
logger.debug("'{}' next refresh in {}", thingUID, delay);
handler.schedule(this::proceedWithUpdate, delay).ifPresent(job -> this.refreshJob = job);
@@ -73,7 +73,7 @@ public abstract class ChannelHelper {
}
}
}
if (localData instanceof NAObject) {
if (localData != null) {
result = internalGetObject(channelId, localData);
if (result != null) {
return result;
@@ -97,7 +97,7 @@ public class WebhookServlet extends NetatmoServlet {
processEvent(new String(req.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
}
private void processEvent(String data) throws IOException {
private void processEvent(String data) {
if (!data.isEmpty()) {
logger.debug("Event transmitted from restService: {}", data);
try {