mirror of
https://github.com/brmlab/brmdoor.git
synced 2025-06-09 12:14:02 +02:00
brmd notify_door_open: Move alert logic from IRC to main session
This commit is contained in:
parent
f8503ab86f
commit
6c815a96a3
1 changed files with 12 additions and 9 deletions
21
brmd/brmd.pl
21
brmd/brmd.pl
|
@ -96,7 +96,15 @@ sub dooropen_update {
|
||||||
my ($self, $newdooropen) = @_[OBJECT, ARG0];
|
my ($self, $newdooropen) = @_[OBJECT, ARG0];
|
||||||
$dooropen = $newdooropen;
|
$dooropen = $newdooropen;
|
||||||
my $st = dooropen_str();
|
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 {
|
sub notify_door_unlocked {
|
||||||
|
@ -681,15 +689,10 @@ sub notify_door_unlocked {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub notify_door_open {
|
sub notify_door_open {
|
||||||
my ($sender, $newstate) = @_[SENDER, ARG0];
|
my ($sender, $newstate, $alert) = @_[SENDER, ARG0, ARG1];
|
||||||
my $irc = $_[HEAP]->{irc};
|
my $irc = $_[HEAP]->{irc};
|
||||||
my $msg;
|
my $msg = "[door] $newstate";
|
||||||
my $unlock_timeout = 30;
|
$alert and $msg .= " \002(alert: closed brmlab, door opened, not unlocked)";
|
||||||
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";
|
|
||||||
}
|
|
||||||
$irc->yield (privmsg => $channel => $msg );
|
$irc->yield (privmsg => $channel => $msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue