mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[netatmo] Presence sub events were not updated (#16681)
* Making sub event work Signed-off-by: clinique <gael@lhopital.org> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
2218dc528e
commit
705ee263b6
@ -51,6 +51,10 @@ public abstract class Event extends NAObject {
|
||||
return cameraId;
|
||||
}
|
||||
|
||||
public void setCameraId(String cameraId) {
|
||||
this.cameraId = cameraId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getName() {
|
||||
String localMessage = super.getName();
|
||||
|
@ -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;
|
||||
@ -93,20 +96,18 @@ public class HomeEvent extends Event {
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2024 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.binding.netatmo.internal.api.dto;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The {@link Snapshot} holds data related to a snapshot.
|
||||
*
|
||||
* @author Gaël L'hopital - Initial contribution
|
||||
*
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class Snapshot {
|
||||
private @Nullable String url;
|
||||
|
||||
public @Nullable String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
@ -163,7 +163,7 @@ public class CameraCapability extends HomeSecurityThingCapability {
|
||||
HomeEvent event = cap.getDeviceLastEvent(handler.getId(), moduleType.apiName);
|
||||
if (event != null) {
|
||||
result.add(event);
|
||||
result.addAll(event.getSubevents());
|
||||
result.addAll(event.getSubEvents());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
@ -22,6 +22,7 @@ import java.util.stream.Stream;
|
||||
|
||||
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;
|
||||
@ -100,7 +101,7 @@ public class PersonCapability extends HomeSecurityThingCapability {
|
||||
}
|
||||
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
|
||||
|
@ -30,7 +30,7 @@ import org.openhab.core.types.State;
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class EventCameraChannelHelper extends EventChannelHelper {
|
||||
public class EventCameraChannelHelper extends ChannelHelper {
|
||||
|
||||
public EventCameraChannelHelper(Set<String> providedGroups) {
|
||||
super(providedGroups);
|
||||
@ -39,22 +39,16 @@ public class EventCameraChannelHelper extends EventChannelHelper {
|
||||
@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);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.VideoStatu
|
||||
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;
|
||||
@ -78,7 +79,7 @@ public class EventChannelHelper extends ChannelHelper {
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user