mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
[netatmo] Solving IAE in CameraCapability (#20254)
* Solving UAE Signed-off-by: gael@lhopital.org <gael@lhopital.org>
This commit is contained in:
+1
-1
@@ -58,7 +58,7 @@ public abstract class Event extends NAObject {
|
|||||||
@Override
|
@Override
|
||||||
public @Nullable String getName() {
|
public @Nullable String getName() {
|
||||||
String localMessage = super.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() {
|
public Optional<EventSubType> getSubTypeDescription() {
|
||||||
|
|||||||
+1
-3
@@ -50,9 +50,7 @@ public class AlarmEventCapability extends HomeSecurityThingCapability {
|
|||||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
|
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
|
||||||
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
|
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
|
||||||
|
|
||||||
final String message = event.getName();
|
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE, toStringType(event.getName()));
|
||||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE,
|
|
||||||
message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+9
-10
@@ -73,8 +73,8 @@ public class CameraCapability extends HomeSecurityThingCapability {
|
|||||||
List<ChannelHelper> channelHelpers) {
|
List<ChannelHelper> channelHelpers) {
|
||||||
super(handler, descriptionProvider, channelHelpers);
|
super(handler, descriptionProvider, channelHelpers);
|
||||||
this.personChannelUID = new ChannelUID(thingUID, GROUP_LAST_EVENT, CHANNEL_EVENT_PERSON_ID);
|
this.personChannelUID = new ChannelUID(thingUID, GROUP_LAST_EVENT, CHANNEL_EVENT_PERSON_ID);
|
||||||
this.cameraHelper = (CameraChannelHelper) channelHelpers.stream().filter(CameraChannelHelper.class::isInstance)
|
this.cameraHelper = channelHelpers.stream().filter(CameraChannelHelper.class::isInstance)
|
||||||
.findFirst().orElseThrow(() -> new IllegalArgumentException(
|
.map(CameraChannelHelper.class::cast).findFirst().orElseThrow(() -> new IllegalArgumentException(
|
||||||
"CameraCapability must find a CameraChannelHelper, please file a bug report."));
|
"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);
|
updatePictureIfUrlPresent(event.getVignetteUrl(), group, CHANNEL_EVENT_VIGNETTE, CHANNEL_EVENT_VIGNETTE_URL);
|
||||||
handler.updateState(group, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
|
handler.updateState(group, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
|
||||||
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
|
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
|
||||||
final String message = event.getName();
|
handler.updateState(group, CHANNEL_EVENT_MESSAGE, toStringType(event.getName()));
|
||||||
handler.updateState(group, CHANNEL_EVENT_MESSAGE,
|
|
||||||
message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
|
|
||||||
State personId = event.getPersons().isEmpty() ? UnDefType.NULL
|
State personId = event.getPersons().isEmpty() ? UnDefType.NULL
|
||||||
: toStringType(event.getPersons().values().iterator().next().getId());
|
: toStringType(event.getPersons().values().iterator().next().getId());
|
||||||
handler.updateState(personChannelUID, personId);
|
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) {
|
String urlChannel) {
|
||||||
if (snapShotUrl != null) {
|
if (url == null || url.isBlank()) {
|
||||||
handler.updateState(group, pictureChannel, toRawType(snapShotUrl));
|
return;
|
||||||
handler.updateState(group, urlChannel, toStringType(snapShotUrl));
|
|
||||||
}
|
}
|
||||||
|
handler.updateState(group, pictureChannel, toRawType(url));
|
||||||
|
handler.updateState(group, urlChannel, toStringType(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,9 +184,9 @@ public class CameraCapability extends HomeSecurityThingCapability {
|
|||||||
|
|
||||||
public @Nullable String ping(String vpnUrl) {
|
public @Nullable String ping(String vpnUrl) {
|
||||||
return getSecurityCapability().map(cap -> {
|
return getSecurityCapability().map(cap -> {
|
||||||
UriBuilder builder = UriBuilder.fromPath(cap.ping(vpnUrl));
|
|
||||||
URI apiLocalUrl = null;
|
URI apiLocalUrl = null;
|
||||||
try {
|
try {
|
||||||
|
UriBuilder builder = UriBuilder.fromPath(cap.ping(vpnUrl));
|
||||||
apiLocalUrl = builder.build();
|
apiLocalUrl = builder.build();
|
||||||
if (apiLocalUrl.getHost().startsWith("169.254.")) {
|
if (apiLocalUrl.getHost().startsWith("169.254.")) {
|
||||||
logger.warn("Suspicious local IP address received: {}", apiLocalUrl);
|
logger.warn("Suspicious local IP address received: {}", apiLocalUrl);
|
||||||
|
|||||||
+1
-4
@@ -83,10 +83,7 @@ public class PersonCapability extends HomeSecurityThingCapability {
|
|||||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
|
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
|
||||||
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
|
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
|
||||||
|
|
||||||
final String message = event.getName();
|
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE, toStringType(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_TIME, toDateTimeType(event.getTime()));
|
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_TIME, toDateTimeType(event.getTime()));
|
||||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SNAPSHOT, toRawType(event.getSnapshotUrl()));
|
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SNAPSHOT, toRawType(event.getSnapshotUrl()));
|
||||||
handler.updateState(cameraChannelUID, toStringType(event.getCameraId()));
|
handler.updateState(cameraChannelUID, toStringType(event.getCameraId()));
|
||||||
|
|||||||
+1
-2
@@ -102,9 +102,8 @@ public class RefreshCapability extends Capability {
|
|||||||
if (Math.abs(ChronoUnit.SECONDS.between(expectedExecution, scheduledExecution)) <= 3) {
|
if (Math.abs(ChronoUnit.SECONDS.between(expectedExecution, scheduledExecution)) <= 3) {
|
||||||
logger.debug("'{}' refresh as already pending roughly as the same time, will not reschedule", thingUID);
|
logger.debug("'{}' refresh as already pending roughly as the same time, will not reschedule", thingUID);
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
stopJob();
|
|
||||||
}
|
}
|
||||||
|
stopJob();
|
||||||
}
|
}
|
||||||
logger.debug("'{}' next refresh in {}", thingUID, delay);
|
logger.debug("'{}' next refresh in {}", thingUID, delay);
|
||||||
handler.schedule(this::proceedWithUpdate, delay).ifPresent(job -> this.refreshJob = job);
|
handler.schedule(this::proceedWithUpdate, delay).ifPresent(job -> this.refreshJob = job);
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ public abstract class ChannelHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (localData instanceof NAObject) {
|
if (localData != null) {
|
||||||
result = internalGetObject(channelId, localData);
|
result = internalGetObject(channelId, localData);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+1
-1
@@ -97,7 +97,7 @@ public class WebhookServlet extends NetatmoServlet {
|
|||||||
processEvent(new String(req.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
|
processEvent(new String(req.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processEvent(String data) throws IOException {
|
private void processEvent(String data) {
|
||||||
if (!data.isEmpty()) {
|
if (!data.isEmpty()) {
|
||||||
logger.debug("Event transmitted from restService: {}", data);
|
logger.debug("Event transmitted from restService: {}", data);
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user