2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

70_ZoneMinder: improved contents of state (thx Florian_GT)

git-svn-id: https://svn.fhem.de/fhem/trunk@20186 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
delmar 2019-09-18 02:16:07 +00:00
parent d5324df9a2
commit 9a1104130b
2 changed files with 35 additions and 9 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- change: 70_ZoneMinder: improved contents of state (thx Florian_GT)
- change: 95_Dashboard: attr dashboard_activetab is now working as designed,
commandref revised, internal code review
- change: 73_AutoShuttersControl: change timelimit for restart initial

View File

@ -96,11 +96,34 @@ sub ZoneMinder_Define {
DevIo_CloseDev($hash) if (DevIo_IsOpen($hash));
DevIo_OpenDev($hash, 0, undef);
my $triggerPortState = $hash->{STATE};
ZoneMinder_updateState( $hash, $triggerPortState, 'n/a' );
ZoneMinder_afterInitialized($hash);
return undef;
}
sub ZoneMinder_updateState {
my ( $hash, $triggerPortState, $apiState ) = @_;
if ( defined( $triggerPortState ) ) {
$hash->{helper}{ZM_TRIGGER_STATE} = $triggerPortState;
} else {
$triggerPortState = $hash->{helper}{ZM_TRIGGER_STATE};
}
if ( defined( $apiState ) ) {
$hash->{helper}{ZM_API_STATE} = $apiState;
} else {
$apiState = $hash->{helper}{ZM_API_STATE};
}
readingsSingleUpdate( $hash, 'state', "Trigger-Port: $triggerPortState, API: $apiState", 0 );
return undef;
}
sub ZoneMinder_afterInitialized {
my ($hash) = @_;
@ -188,12 +211,17 @@ sub ZoneMinder_API_Login_Callback {
$hash->{APILoginStatus} = $param->{code};
Log3 $name, 3, "ZoneMinder ($name) - login status: $hash->{APILoginStatus}";
my $apiState = undef;
if($err ne "") {
Log3 $name, 0, "error while requesting ".$param->{url}." - $err";
$hash->{APILoginError} = $err;
$apiState = 'error';
} elsif($data ne "") {
if ($data =~ m/Invalid username or password/) {
$hash->{APILoginError} = "Invalid username or password.";
$apiState = 'login failed';
} else {
delete($defs{$name}{APILoginError});
@ -206,9 +234,12 @@ sub ZoneMinder_API_Login_Callback {
ZoneMinder_SimpleGet($hash, "$zmApiUrl/host/getVersion.json", \&ZoneMinder_API_ReadHostInfo_Callback);
ZoneMinder_SimpleGet($hash, "$zmApiUrl/configs.json", \&ZoneMinder_API_ReadConfig_Callback);
ZoneMinder_API_getLoad($hash);
$apiState = 'opened';
}
}
}
ZoneMinder_updateState( $hash, undef, $apiState );
RemoveInternalTimer($hash, "ZoneMinder_API_Login");
my $interval = AttrVal($name, 'loginInterval', 3600);
@ -716,16 +747,10 @@ sub ZoneMinder_Ready {
my ( $hash ) = @_;
my $name = $hash->{NAME};
if ( $hash->{STATE} eq "disconnected" ) {
return DevIo_OpenDev($hash, 1, undef ); #if success, $err is undef
}
ZoneMinder_updateState( $hash, 'disappeared', undef );
return DevIo_OpenDev($hash, 1, undef ); #if success, $err is undef
# This is relevant for Windows/USB only
if(defined($hash->{USBDev})) {
my $po = $hash->{USBDev};
my ( $BlockingFlags, $InBytes, $OutBytes, $ErrorFlags ) = $po->status;
return ( $InBytes > 0 );
}
}
1;