2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 05:16:45 +00:00

71_YAMAHA_MC.pm:Define optimiert wie im Wiki beschrieben unter

Beruecksichtigung von $init_done
                Loglevel herbagestuft fuer einige Meldungen



git-svn-id: https://svn.fhem.de/fhem/trunk@21033 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Leugi 2020-01-22 21:40:14 +00:00
parent f2e909a985
commit cfaeb7da10

View File

@ -60,6 +60,7 @@ sub YAMAHA_MC_GetStatus($;$);
sub YAMAHA_MC_ResetTimer($;$); sub YAMAHA_MC_ResetTimer($;$);
sub YAMAHA_MC_Get($@); sub YAMAHA_MC_Get($@);
sub YAMAHA_MC_Define($$); sub YAMAHA_MC_Define($$);
sub YAMAHA_MC_Notify($$);
sub YAMAHA_MC_Attr(@); sub YAMAHA_MC_Attr(@);
sub YAMAHA_MC_Undefine($$); sub YAMAHA_MC_Undefine($$);
sub YAMAHA_MC_UpdateLists($;$); sub YAMAHA_MC_UpdateLists($;$);
@ -287,6 +288,9 @@ sub YAMAHA_MC_Define($$) # only called when defined, not on reload.
$hash->{UdpClientPort} = $data{YAMAHA_MC_UDPCLIENTPORTSTART}; $hash->{UdpClientPort} = $data{YAMAHA_MC_UDPCLIENTPORTSTART};
$data{YAMAHA_MC_UDPCLIENTPORTSTART}++; $data{YAMAHA_MC_UDPCLIENTPORTSTART}++;
$hash->{NOTIFYDEV} = "global";
if ($init_done) {
if ( AttrVal( $name, "eventProcessing", 0 ) ) { if ( AttrVal( $name, "eventProcessing", 0 ) ) {
Log3 $hash->{NAME}, 2, "$hash->{TYPE}: $hash->{NAME} event Processing enabled "; Log3 $hash->{NAME}, 2, "$hash->{TYPE}: $hash->{NAME} event Processing enabled ";
@ -296,6 +300,7 @@ sub YAMAHA_MC_Define($$) # only called when defined, not on reload.
else { else {
Log3 $hash->{NAME}, 2, "$hash->{TYPE}: $hash->{NAME} event Processing disabled "; Log3 $hash->{NAME}, 2, "$hash->{TYPE}: $hash->{NAME} event Processing disabled ";
} }
}
# if an update interval was given which is greater than zero, use it. # if an update interval was given which is greater than zero, use it.
if ( defined( $a[4] ) and $a[4] > 0 ) { if ( defined( $a[4] ) and $a[4] > 0 ) {
@ -321,11 +326,11 @@ sub YAMAHA_MC_Define($$) # only called when defined, not on reload.
if ( defined( $a[6] ) ) { if ( defined( $a[6] ) ) {
unless ( defined( $hash->{helper}{SELECTED_ZONE} ) ) { $hash->{helper}{SELECTED_ZONE} = $a[6]; } unless ( defined( $hash->{helper}{SELECTED_ZONE} ) ) { $hash->{helper}{SELECTED_ZONE} = $a[6]; }
$hash->{ZONE} = $a[6]; $hash->{ZONE} = $a[6];
Log3 $hash->{NAME}, 1, "$hash->{TYPE}: $hash->{NAME} Setting selected zone to " . $a[6]; Log3 $hash->{NAME}, 3, "$hash->{TYPE}: $hash->{NAME} Setting selected zone to " . $a[6];
} }
else { else {
$hash->{ZONE} = "main"; $hash->{ZONE} = "main";
Log3 $hash->{NAME}, 1, "$hash->{TYPE}: $hash->{NAME} no zone defined in device using main "; Log3 $hash->{NAME}, 3, "$hash->{TYPE}: $hash->{NAME} no zone defined in device using main ";
} }
# create empty CMD Queue # create empty CMD Queue
@ -361,6 +366,7 @@ sub YAMAHA_MC_Define($$) # only called when defined, not on reload.
readingsSingleUpdate( $hash, 'state', 'opened', 1 ); readingsSingleUpdate( $hash, 'state', 'opened', 1 );
if ($init_done) {
my $DLNAsearch = AttrVal( $hash->{NAME}, "DLNAsearch", "on" ); my $DLNAsearch = AttrVal( $hash->{NAME}, "DLNAsearch", "on" );
readingsSingleUpdate( $hash, "DLNARenderer", "unknown", 1 ); readingsSingleUpdate( $hash, "DLNARenderer", "unknown", 1 );
@ -384,6 +390,7 @@ sub YAMAHA_MC_Define($$) # only called when defined, not on reload.
YAMAHA_MC_setupMediaRenderer($hash); YAMAHA_MC_setupMediaRenderer($hash);
InternalTimer( gettimeofday() + 150, 'YAMAHA_MC_DiscoverDLNAProcess', $hash, 0 ); InternalTimer( gettimeofday() + 150, 'YAMAHA_MC_DiscoverDLNAProcess', $hash, 0 );
} }
}
Log3 $hash->{NAME}, 1, "$type: $name opened device $name -> host:$hash->{HOST}:" . "$hash->{PORT}" . " $hash->{OFF_INTERVAL}" . " $hash->{ON_INTERVAL}" . " $hash->{ZONE}"; Log3 $hash->{NAME}, 1, "$type: $name opened device $name -> host:$hash->{HOST}:" . "$hash->{PORT}" . " $hash->{OFF_INTERVAL}" . " $hash->{ON_INTERVAL}" . " $hash->{ZONE}";
@ -394,6 +401,62 @@ sub YAMAHA_MC_Define($$) # only called when defined, not on reload.
return undef; return undef;
} }
# ------------------------------------------------------------------------------
# YAMAHA_MC_Notify
# ------------------------------------------------------------------------------
sub YAMAHA_MC_Notify($$)
{
my ($hash, $dev_hash) = @_;
my $ownName = $hash->{NAME}; # own name / hash
return "" if(IsDisabled($ownName)); # Return without any further action if the module is disabled
my $devName = $dev_hash->{NAME}; # Device that created the events
my $events = deviceEvents($dev_hash, 1);
my $name = $hash->{NAME};
if($devName eq "global" && grep(m/^INITIALIZED|REREADCFG$/, @{$events}))
{
#Event PRocessing
if ( AttrVal( $name, "eventProcessing", 0 ) ) {
Log3 $hash->{NAME}, 2, "$hash->{TYPE}: $hash->{NAME} event Processing enabled ";
#open UDP Client for incoming events
YAMAHA_MC_OpenUDPConn($hash);
}
else {
Log3 $hash->{NAME}, 2, "$hash->{TYPE}: $hash->{NAME} event Processing disabled ";
}
# DLNA Search
my $DLNAsearch = AttrVal( $hash->{NAME}, "DLNAsearch", "on" );
readingsSingleUpdate( $hash, "DLNARenderer", "unknown", 1 );
readingsSingleUpdate( $hash, 'MediaServer', 'unknown', 1 );
if ( $DLNAsearch eq "on" ) {
YAMAHA_MC_setupControlpoint($hash);
YAMAHA_MC_setupMediaRenderer($hash);
Log3 $hash->{NAME}, 2, "$hash->{TYPE}: $name DLNAsearch turned $DLNAsearch setting timer for getting devices in 150Secs";
InternalTimer( gettimeofday() + 120, 'YAMAHA_MC_getNetworkStatus', $hash, 0 );
InternalTimer( gettimeofday() + 150, 'YAMAHA_MC_DiscoverDLNAProcess', $hash, 0 );
}
else {
Log3 $name, 1, "$hash->{TYPE}: $name - DLNASearch turned $DLNAsearch";
Log3 $name, 1, "$hash->{TYPE}: $name - starting InternalTimer YAMAHA_MC_DiscoverDLNAProcess anyway once in 150Secs";
YAMAHA_MC_setupControlpoint($hash);
YAMAHA_MC_setupMediaRenderer($hash);
InternalTimer( gettimeofday() + 150, 'YAMAHA_MC_DiscoverDLNAProcess', $hash, 0 );
}
}
}
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# YAMAHA_MC_setupControlpoint # YAMAHA_MC_setupControlpoint
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------