mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
fhem.pl: optimizing createNtfyHash (Forum #66402)
git-svn-id: https://svn.fhem.de/fhem/trunk@13334 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
724b3810c8
commit
7065633b55
@ -129,7 +129,7 @@ FHEMWEB_Initialize($)
|
||||
$hash->{AttrFn} = "FW_Attr";
|
||||
$hash->{DefFn} = "FW_Define";
|
||||
$hash->{UndefFn} = "FW_Undef";
|
||||
$hash->{NotifyFn}= ($init_done ? "FW_Notify" : "FW_SecurityCheck");
|
||||
$hash->{NotifyFn}= "FW_Notify";
|
||||
$hash->{AsyncOutputFn} = "FW_AsyncOutput";
|
||||
$hash->{ActivateInformFn} = "FW_ActivateInform";
|
||||
no warnings 'qw';
|
||||
@ -217,16 +217,13 @@ FHEMWEB_Initialize($)
|
||||
FW_readIcons($pe);
|
||||
}
|
||||
}
|
||||
|
||||
InternalTimer(1, "FW_SecurityCheck", $hash);
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FW_SecurityCheck($$)
|
||||
{
|
||||
my ($ntfy, $dev) = @_;
|
||||
return if($dev->{NAME} ne "global" ||
|
||||
!grep(m/^INITIALIZED$/, @{$dev->{CHANGED}}));
|
||||
my $motd = AttrVal("global", "motd", "");
|
||||
if($motd =~ "^SecurityCheck") {
|
||||
my @list1 = devspec2array("TYPE=FHEMWEB");
|
||||
@ -247,8 +244,6 @@ FW_SecurityCheck($$)
|
||||
if(@list3);
|
||||
$attr{global}{motd} = $motd;
|
||||
}
|
||||
$modules{FHEMWEB}{NotifyFn}= "FW_Notify";
|
||||
return;
|
||||
}
|
||||
|
||||
#####################################
|
||||
|
@ -20,7 +20,6 @@ telnet_Initialize($)
|
||||
$hash->{AsyncOutputFn} = "telnet_Output";
|
||||
$hash->{UndefFn} = "telnet_Undef";
|
||||
$hash->{AttrFn} = "telnet_Attr";
|
||||
$hash->{NotifyFn}= "telnet_SecurityCheck";
|
||||
$hash->{AttrList} = "globalpassword password prompt allowedCommands ".
|
||||
"allowfrom SSL connectTimeout connectInterval ".
|
||||
"encoding:utf8,latin1 sslVersion";
|
||||
@ -34,6 +33,7 @@ telnet_Initialize($)
|
||||
$cmds{inform} = { Fn=>"CommandTelnetInform",
|
||||
ClientFilter => "telnet",
|
||||
Hlp=>"{on|off|log|raw|timer|status},echo all events to this client" };
|
||||
InternalTimer(1, "telnet_SecurityCheck", $hash);
|
||||
}
|
||||
|
||||
sub
|
||||
@ -58,11 +58,8 @@ CommandTelnetEncoding($$)
|
||||
|
||||
#####################################
|
||||
sub
|
||||
telnet_SecurityCheck($$)
|
||||
telnet_SecurityCheck()
|
||||
{
|
||||
my ($ntfy, $dev) = @_;
|
||||
return if($dev->{NAME} ne "global" ||
|
||||
!grep(m/^INITIALIZED$/, @{$dev->{CHANGED}}));
|
||||
my $motd = AttrVal("global", "motd", "");
|
||||
if($motd =~ "^SecurityCheck") {
|
||||
my @list1 = devspec2array("TYPE=telnet");
|
||||
@ -85,9 +82,6 @@ telnet_SecurityCheck($$)
|
||||
if(@list3);
|
||||
$attr{global}{motd} = $motd;
|
||||
}
|
||||
delete $modules{telnet}{NotifyFn};
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
##########################
|
||||
|
37
fhem/fhem.pl
37
fhem/fhem.pl
@ -1864,8 +1864,8 @@ CommandModify($$)
|
||||
|
||||
# Return a list of modules
|
||||
return "Define $a[0] first" if(!defined($defs{$a[0]}));
|
||||
%ntfyHash = ();
|
||||
my $hash = $defs{$a[0]};
|
||||
%ntfyHash = () if($hash->{NTFY_ORDER});
|
||||
|
||||
$hash->{OLDDEF} = $hash->{DEF};
|
||||
$hash->{DEF} = $a[1];
|
||||
@ -4499,25 +4499,30 @@ createNtfyHash()
|
||||
grep { $defs{$_}{NTFY_ORDER} &&
|
||||
$defs{$_}{TYPE} &&
|
||||
$modules{$defs{$_}{TYPE}}{NotifyFn} } keys %defs;
|
||||
my %d2a_cache;
|
||||
%ntfyHash = ("*" => []);
|
||||
foreach my $d (@ntfyList) {
|
||||
if($defs{$d}{NOTIFYDEV}) {
|
||||
foreach my $nd (devspec2array($defs{$d}{NOTIFYDEV})) {
|
||||
$ntfyHash{$nd} = [] if($nd && !defined($ntfyHash{$nd}));
|
||||
}
|
||||
}
|
||||
}
|
||||
$ntfyHash{"*"} = [];
|
||||
foreach my $d (@ntfyList) {
|
||||
if($defs{$d}{NOTIFYDEV}) {
|
||||
foreach my $nd (devspec2array($defs{$d}{NOTIFYDEV})) {
|
||||
my $arr = $ntfyHash{$nd};
|
||||
push @{$arr}, $d if(!grep /^$d$/, @{$arr});
|
||||
}
|
||||
my $ndl = $defs{$d}{NOTIFYDEV};
|
||||
next if(!$ndl);
|
||||
my @ndlarr;
|
||||
if($d2a_cache{$ndl}) {
|
||||
@ndlarr = @{$d2a_cache{$ndl}};
|
||||
} else {
|
||||
foreach my $nd (keys %ntfyHash) {
|
||||
push @{$ntfyHash{$nd}}, $d;
|
||||
@ndlarr = devspec2array($ndl);
|
||||
if(@ndlarr > 1) {
|
||||
my %h = map { $_ => 1 } @ndlarr;
|
||||
@ndlarr = keys %h;
|
||||
}
|
||||
$d2a_cache{$ndl} = \@ndlarr;
|
||||
}
|
||||
map { $ntfyHash{$_} = [] } @ndlarr;
|
||||
}
|
||||
|
||||
my @nhk = keys %ntfyHash;
|
||||
foreach my $d (@ntfyList) {
|
||||
my $ndl = $defs{$d}{NOTIFYDEV};
|
||||
my $arr = ($ndl ? $d2a_cache{$ndl} : \@nhk);
|
||||
map { push @{$ntfyHash{$_}}, $d } @{$arr};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user