[zoneminder] Fixed most recent event channels (#9672)

Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
Mark Hilbush 2021-01-03 11:38:15 -05:00 committed by GitHub
parent 9394dc4676
commit 0fdf1e34c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 37 deletions

View File

@ -98,15 +98,15 @@ The following configuration parameters are available on the Monitor thing:
| totalEvents | Number | Total number of events | | totalEvents | Number | Total number of events |
| imageUrl | String | URL for image snapshot | | imageUrl | String | URL for image snapshot |
| videoUrl | String | URL for JPEG video stream | | videoUrl | String | URL for JPEG video stream |
| eventId | String | Event ID | | eventId | String | ID of most recently completed event |
| eventName | String | Event name | | eventName | String | Name of most recently completed event |
| eventCause | String | Event cause | | eventCause | String | Cause of most recently completed event |
| eventNotes | String | Event notes | | eventNotes | String | Notes of most recently completed event |
| eventStart | DateTime | Event start date/time | | eventStart | DateTime | Start date/time of most recently completed event |
| eventEnd | DateTime | Event end date/time | | eventEnd | DateTime | End date/time of most recently completed event |
| eventFrames | Number | Event frames | | eventFrames | Number | Number of frames of most recently completed event |
| eventAlarmFrames | Number | Event alarm frames | | eventAlarmFrames | Number | Number of alarm frames of most recently completed event |
| eventLength | Number:Time | Event length in seconds | | eventLength | Number:Time | Length in seconds of most recently completed event |
## Thing Actions ## Thing Actions
@ -256,18 +256,17 @@ end
``` ```
``` ```
val int NUM_MONITORS = 6 val monitors = newArrayList("1", "3", "4", "6")
var int monitorId = 1 var int index = 0
rule "Rotate Through All Monitor Images Every 10 Seconds" rule "Rotate Through a List of Monitor Images Every 10 Seconds"
when when
Time cron "0/10 * * ? * * *" Time cron "0/10 * * ? * * *"
then then
var String id = String::format("%d", monitorId) ZmServer_ImageMonitorId.sendCommand(monitors.get(index))
ZmServer_ImageMonitorId.sendCommand(id) index = index + 1
monitorId = monitorId + 1 if (index >= monitors.size) {
if (monitorId > NUM_MONITORS) { index = 0
monitorId = 1
} }
end end
``` ```

View File

@ -191,7 +191,7 @@ public class Monitor {
this.videoUrl = videoUrl; this.videoUrl = videoUrl;
} }
public @Nullable Event getLastEvent() { public @Nullable Event getMostRecentCompletedEvent() {
return lastEvent; return lastEvent;
} }

View File

