|
36 | 36 | public class CameraChannelHelper extends ChannelHelper {
|
37 | 37 | private static final String QUALITY_CONF_ENTRY = "quality";
|
38 | 38 | private static final String LIVE_PICTURE = "/live/snapshot_720.jpg";
|
39 |
| - private boolean isLocal; |
| 39 | + |
40 | 40 | private @Nullable String vpnUrl;
|
41 | 41 | private @Nullable String localUrl;
|
42 | 42 |
|
43 | 43 | public CameraChannelHelper(Set<String> providedGroups) {
|
44 | 44 | super(providedGroups);
|
45 | 45 | }
|
46 | 46 |
|
47 |
| - public void setUrls(String vpnUrl, @Nullable String localUrl) { |
| 47 | + public void setUrls(@Nullable String vpnUrl, @Nullable String localUrl) { |
48 | 48 | this.localUrl = localUrl;
|
49 | 49 | this.vpnUrl = vpnUrl;
|
50 |
| - this.isLocal = localUrl != null; |
51 |
| - } |
52 |
| - |
53 |
| - public @Nullable String getLocalURL() { |
54 |
| - return localUrl; |
55 | 50 | }
|
56 | 51 |
|
57 | 52 | @Override
|
58 | 53 | protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
|
59 | 54 | if (naThing instanceof HomeStatusModule camera) {
|
60 |
| - boolean isMonitoring = OnOffType.ON.equals(camera.getMonitoring()); |
61 |
| - switch (channelId) { |
62 |
| - case CHANNEL_MONITORING: |
63 |
| - return camera.getMonitoring(); |
64 |
| - case CHANNEL_SD_CARD: |
65 |
| - return toStringType(camera.getSdStatus()); |
66 |
| - case CHANNEL_ALIM_STATUS: |
67 |
| - return toStringType(camera.getAlimStatus()); |
68 |
| - case CHANNEL_LIVEPICTURE_VPN_URL: |
69 |
| - return toStringType(getLivePictureURL(false, isMonitoring)); |
70 |
| - case CHANNEL_LIVEPICTURE_LOCAL_URL: |
71 |
| - return toStringType(getLivePictureURL(true, isMonitoring)); |
72 |
| - case CHANNEL_LIVEPICTURE: |
73 |
| - return toRawType(getLivePictureURL(isLocal, isMonitoring)); |
74 |
| - case CHANNEL_LIVESTREAM_VPN_URL: |
75 |
| - return getLiveStreamURL(false, (String) config.get(QUALITY_CONF_ENTRY), isMonitoring); |
76 |
| - case CHANNEL_LIVESTREAM_LOCAL_URL: |
77 |
| - return getLiveStreamURL(true, (String) config.get(QUALITY_CONF_ENTRY), isMonitoring); |
78 |
| - } |
| 55 | + return switch (channelId) { |
| 56 | + case CHANNEL_MONITORING -> camera.getMonitoring(); |
| 57 | + case CHANNEL_SD_CARD -> toStringType(camera.getSdStatus()); |
| 58 | + case CHANNEL_ALIM_STATUS -> toStringType(camera.getAlimStatus()); |
| 59 | + default -> liveChannels(channelId, (String) config.get(QUALITY_CONF_ENTRY), camera, |
| 60 | + OnOffType.ON.equals(camera.getMonitoring()), localUrl != null); |
| 61 | + }; |
79 | 62 | }
|
80 | 63 | return null;
|
81 | 64 | }
|
82 | 65 |
|
83 |
| - private @Nullable String getLivePictureURL(boolean local, boolean isMonitoring) { |
84 |
| - String url = local ? localUrl : vpnUrl; |
85 |
| - if (!isMonitoring || (local && !isLocal) || url == null) { |
| 66 | + public @Nullable String getLivePictureURL(boolean local, boolean isMonitoring) { |
| 67 | + String url = getUrl(local); |
| 68 | + if (!isMonitoring || url == null) { |
86 | 69 | return null;
|
87 | 70 | }
|
88 | 71 | return "%s%s".formatted(url, LIVE_PICTURE);
|
89 | 72 | }
|
90 | 73 |
|
| 74 | + private @Nullable State liveChannels(String channelId, String qualityConf, HomeStatusModule camera, |
| 75 | + boolean isMonitoring, boolean isLocal) { |
| 76 | + if (vpnUrl == null) { |
| 77 | + setUrls(camera.getVpnUrl(), localUrl); |
| 78 | + } |
| 79 | + return switch (channelId) { |
| 80 | + case CHANNEL_LIVESTREAM_LOCAL_URL -> |
| 81 | + isLocal ? getLiveStreamURL(true, qualityConf, isMonitoring) : UnDefType.NULL; |
| 82 | + case CHANNEL_LIVEPICTURE_LOCAL_URL -> |
| 83 | + isLocal ? toStringType(getLivePictureURL(true, isMonitoring)) : UnDefType.NULL; |
| 84 | + case CHANNEL_LIVESTREAM_VPN_URL -> getLiveStreamURL(false, qualityConf, isMonitoring); |
| 85 | + case CHANNEL_LIVEPICTURE_VPN_URL -> toStringType(getLivePictureURL(false, isMonitoring)); |
| 86 | + case CHANNEL_LIVEPICTURE -> { |
| 87 | + State result = toRawType(getLivePictureURL(isLocal, isMonitoring)); |
| 88 | + if (UnDefType.NULL.equals(result) && isLocal) {// If local read is unsuccessfull, try the VPN version |
| 89 | + result = toRawType(getLivePictureURL(false, isMonitoring)); |
| 90 | + } |
| 91 | + yield result; |
| 92 | + } |
| 93 | + default -> null; |
| 94 | + }; |
| 95 | + } |
| 96 | + |
| 97 | + private @Nullable String getUrl(boolean local) { |
| 98 | + return local ? localUrl : vpnUrl; |
| 99 | + } |
| 100 | + |
91 | 101 | private State getLiveStreamURL(boolean local, @Nullable String configQual, boolean isMonitoring) {
|
92 |
| - String url = local ? localUrl : vpnUrl; |
93 |
| - if (!isMonitoring || (local && !isLocal) || url == null) { |
| 102 | + String url = getUrl(local); |
| 103 | + if (!isMonitoring || url == null) { |
94 | 104 | return UnDefType.NULL;
|
95 | 105 | }
|
96 | 106 | String finalQual = configQual != null ? configQual : "poor";
|
97 |
| - return toStringType("%s/live/%s", url, local ? "files/%s/index.m3u8".formatted(finalQual) : "index.m3u8"); |
| 107 | + return toStringType("%s/live/%sindex.m3u8", url, local ? "files/%s/".formatted(finalQual) : ""); |
98 | 108 | }
|
99 | 109 | }
|
0 commit comments