mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +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;
|
return cameraId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCameraId(String cameraId) {
|
||||||
|
this.cameraId = cameraId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String getName() {
|
public @Nullable String getName() {
|
||||||
String localMessage = super.getName();
|
String localMessage = super.getName();
|
||||||
|
@ -37,6 +37,9 @@ public class HomeEvent extends Event {
|
|||||||
public class NAEventsDataResponse extends ApiResponse<BodyResponse<Home>> {
|
public class NAEventsDataResponse extends ApiResponse<BodyResponse<Home>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record Snapshot(String url, ZonedDateTime expiresAt) {
|
||||||
|
}
|
||||||
|
|
||||||
private ZonedDateTime time = ZonedDateTime.now();
|
private ZonedDateTime time = ZonedDateTime.now();
|
||||||
private @Nullable String personId;
|
private @Nullable String personId;
|
||||||
private EventCategory category = EventCategory.UNKNOWN;
|
private EventCategory category = EventCategory.UNKNOWN;
|
||||||
@ -93,20 +96,18 @@ public class HomeEvent extends Event {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String getSnapshotUrl() {
|
public @Nullable String getSnapshotUrl() {
|
||||||
Snapshot image = snapshot;
|
return internalGetUrl(snapshot);
|
||||||
return image != null ? image.getUrl() : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable String getVignetteUrl() {
|
public @Nullable String getVignetteUrl() {
|
||||||
Snapshot image = vignette;
|
return internalGetUrl(vignette);
|
||||||
return image != null ? image.getUrl() : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HomeEvent> getSubevents() {
|
public List<HomeEvent> getSubEvents() {
|
||||||
return subevents;
|
return subevents.stream().peek(subevent -> subevent.setCameraId(getCameraId())).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Snapshot getVignette() {
|
private @Nullable String internalGetUrl(@Nullable Snapshot image) {
|
||||||
return vignette;
|
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);
|
HomeEvent event = cap.getDeviceLastEvent(handler.getId(), moduleType.apiName);
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
result.add(event);
|
result.add(event);
|
||||||
result.addAll(event.getSubevents());
|
result.addAll(event.getSubEvents());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
@ -22,6 +22,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
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.EventType;
|
||||||
import org.openhab.binding.netatmo.internal.api.data.ModuleType;
|
import org.openhab.binding.netatmo.internal.api.data.ModuleType;
|
||||||
import org.openhab.binding.netatmo.internal.api.dto.Event;
|
import org.openhab.binding.netatmo.internal.api.dto.Event;
|
||||||
@ -100,7 +101,7 @@ public class PersonCapability extends HomeSecurityThingCapability {
|
|||||||
}
|
}
|
||||||
lastEventTime = eventTime;
|
lastEventTime = eventTime;
|
||||||
handler.triggerChannel(CHANNEL_HOME_EVENT,
|
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
|
@Override
|
||||||
|
@ -30,7 +30,7 @@ import org.openhab.core.types.State;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class EventCameraChannelHelper extends EventChannelHelper {
|
public class EventCameraChannelHelper extends ChannelHelper {
|
||||||
|
|
||||||
public EventCameraChannelHelper(Set<String> providedGroups) {
|
public EventCameraChannelHelper(Set<String> providedGroups) {
|
||||||
super(providedGroups);
|
super(providedGroups);
|
||||||
@ -39,22 +39,16 @@ public class EventCameraChannelHelper extends EventChannelHelper {
|
|||||||
@Override
|
@Override
|
||||||
protected @Nullable State internalGetHomeEvent(String channelId, @Nullable String groupId, HomeEvent event) {
|
protected @Nullable State internalGetHomeEvent(String channelId, @Nullable String groupId, HomeEvent event) {
|
||||||
if (groupId != null && groupId.startsWith(GROUP_SUB_EVENT)) {
|
if (groupId != null && groupId.startsWith(GROUP_SUB_EVENT)) {
|
||||||
switch (channelId) {
|
return switch (channelId) {
|
||||||
case CHANNEL_EVENT_TYPE:
|
case CHANNEL_EVENT_TYPE -> toStringType(event.getEventType());
|
||||||
return toStringType(event.getEventType());
|
case CHANNEL_EVENT_TIME -> new DateTimeType(event.getTime());
|
||||||
case CHANNEL_EVENT_TIME:
|
case CHANNEL_EVENT_MESSAGE -> toStringType(event.getName());
|
||||||
return new DateTimeType(event.getTime());
|
case CHANNEL_EVENT_SNAPSHOT -> toRawType(event.getSnapshotUrl());
|
||||||
case CHANNEL_EVENT_MESSAGE:
|
case CHANNEL_EVENT_SNAPSHOT_URL -> toStringType(event.getSnapshotUrl());
|
||||||
return toStringType(event.getName());
|
case CHANNEL_EVENT_VIGNETTE -> toRawType(event.getVignetteUrl());
|
||||||
case CHANNEL_EVENT_SNAPSHOT:
|
case CHANNEL_EVENT_VIGNETTE_URL -> toStringType(event.getVignetteUrl());
|
||||||
return toRawType(event.getSnapshotUrl());
|
default -> super.internalGetHomeEvent(channelId, groupId, event);
|
||||||
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 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.Event;
|
||||||
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
|
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
|
||||||
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
|
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.library.types.DateTimeType;
|
||||||
import org.openhab.core.types.State;
|
import org.openhab.core.types.State;
|
||||||
import org.openhab.core.types.UnDefType;
|
import org.openhab.core.types.UnDefType;
|
||||||
@ -78,7 +79,7 @@ public class EventChannelHelper extends ChannelHelper {
|
|||||||
case CHANNEL_EVENT_CAMERA_ID:
|
case CHANNEL_EVENT_CAMERA_ID:
|
||||||
return toStringType(event.getCameraId());
|
return toStringType(event.getCameraId());
|
||||||
case CHANNEL_EVENT_SUBTYPE:
|
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:
|
case CHANNEL_EVENT_SNAPSHOT:
|
||||||
return toRawType(event.getSnapshotUrl());
|
return toRawType(event.getSnapshotUrl());
|
||||||
case CHANNEL_EVENT_SNAPSHOT_URL:
|
case CHANNEL_EVENT_SNAPSHOT_URL:
|
||||||
|
Loading…
Reference in New Issue
Block a user