@ -350,8 +350,8 @@ public class ZmBridgeHandler extends BaseBridgeHandler {
parameters.add("sort=StartTime"); parameters.add("sort=StartTime");
parameters.add("direction=desc"); parameters.add("direction=desc");
parameters.add("limit=1"); parameters.add("limit=1");
String response = executeGet( String response = executeGet(buildUrlWithParameters(
buildUrlWithParameters(String.format("/api/events/index/MonitorId:%s.json", id), parameters)); String.format("/api/events/index/MonitorId:%s/Name!=:New%%20Event.json", id), parameters));
EventsDTO events = GSON.fromJson(response, EventsDTO.class); EventsDTO events = GSON.fromJson(response, EventsDTO.class);
if (events != null && events.eventsList != null && events.eventsList.size() == 1) { if (events != null && events.eventsList != null && events.eventsList.size() == 1) {
EventDTO e = events.eventsList.get(0).event; EventDTO e = events.eventsList.get(0).event;

View File

@ -181,7 +181,7 @@ public class ZmMonitorHandler extends BaseThingHandler {
@SuppressWarnings("null") @SuppressWarnings("null")
public void updateStatus(Monitor m) { public void updateStatus(Monitor m) {
logger.debug("Monitor {}: Updating: {}", m.getId(), m.toString()); logger.debug("Monitor {}: Updating Monitor: {}", m.getId(), m);
updateChannelState(CHANNEL_ID, new StringType(m.getId())); updateChannelState(CHANNEL_ID, new StringType(m.getId()));
updateChannelState(CHANNEL_NAME, new StringType(m.getName())); updateChannelState(CHANNEL_NAME, new StringType(m.getName()));
updateChannelState(CHANNEL_FUNCTION, new StringType(m.getFunction())); updateChannelState(CHANNEL_FUNCTION, new StringType(m.getFunction()));
@ -198,25 +198,26 @@ public class ZmMonitorHandler extends BaseThingHandler {
if (!m.isAlarm()) { if (!m.isAlarm()) {
updateChannelState(CHANNEL_TRIGGER_ALARM, m.isAlarm() ? OnOffType.ON : OnOffType.OFF); updateChannelState(CHANNEL_TRIGGER_ALARM, m.isAlarm() ? OnOffType.ON : OnOffType.OFF);
} }
Event event = m.getLastEvent(); Event event = m.getMostRecentCompletedEvent();
if (event == null) { if (event == null) {
// No most recent event, so clear out the event channels
clearEventChannels(); clearEventChannels();
} else if (event.getEnd() != null) { return;
// If end is null, assume event hasn't completed yet
logger.trace("Monitor {}: Id:{}, Frames:{}, AlarmFrames:{}, Length:{}", m.getId(), event.getId(),
event.getFrames(), event.getAlarmFrames(), event.getLength());
updateChannelState(CHANNEL_EVENT_ID, new StringType(event.getId()));
updateChannelState(CHANNEL_EVENT_NAME, new StringType(event.getName()));
updateChannelState(CHANNEL_EVENT_CAUSE, new StringType(event.getCause()));
updateChannelState(CHANNEL_EVENT_NOTES, new StringType(event.getNotes()));
updateChannelState(CHANNEL_EVENT_START, new DateTimeType(
ZonedDateTime.ofInstant(event.getStart().toInstant(), timeZoneProvider.getTimeZone())));
updateChannelState(CHANNEL_EVENT_END, new DateTimeType(
ZonedDateTime.ofInstant(event.getEnd().toInstant(), timeZoneProvider.getTimeZone())));
updateChannelState(CHANNEL_EVENT_FRAMES, new DecimalType(event.getFrames()));
updateChannelState(CHANNEL_EVENT_ALARM_FRAMES, new DecimalType(event.getAlarmFrames()));
updateChannelState(CHANNEL_EVENT_LENGTH, new QuantityType<Time>(event.getLength(), Units.SECOND));
} }
// Update channels for most recent completed event
logger.debug("Monitor {}: Updating Event Id:{}, Name:{}, Frames:{}, AlarmFrames:{}, Length:{}", m.getId(),
event.getId(), event.getName(), event.getFrames(), event.getAlarmFrames(), event.getLength());
updateChannelState(CHANNEL_EVENT_ID, new StringType(event.getId()));
updateChannelState(CHANNEL_EVENT_NAME, new StringType(event.getName()));
updateChannelState(CHANNEL_EVENT_CAUSE, new StringType(event.getCause()));
updateChannelState(CHANNEL_EVENT_NOTES, new StringType(event.getNotes()));
updateChannelState(CHANNEL_EVENT_START, new DateTimeType(
ZonedDateTime.ofInstant(event.getStart().toInstant(), timeZoneProvider.getTimeZone())));
updateChannelState(CHANNEL_EVENT_END,
new DateTimeType(ZonedDateTime.ofInstant(event.getEnd().toInstant(), timeZoneProvider.getTimeZone())));
updateChannelState(CHANNEL_EVENT_FRAMES, new DecimalType(event.getFrames()));
updateChannelState(CHANNEL_EVENT_ALARM_FRAMES, new DecimalType(event.getAlarmFrames()));
updateChannelState(CHANNEL_EVENT_LENGTH, new QuantityType<Time>(event.getLength(), Units.SECOND));
} }
private void clearEventChannels() { private void clearEventChannels() {