mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-17 05:16:02 +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->{AttrFn} = "FW_Attr";
|
||||||
$hash->{DefFn} = "FW_Define";
|
$hash->{DefFn} = "FW_Define";
|
||||||
$hash->{UndefFn} = "FW_Undef";
|
$hash->{UndefFn} = "FW_Undef";
|
||||||
$hash->{NotifyFn}= ($init_done ? "FW_Notify" : "FW_SecurityCheck");
|
$hash->{NotifyFn}= "FW_Notify";
|
||||||
$hash->{AsyncOutputFn} = "FW_AsyncOutput";
|
$hash->{AsyncOutputFn} = "FW_AsyncOutput";
|
||||||
$hash->{ActivateInformFn} = "FW_ActivateInform";
|
$hash->{ActivateInformFn} = "FW_ActivateInform";
|
||||||
no warnings 'qw';
|
no warnings 'qw';
|
||||||
@ -217,16 +217,13 @@ FHEMWEB_Initialize($)
|
|||||||
FW_readIcons($pe);
|
FW_readIcons($pe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
InternalTimer(1, "FW_SecurityCheck", $hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
sub
|
sub
|
||||||
FW_SecurityCheck($$)
|
FW_SecurityCheck($$)
|
||||||
{
|
{
|
||||||
my ($ntfy, $dev) = @_;
|
|
||||||
return if($dev->{NAME} ne "global" ||
|
|
||||||
!grep(m/^INITIALIZED$/, @{$dev->{CHANGED}}));
|
|
||||||
my $motd = AttrVal("global", "motd", "");
|
my $motd = AttrVal("global", "motd", "");
|
||||||
if($motd =~ "^SecurityCheck") {
|
if($motd =~ "^SecurityCheck") {
|
||||||
my @list1 = devspec2array("TYPE=FHEMWEB");
|
my @list1 = devspec2array("TYPE=FHEMWEB");
|
||||||
@ -247,8 +244,6 @@ FW_SecurityCheck($$)
|
|||||||
if(@list3);
|
if(@list3);
|
||||||
$attr{global}{motd} = $motd;
|
$attr{global}{motd} = $motd;
|
||||||
}
|
}
|
||||||
$modules{FHEMWEB}{NotifyFn}= "FW_Notify";
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
|
@ -20,7 +20,6 @@ telnet_Initialize($)
|
|||||||
$hash->{AsyncOutputFn} = "telnet_Output";
|
$hash->{AsyncOutputFn} = "telnet_Output";
|
||||||
$hash->{UndefFn} = "telnet_Undef";
|
$hash->{UndefFn} = "telnet_Undef";
|
||||||
$hash->{AttrFn} = "telnet_Attr";
|
$hash->{AttrFn} = "telnet_Attr";
|
||||||
$hash->{NotifyFn}= "telnet_SecurityCheck";
|
|
||||||
$hash->{AttrList} = "globalpassword password prompt allowedCommands ".
|
$hash->{AttrList} = "globalpassword password prompt allowedCommands ".
|
||||||
"allowfrom SSL connectTimeout connectInterval ".
|
"allowfrom SSL connectTimeout connectInterval ".
|
||||||
"encoding:utf8,latin1 sslVersion";
|
"encoding:utf8,latin1 sslVersion";
|
||||||
@ -34,6 +33,7 @@ telnet_Initialize($)
|
|||||||
$cmds{inform} = { Fn=>"CommandTelnetInform",
|
$cmds{inform} = { Fn=>"CommandTelnetInform",
|
||||||
ClientFilter => "telnet",
|
ClientFilter => "telnet",
|
||||||
Hlp=>"{on|off|log|raw|timer|status},echo all events to this client" };
|
Hlp=>"{on|off|log|raw|timer|status},echo all events to this client" };
|
||||||
|
InternalTimer(1, "telnet_SecurityCheck", $hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@ -58,11 +58,8 @@ CommandTelnetEncoding($$)
|
|||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
sub
|
sub
|
||||||
telnet_SecurityCheck($$)
|
telnet_SecurityCheck()
|
||||||
{
|
{
|
||||||
my ($ntfy, $dev) = @_;
|
|
||||||
return if($dev->{NAME} ne "global" ||
|
|
||||||
!grep(m/^INITIALIZED$/, @{$dev->{CHANGED}}));
|
|
||||||
my $motd = AttrVal("global", "motd", "");
|
my $motd = AttrVal("global", "motd", "");
|
||||||
if($motd =~ "^SecurityCheck") {
|
if($motd =~ "^SecurityCheck") {
|
||||||
my @list1 = devspec2array("TYPE=telnet");
|
my @list1 = devspec2array("TYPE=telnet");
|
||||||
@ -85,9 +82,6 @@ telnet_SecurityCheck($$)
|
|||||||
if(@list3);
|
if(@list3);
|
||||||
$attr{global}{motd} = $motd;
|
$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 a list of modules
|
||||||
return "Define $a[0] first" if(!defined($defs{$a[0]}));
|
return "Define $a[0] first" if(!defined($defs{$a[0]}));
|
||||||
%ntfyHash = ();
|
|
||||||
my $hash = $defs{$a[0]};
|
my $hash = $defs{$a[0]};
|
||||||
|
%ntfyHash = () if($hash->{NTFY_ORDER});
|
||||||
|
|
||||||
$hash->{OLDDEF} = $hash->{DEF};
|
$hash->{OLDDEF} = $hash->{DEF};
|
||||||
$hash->{DEF} = $a[1];
|
$hash->{DEF} = $a[1];
|
||||||
@ -4499,25 +4499,30 @@ createNtfyHash()
|
|||||||
grep { $defs{$_}{NTFY_ORDER} &&
|
grep { $defs{$_}{NTFY_ORDER} &&
|
||||||
$defs{$_}{TYPE} &&
|
$defs{$_}{TYPE} &&
|
||||||
$modules{$defs{$_}{TYPE}}{NotifyFn} } keys %defs;
|
$modules{$defs{$_}{TYPE}}{NotifyFn} } keys %defs;
|
||||||
|
my %d2a_cache;
|
||||||
|
%ntfyHash = ("*" => []);
|
||||||
foreach my $d (@ntfyList) {
|
foreach my $d (@ntfyList) {
|
||||||
if($defs{$d}{NOTIFYDEV}) {
|
my $ndl = $defs{$d}{NOTIFYDEV};
|
||||||
foreach my $nd (devspec2array($defs{$d}{NOTIFYDEV})) {
|
next if(!$ndl);
|
||||||
$ntfyHash{$nd} = [] if($nd && !defined($ntfyHash{$nd}));
|
my @ndlarr;
|
||||||
}
|
if($d2a_cache{$ndl}) {
|
||||||
}
|
@ndlarr = @{$d2a_cache{$ndl}};
|
||||||
}
|
|
||||||
$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});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
foreach my $nd (keys %ntfyHash) {
|
@ndlarr = devspec2array($ndl);
|
||||||
push @{$ntfyHash{$nd}}, $d;
|
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…
x
Reference in New Issue
Block a user