mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
74_UnifiVideo.pm: added disable attribute
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@15966 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
40f350d195
commit
aa96c7d21c
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
@ -31,7 +30,7 @@ UnifiVideo_Initialize($)
|
|||||||
$hash->{SetFn} = "UnifiVideo_Set";
|
$hash->{SetFn} = "UnifiVideo_Set";
|
||||||
$hash->{GetFn} = "UnifiVideo_Get";
|
$hash->{GetFn} = "UnifiVideo_Get";
|
||||||
$hash->{AttrFn} = "UnifiVideo_Attr";
|
$hash->{AttrFn} = "UnifiVideo_Attr";
|
||||||
$hash->{AttrList} = "filePath apiKey ".
|
$hash->{AttrList} = "disable filePath apiKey ".
|
||||||
"sshUser ".
|
"sshUser ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
|
|
||||||
@ -69,6 +68,8 @@ UnifiVideo_Define($$)
|
|||||||
|
|
||||||
if( $init_done ) {
|
if( $init_done ) {
|
||||||
UnifiVideo_Connect($hash);
|
UnifiVideo_Connect($hash);
|
||||||
|
} else {
|
||||||
|
readingsSingleUpdate($hash, 'state', 'initialized', 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -92,6 +93,7 @@ UnifiVideo_Undefine($$)
|
|||||||
{
|
{
|
||||||
my ($hash, $arg) = @_;
|
my ($hash, $arg) = @_;
|
||||||
|
|
||||||
|
UnifiVideo_killLogWatcher($hash);
|
||||||
RemoveInternalTimer($hash, "UnifiVideo_Connect");
|
RemoveInternalTimer($hash, "UnifiVideo_Connect");
|
||||||
|
|
||||||
delete $modules{$hash->{TYPE}}{defptr};
|
delete $modules{$hash->{TYPE}}{defptr};
|
||||||
@ -302,7 +304,8 @@ UnifiVideo_parseHttpAnswer($$$)
|
|||||||
|
|
||||||
my $totalCount = $json->{meta}{totalCount};
|
my $totalCount = $json->{meta}{totalCount};
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdate($hash, 'totalCount', $totalCount, 1);
|
readingsBulkUpdate($hash, 'state', $hash->{PID}?'watching':'running', 1 );
|
||||||
|
readingsBulkUpdateIfChanged($hash, 'totalCount', $totalCount, 1);
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
foreach my $entry (@{$json->{data}}) {
|
foreach my $entry (@{$json->{data}}) {
|
||||||
if( !$entry->{deleted} ) {
|
if( !$entry->{deleted} ) {
|
||||||
@ -317,7 +320,7 @@ UnifiVideo_parseHttpAnswer($$$)
|
|||||||
readingsEndUpdate($hash,1);
|
readingsEndUpdate($hash,1);
|
||||||
|
|
||||||
RemoveInternalTimer($hash, "UnifiVideo_Connect");
|
RemoveInternalTimer($hash, "UnifiVideo_Connect");
|
||||||
InternalTimer(gettimeofday() + 900, "UnifiVideo_Connect", $hash)
|
InternalTimer(gettimeofday() + 900, "UnifiVideo_Connect", $hash);
|
||||||
|
|
||||||
} elsif( $param->{key} eq 'snapshot' ) {
|
} elsif( $param->{key} eq 'snapshot' ) {
|
||||||
my $modpath = $attr{global}{modpath};
|
my $modpath = $attr{global}{modpath};
|
||||||
@ -425,20 +428,30 @@ UnifiVideo_killLogWatcher($)
|
|||||||
{
|
{
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
Log 1, "!!!!!!!";
|
||||||
|
|
||||||
|
Log 1, "2";
|
||||||
|
kill( 9, $hash->{PID} ) if( $hash->{PID} );
|
||||||
|
|
||||||
|
Log 1, "1";
|
||||||
close($hash->{FH}) if($hash->{FH});
|
close($hash->{FH}) if($hash->{FH});
|
||||||
|
Log 1, "1.1";
|
||||||
delete($hash->{FH});
|
delete($hash->{FH});
|
||||||
|
Log 1, "1.2";
|
||||||
delete($hash->{FD});
|
delete($hash->{FD});
|
||||||
|
Log 1, "1.3";
|
||||||
|
|
||||||
return if( !$hash->{PID} );
|
return if( !$hash->{PID} );
|
||||||
|
|
||||||
kill( 9, $hash->{PID} );
|
|
||||||
delete $hash->{PID};
|
delete $hash->{PID};
|
||||||
|
|
||||||
|
Log 1, "3";
|
||||||
|
|
||||||
|
readingsSingleUpdate($hash, 'state', 'running', 1 );
|
||||||
Log3 $name, 3, "$name: stopped logfile watcher";
|
Log3 $name, 3, "$name: stopped logfile watcher";
|
||||||
|
|
||||||
delete $hash->{PARTIAL};
|
delete $hash->{PARTIAL};
|
||||||
delete($selectlist{$name});
|
delete($selectlist{$name});
|
||||||
|
Log 1, "4";
|
||||||
}
|
}
|
||||||
sub
|
sub
|
||||||
UnifiVideo_startLogWatcher($)
|
UnifiVideo_startLogWatcher($)
|
||||||
@ -467,6 +480,8 @@ UnifiVideo_startLogWatcher($)
|
|||||||
|
|
||||||
$selectlist{$name} = $hash;
|
$selectlist{$name} = $hash;
|
||||||
|
|
||||||
|
readingsSingleUpdate($hash, 'state', 'watching', 1 );
|
||||||
|
|
||||||
Log3 $name, 3, "$name: started logfile watcher";
|
Log3 $name, 3, "$name: started logfile watcher";
|
||||||
} else {
|
} else {
|
||||||
Log3 $name, 2, "$name: failed to start logfile watcher";
|
Log3 $name, 2, "$name: failed to start logfile watcher";
|
||||||
@ -481,6 +496,8 @@ UnifiVideo_Connect($)
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
return if( IsDisabled($name) );
|
||||||
|
|
||||||
my $apiKey = AttrVal($name, 'apiKey', undef);
|
my $apiKey = AttrVal($name, 'apiKey', undef);
|
||||||
if( !$apiKey ) {
|
if( !$apiKey ) {
|
||||||
$hash->{STATE} = 'disconnected';
|
$hash->{STATE} = 'disconnected';
|
||||||
@ -505,7 +522,7 @@ UnifiVideo_Connect($)
|
|||||||
$param->{callback} = \&UnifiVideo_parseHttpAnswer;
|
$param->{callback} = \&UnifiVideo_parseHttpAnswer;
|
||||||
HttpUtils_NonblockingGet( $param );
|
HttpUtils_NonblockingGet( $param );
|
||||||
|
|
||||||
UnifiVideo_startLogWatcher( $hash );
|
UnifiVideo_startLogWatcher( $hash ) if( !$hash->{PID} );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -553,12 +570,24 @@ UnifiVideo_Attr($$$)
|
|||||||
my $orig = $attrVal;
|
my $orig = $attrVal;
|
||||||
|
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
if( $attrName eq "disable" ) {
|
if( $attrName eq 'disable' ) {
|
||||||
} elsif( $attrName eq "sshUser" ) {
|
if( $cmd eq "set" && $attrVal ) {
|
||||||
|
UnifiVideo_killLogWatcher($hash);
|
||||||
|
readingsSingleUpdate($hash, 'state', 'disabled', 1 );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
readingsSingleUpdate($hash, 'state', 'running', 1 );
|
||||||
|
$attr{$name}{$attrName} = 0;
|
||||||
|
UnifiVideo_Connect($hash);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} elsif( $attrName eq 'sshUser' ) {
|
||||||
if( $cmd eq "set" && $attrVal ) {
|
if( $cmd eq "set" && $attrVal ) {
|
||||||
$attr{$name}{$attrName} = $attrVal;
|
$attr{$name}{$attrName} = $attrVal;
|
||||||
} else {
|
} else {
|
||||||
delete $attr{$name}{$attrName};
|
delete $attr{$name}{$attrName};
|
||||||
|
UnifiVideo_killLogWatcher($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnifiVideo_Connect($hash);
|
UnifiVideo_Connect($hash);
|
||||||
@ -566,10 +595,7 @@ UnifiVideo_Attr($$$)
|
|||||||
} elsif( $attrName eq 'apiKey' ) {
|
} elsif( $attrName eq 'apiKey' ) {
|
||||||
if( $cmd eq "set" && $attrVal ) {
|
if( $cmd eq "set" && $attrVal ) {
|
||||||
|
|
||||||
if( $attrVal =~ m/^crypt:/ ) {
|
return if( $attrVal =~ m/^crypt:/ );
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$attrVal = UnifiVideo_encrypt($attrVal);
|
$attrVal = UnifiVideo_encrypt($attrVal);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user