Skip to content

Commit

Permalink
[netatmo] Correction of Last-Event group (#16684)
Browse files Browse the repository at this point in the history
* Correction of Last-Event group

Signed-off-by: root <[email protected]>
Signed-off-by: Gaël L'hopital <[email protected]>
  • Loading branch information
clinique authored Apr 29, 2024
1 parent 5f7282b commit 57025ce
Showing 1 changed file with 30 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
*/
@NonNullByDefault
public class EventChannelHelper extends ChannelHelper {
private boolean isLocal;
private @Nullable String vpnUrl, localUrl;
private @Nullable String vpnUrl;
private @Nullable String localUrl;
protected ModuleType moduleType = ModuleType.UNKNOWN;

public EventChannelHelper(Set<String> providedGroups) {
Expand All @@ -49,61 +49,53 @@ public void setModuleType(ModuleType moduleType) {
this.moduleType = moduleType;
}

public void setUrls(String vpnUrl, @Nullable String localUrl) {
public void setUrls(@Nullable String vpnUrl, @Nullable String localUrl) {
this.localUrl = localUrl;
this.vpnUrl = vpnUrl;
this.isLocal = localUrl != null;
}

@Override
public void setNewData(@Nullable NAObject data) {
if (data instanceof Event event) {
if (!event.getEventType().validFor(moduleType)) {
return;
}
if (data instanceof Event event && !event.getEventType().validFor(moduleType)) {
return;
}
super.setNewData(data);
}

@Override
protected @Nullable State internalGetEvent(String channelId, Event event) {
switch (channelId) {
case CHANNEL_EVENT_TYPE:
return toStringType(event.getEventType());
case CHANNEL_EVENT_MESSAGE:
return toStringType(event.getName());
case CHANNEL_EVENT_TIME:
return new DateTimeType(event.getTime());
case CHANNEL_EVENT_PERSON_ID:
return toStringType(event.getPersonId());
case CHANNEL_EVENT_CAMERA_ID:
return toStringType(event.getCameraId());
case CHANNEL_EVENT_SUBTYPE:
return event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL);
case CHANNEL_EVENT_SNAPSHOT:
return toRawType(event.getSnapshotUrl());
case CHANNEL_EVENT_SNAPSHOT_URL:
return toStringType(event.getSnapshotUrl());
}
return null;
return switch (channelId) {
case CHANNEL_EVENT_TYPE -> toStringType(event.getEventType());
case CHANNEL_EVENT_MESSAGE -> toStringType(event.getName());
case CHANNEL_EVENT_TIME -> new DateTimeType(event.getTime());
case CHANNEL_EVENT_PERSON_ID -> toStringType(event.getPersonId());
case CHANNEL_EVENT_CAMERA_ID -> toStringType(event.getCameraId());
case CHANNEL_EVENT_SUBTYPE ->
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL);
case CHANNEL_EVENT_SNAPSHOT -> toRawType(event.getSnapshotUrl());
case CHANNEL_EVENT_SNAPSHOT_URL -> toStringType(event.getSnapshotUrl());
default -> null;
};
}

@Override
protected @Nullable State internalGetHomeEvent(String channelId, @Nullable String groupId, HomeEvent event) {
switch (channelId) {
case CHANNEL_EVENT_VIDEO_STATUS:
return event.getVideoId() != null ? toStringType(event.getVideoStatus()) : UnDefType.NULL;
case CHANNEL_EVENT_VIDEO_LOCAL_URL:
return getStreamURL(true, event.getVideoId(), event.getVideoStatus());
case CHANNEL_EVENT_VIDEO_VPN_URL:
return getStreamURL(false, event.getVideoId(), event.getVideoStatus());
}
return null;
return switch (channelId) {
case CHANNEL_EVENT_VIDEO_STATUS ->
event.getVideoId() != null ? toStringType(event.getVideoStatus()) : UnDefType.NULL;
case CHANNEL_EVENT_VIDEO_LOCAL_URL -> getStreamURL(true, event.getVideoId(), event.getVideoStatus());
case CHANNEL_EVENT_VIDEO_VPN_URL -> getStreamURL(false, event.getVideoId(), event.getVideoStatus());
default -> null;
};
}

private @Nullable String getUrl(boolean local) {
return local ? localUrl : vpnUrl;
}

private State getStreamURL(boolean local, @Nullable String videoId, VideoStatus videoStatus) {
String url = local ? localUrl : vpnUrl;
if ((local && !isLocal) || url == null || videoId == null || videoStatus != VideoStatus.AVAILABLE) {
String url = getUrl(local);
if (url == null || videoId == null || videoStatus != VideoStatus.AVAILABLE) {
return UnDefType.NULL;
}
return toStringType("%s/vod/%s/index.m3u8", url, videoId);
Expand Down

0 comments on commit 57025ce

Please sign in to comment.