From 6c815a96a3780da1da441cc2182190e027818c95 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Wed, 19 Oct 2011 01:38:41 +0200 Subject: [PATCH] brmd notify_door_open: Move alert logic from IRC to main session --- brmd/brmd.pl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/brmd/brmd.pl b/brmd/brmd.pl index 296fbde..ec940ce 100755 --- a/brmd/brmd.pl +++ b/brmd/brmd.pl @@ -96,7 +96,15 @@ sub dooropen_update { my ($self, $newdooropen) = @_[OBJECT, ARG0]; $dooropen = $newdooropen; my $st = dooropen_str(); - $poe_kernel->post( $irc, 'notify_door_open', $st ); + + my $closed_timeout = 60; + my $unlock_timeout = 30; + my $alert = ($dooropen == 1 and $status == 0 and time - $lastunlock >= $unlock_timeout); + if ($alert) { + $poe_kernel->post($door, 'play_alarm'); + } + + $poe_kernel->post( $irc, 'notify_door_open', $st, $alert ); } sub notify_door_unlocked { @@ -681,15 +689,10 @@ sub notify_door_unlocked { } sub notify_door_open { - my ($sender, $newstate) = @_[SENDER, ARG0]; + my ($sender, $newstate, $alert) = @_[SENDER, ARG0, ARG1]; my $irc = $_[HEAP]->{irc}; - my $msg; - my $unlock_timeout = 30; - if ($dooropen == 1 and $status == 0 and time - $lastunlock >= $unlock_timeout) { - $msg = "[door] $newstate \002(alert: closed brmlab, door opened, unlocked before more than $unlock_timeout seconds)"; - } else { - $msg = "[door] $newstate"; - } + my $msg = "[door] $newstate"; + $alert and $msg .= " \002(alert: closed brmlab, door opened, not unlocked)"; $irc->yield (privmsg => $channel => $msg ); }