Skip to content

Commit

Permalink
[netatmo] Presence sub events were not updated (openhab#16681)
Browse files Browse the repository at this point in the history
* Making sub event work
Signed-off-by: clinique <gael@lhopital.org>
Signed-off-by: Paul Smedley <paul@smedley.id.au>
  • Loading branch information
clinique authored and psmedley committed Jun 15, 2024
1 parent 2f781c4 commit 47d0853
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public String getCameraId() {
return cameraId;
}

public void setCameraId(String cameraId) {
this.cameraId = cameraId;
}

@Override
public @Nullable String getName() {
String localMessage = super.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class HomeEvent extends Event {
public class NAEventsDataResponse extends ApiResponse<BodyResponse<Home>> {
}

private record Snapshot(String url, ZonedDateTime expiresAt) {
}

private ZonedDateTime time = ZonedDateTime.now();
private @Nullable String personId;
private EventCategory category = EventCategory.UNKNOWN;
Expand Down Expand Up @@ -93,20 +96,18 @@ public Optional<EventSubType> getSubTypeDescription() {

@Override
public @Nullable String getSnapshotUrl() {
Snapshot image = snapshot;
return image != null ? image.getUrl() : null;
return internalGetUrl(snapshot);
}

public @Nullable String getVignetteUrl() {
Snapshot image = vignette;
return image != null ? image.getUrl() : null;
return internalGetUrl(vignette);
}

public List<HomeEvent> getSubevents() {
return subevents;
public List<HomeEvent> getSubEvents() {
return subevents.stream().peek(subevent -> subevent.setCameraId(getCameraId())).toList();
}

public @Nullable Snapshot getVignette() {
return vignette;
private @Nullable String internalGetUrl(@Nullable Snapshot image) {
return image == null ? null : image.url();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public List<NAObject> updateReadings() {
HomeEvent event = cap.getDeviceLastEvent(handler.getId(), moduleType.apiName);
if (event != null) {
result.add(event);
result.addAll(event.getSubevents());
result.addAll(event.getSubEvents());
}
});
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.EventSubType;
import org.openhab.binding.netatmo.internal.api.data.EventType;
import org.openhab.binding.netatmo.internal.api.data.ModuleType;
import org.openhab.binding.netatmo.internal.api.dto.Event;
Expand Down Expand Up @@ -100,7 +101,7 @@ public void updateEvent(Event event) {
}
lastEventTime = eventTime;
handler.triggerChannel(CHANNEL_HOME_EVENT,
event.getSubTypeDescription().map(st -> st.name()).orElse(event.getEventType().name()));
event.getSubTypeDescription().map(EventSubType::name).orElse(event.getEventType().name()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
*/
@NonNullByDefault
public class EventCameraChannelHelper extends EventChannelHelper {
public class EventCameraChannelHelper extends ChannelHelper {

public EventCameraChannelHelper(Set<String> providedGroups) {
super(providedGroups);
Expand All @@ -39,22 +39,16 @@ public EventCameraChannelHelper(Set<String> providedGroups) {
@Override
protected @Nullable State internalGetHomeEvent(String channelId, @Nullable String groupId, HomeEvent event) {
if (groupId != null && groupId.startsWith(GROUP_SUB_EVENT)) {
switch (channelId) {
case CHANNEL_EVENT_TYPE:
return toStringType(event.getEventType());
case CHANNEL_EVENT_TIME:
return new DateTimeType(event.getTime());
case CHANNEL_EVENT_MESSAGE:
return toStringType(event.getName());
case CHANNEL_EVENT_SNAPSHOT:
return toRawType(event.getSnapshotUrl());
case CHANNEL_EVENT_SNAPSHOT_URL:
return toStringType(event.getSnapshotUrl());
case CHANNEL_EVENT_VIGNETTE:
return toRawType(event.getVignetteUrl());
case CHANNEL_EVENT_VIGNETTE_URL:
return toStringType(event.getVignetteUrl());
}
return switch (channelId) {
case CHANNEL_EVENT_TYPE -> toStringType(event.getEventType());
case CHANNEL_EVENT_TIME -> new DateTimeType(event.getTime());
case CHANNEL_EVENT_MESSAGE -> toStringType(event.getName());
case CHANNEL_EVENT_SNAPSHOT -> toRawType(event.getSnapshotUrl());
case CHANNEL_EVENT_SNAPSHOT_URL -> toStringType(event.getSnapshotUrl());
case CHANNEL_EVENT_VIGNETTE -> toRawType(event.getVignetteUrl());
case CHANNEL_EVENT_VIGNETTE_URL -> toStringType(event.getVignetteUrl());
default -> super.internalGetHomeEvent(channelId, groupId, event);
};
}
return super.internalGetHomeEvent(channelId, groupId, event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openhab.binding.netatmo.internal.api.dto.Event;
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
import org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void setNewData(@Nullable NAObject data) {
case CHANNEL_EVENT_CAMERA_ID:
return toStringType(event.getCameraId());
case CHANNEL_EVENT_SUBTYPE:
return event.getSubTypeDescription().map(d -> toStringType(d)).orElse(UnDefType.NULL);
return event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL);
case CHANNEL_EVENT_SNAPSHOT:
return toRawType(event.getSnapshotUrl());
case CHANNEL_EVENT_SNAPSHOT_URL:
Expand Down

0 comments on commit 47d0853

Please sign in to comment.