2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 19:04:20 +00:00

added volumeLimit attribute and bugfixes

git-svn-id: https://svn.fhem.de/fhem/trunk@6303 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
fhemrocks 2014-07-23 06:22:52 +00:00
parent f29ed626bc
commit 0e0e00db81

View File

@ -56,6 +56,8 @@ use Encode qw(decode encode);
# include this for the self-calling timer we use later on # include this for the self-calling timer we use later on
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use constant { true => 1, false => 0 };
# the list of favorites # the list of favorites
my %SB_PLAYER_Favs; my %SB_PLAYER_Favs;
@ -87,14 +89,15 @@ sub SB_PLAYER_Initialize( $ ) {
# the attributes we have. Space separated list of attribute values in # the attributes we have. Space separated list of attribute values in
# the form name:default1,default2 # the form name:default1,default2
$hash->{AttrList} = "volumeStep ttslanguage:de,en,fr "; $hash->{AttrList} = "volumeStep volumeLimit ";
$hash->{AttrList} .= "ttslink "; $hash->{AttrList} .= "ttslanguage:de,en,fr ttslink ";
$hash->{AttrList} .= "donotnotify:true,false "; $hash->{AttrList} .= "donotnotify:true,false ";
$hash->{AttrList} .= "idismac:true,false "; $hash->{AttrList} .= "idismac:true,false ";
$hash->{AttrList} .= "serverautoon:true,false "; $hash->{AttrList} .= "serverautoon:true,false ";
$hash->{AttrList} .= "fadeinsecs "; $hash->{AttrList} .= "fadeinsecs ";
$hash->{AttrList} .= "amplifier:on,play "; $hash->{AttrList} .= "amplifier:on,play ";
$hash->{AttrList} .= "coverartsize:50,100,200 "; $hash->{AttrList} .= "coverartheight:50,100,200 ";
$hash->{AttrList} .= "coverartwidth:50,100,200 ";
$hash->{AttrList} .= $readingFnAttributes; $hash->{AttrList} .= $readingFnAttributes;
} }
@ -114,12 +117,13 @@ sub SB_PLAYER_Define( $$ ) {
if( ( @a < 3 ) || ( @a > 5 ) ) { if( ( @a < 3 ) || ( @a > 5 ) ) {
Log3( $hash, 1, "SB_PLAYER_Define: falsche Anzahl an Argumenten" ); Log3( $hash, 1, "SB_PLAYER_Define: falsche Anzahl an Argumenten" );
return( "wrong syntax: define <name> SB_PLAYER <playerid> " . return( "wrong syntax: define <name> SB_PLAYER <playerid> " .
"<ampl:FHEM_NAME> <coverart:FHEMNAME>" ); "<ampl:FHEM_NAME> <coverart:FHEMNAME>" );
} }
# remove the name and our type # remove the name and our type
my $name = shift( @a ); # my $name = shift( @a );
shift( @a ); shift( @a ); # name
shift( @a ); # type
# needed for manual creation of the Player; autocreate checks in ParseFn # needed for manual creation of the Player; autocreate checks in ParseFn
if( SB_PLAYER_IsValidMAC( $a[ 0] ) == 1 ) { if( SB_PLAYER_IsValidMAC( $a[ 0] ) == 1 ) {
@ -215,6 +219,11 @@ sub SB_PLAYER_Define( $$ ) {
$attr{$name}{volumeStep} = 10; $attr{$name}{volumeStep} = 10;
} }
# Upper limit for volume setting
if( !defined( $attr{$name}{volumeLimit} ) ) {
$attr{$name}{volumeLimit} = 100;
}
# how many secs for fade in when going from stop to play # how many secs for fade in when going from stop to play
if( !defined( $attr{$name}{fadeinsecs} ) ) { if( !defined( $attr{$name}{fadeinsecs} ) ) {
$attr{$name}{fadeinsecs} = 10; $attr{$name}{fadeinsecs} = 10;
@ -464,53 +473,47 @@ sub SB_PLAYER_Parse( $$ ) {
if( $cmd eq "mixer" ) { if( $cmd eq "mixer" ) {
if( $args[ 0 ] eq "volume" ) { if( $args[ 0 ] eq "volume" ) {
# update the volume # update the volume
if ($args[ 1 ] eq "?") { if ($args[ 1 ] eq "?") {
# it is a request # it is a request
} elsif( scalar( $args[ 1 ] ) > 0 ) {
readingsSingleUpdate( $hash, "volume",
scalar( $args[ 1 ] ), 0 );
} else { } else {
readingsSingleUpdate( $hash, "volume", SB_SERVER_UpdateVolumeReadings( $hash, $args[ 1 ], true );
"muted", 0 );
} }
readingsSingleUpdate( $hash, "volumeStraight",
scalar( $args[ 1 ] ), 0 );
} }
} elsif( $cmd eq "remote" ) { } elsif( $cmd eq "remote" ) {
$hash->{ISREMOTESTREAM} = "$args[ 0 ]"; $hash->{ISREMOTESTREAM} = "$args[ 0 ]";
} elsif( $cmd eq "play" ) { } elsif( $cmd eq "play" ) {
readingsSingleUpdate( $hash, "playStatus", "playing", 1 ); readingsBulkUpdate( $hash, "playStatus", "playing" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} elsif( $cmd eq "stop" ) { } elsif( $cmd eq "stop" ) {
readingsSingleUpdate( $hash, "playStatus", "stopped", 1 ); readingsBulkUpdate( $hash, "playStatus", "stopped" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} elsif( $cmd eq "pause" ) { } elsif( $cmd eq "pause" ) {
if( $args[ 0 ] eq "0" ) { if( $args[ 0 ] eq "0" ) {
readingsSingleUpdate( $hash, "playStatus", "playing", 1 ); readingsBulkUpdate( $hash, "playStatus", "playing" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} else { } else {
readingsSingleUpdate( $hash, "playStatus", "paused", 1 ); readingsBulkUpdate( $hash, "playStatus", "paused" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} }
} elsif( $cmd eq "mode" ) { } elsif( $cmd eq "mode" ) {
#Log3( $hash, 1, "Playmode: $args[ 0 ]" ); #Log3( $hash, 1, "Playmode: $args[ 0 ]" );
# alittle more complex to fulfill FHEM Development guidelines # alittle more complex to fulfill FHEM Development guidelines
if( $args[ 0 ] eq "play" ) { if( $args[ 0 ] eq "play" ) {
readingsSingleUpdate( $hash, "playStatus", "playing", 1 ); readingsBulkUpdate( $hash, "playStatus", "playing" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} elsif( $args[ 0 ] eq "stop" ) { } elsif( $args[ 0 ] eq "stop" ) {
readingsSingleUpdate( $hash, "playStatus", "stopped", 1 ); readingsBulkUpdate( $hash, "playStatus", "stopped" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} elsif( $args[ 0 ] eq "pause" ) { } elsif( $args[ 0 ] eq "pause" ) {
readingsSingleUpdate( $hash, "playStatus", "paused", 1 ); readingsBulkUpdate( $hash, "playStatus", "paused" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} else { } else {
readingsSingleUpdate( $hash, "playStatus", $args[ 0 ], 1 ); readingsBulkUpdate( $hash, "playStatus", $args[ 0 ] );
} }
} elsif( $cmd eq "newmetadata" ) { } elsif( $cmd eq "newmetadata" ) {
@ -546,15 +549,15 @@ sub SB_PLAYER_Parse( $$ ) {
# } # }
if ($hash->{READINGS}{talkStatus}{VAL} eq "requested") { if ($hash->{READINGS}{talkStatus}{VAL} eq "requested") {
# should be my talk # should be my talk
Log3( $hash, 1, "SB_PLAYER: talkstatus = " . Log3( $hash, 5, "SB_PLAYER: talkstatus = " .
$hash->{READINGS}{talkStatus}{VAL} ); $hash->{READINGS}{talkStatus}{VAL} );
readingsSingleUpdate( $hash, "talkStatus", "playing", 1 ); readingsBulkUpdate( $hash, "talkStatus", "playing" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} elsif ($hash->{READINGS}{talkStatus}{VAL} eq "requested " . } elsif ($hash->{READINGS}{talkStatus}{VAL} eq "requested " .
"recall pending" ) { "recall pending" ) {
Log3( $hash, 1, "SB_PLAYER: talkstatus = " . Log3( $hash, 5, "SB_PLAYER: talkstatus = " .
$hash->{READINGS}{talkStatus}{VAL} ); $hash->{READINGS}{talkStatus}{VAL} );
readingsSingleUpdate( $hash, "talkStatus", "playing " . readingsBulkUpdate( $hash, "talkStatus", "playing " .
"recall pending", 1 ); "recall pending", 1 );
} }
} elsif( $args[ 0 ] eq "repeat" ) { } elsif( $args[ 0 ] eq "repeat" ) {
@ -590,46 +593,46 @@ sub SB_PLAYER_Parse( $$ ) {
if( $hash->{READINGS}{talkStatus}{VAL} eq "playing recall pending" ) { if( $hash->{READINGS}{talkStatus}{VAL} eq "playing recall pending" ) {
# I was waiting for the end of the talk and a playlist stopped # I was waiting for the end of the talk and a playlist stopped
# need to recall saved playlist and saved status # need to recall saved playlist and saved status
Log3( $hash, 1, "SB_PLAYER: stop talking - talkStatus was " . Log3( $hash, 5, "SB_PLAYER: stop talking - talkStatus was " .
"$hash->{READINGS}{talkStatus}{VAL}" ); "$hash->{READINGS}{talkStatus}{VAL}" );
readingsSingleUpdate( $hash, "talkStatus", "stopped", 1 ); readingsBulkUpdate( $hash, "talkStatus", "stopped" );
# recall # recall
if( $hash->{READINGS}{savedState}{VAL} eq "off" ) { if( $hash->{READINGS}{savedState}{VAL} eq "off" ) {
# I need to call the playlist and shut off the SB # I need to call the playlist and shut off the SB
IOWrite( $hash, "$hash->{PLAYERMAC} playlist resume " . IOWrite( $hash, "$hash->{PLAYERMAC} playlist resume " .
"fhem_$hash->{NAME} noplay:1\n" ); "fhem_$hash->{NAME} noplay:1\n" );
IOWrite( $hash, "$hash->{PLAYERMAC} power 0\n" ); IOWrite( $hash, "$hash->{PLAYERMAC} power 0\n" );
readingsSingleUpdate( $hash, "power", "off", 1 ); readingsBulkUpdate( $hash, "power", "off" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
Log3( $hash, 1, "SB_PLAYER: recall : off" ); Log3( $hash, 5, "SB_PLAYER: recall : off" );
} elsif( $hash->{READINGS}{savedPlayStatus}{VAL} eq "stopped" ) { } elsif( $hash->{READINGS}{savedPlayStatus}{VAL} eq "stopped" ) {
# Need to recall playlist + stop # Need to recall playlist + stop
IOWrite( $hash, "$hash->{PLAYERMAC} playlist resume " . IOWrite( $hash, "$hash->{PLAYERMAC} playlist resume " .
"fhem_$hash->{NAME} noplay:1\n" ); "fhem_$hash->{NAME} noplay:1\n" );
IOWrite( $hash, "$hash->{PLAYERMAC} stop\n" ); IOWrite( $hash, "$hash->{PLAYERMAC} stop\n" );
Log3( $hash, 1, "SB_PLAYER: recall : stop" ); Log3( $hash, 5, "SB_PLAYER: recall : stop" );
} elsif( $hash->{READINGS}{savedPlayStatus}{VAL} eq "paused" ) { } elsif( $hash->{READINGS}{savedPlayStatus}{VAL} eq "paused" ) {
# Need to recall playlist + pause # Need to recall playlist + pause
IOWrite( $hash, "$hash->{PLAYERMAC} playlist resume " . IOWrite( $hash, "$hash->{PLAYERMAC} playlist resume " .
"fhem_$hash->{NAME} noplay:1\n" ); "fhem_$hash->{NAME} noplay:1\n" );
IOWrite( $hash, "$hash->{PLAYERMAC} pause 1\n" ); IOWrite( $hash, "$hash->{PLAYERMAC} pause 1\n" );
Log3( $hash, 1, "SB_PLAYER: recall : pause 1" ); Log3( $hash, 5, "SB_PLAYER: recall : pause 1" );
} else { } else {
# Need to recall and play playlist # Need to recall and play playlist
IOWrite( $hash, "$hash->{PLAYERMAC} playlist resume " . IOWrite( $hash, "$hash->{PLAYERMAC} playlist resume " .
"fhem_$hash->{NAME}\n" ); "fhem_$hash->{NAME}\n" );
Log3( $hash, 1, "SB_PLAYER: recall now - talkStatus=" . Log3( $hash, 5, "SB_PLAYER: recall now - talkStatus=" .
"$hash->{READINGS}{talkStatus}{VAL}" ); "$hash->{READINGS}{talkStatus}{VAL}" );
} }
} elsif( $hash->{READINGS}{talkStatus}{VAL} eq "playing" ) { } elsif( $hash->{READINGS}{talkStatus}{VAL} eq "playing" ) {
# I was waiting for the end of the talk and a playlist stopped # I was waiting for the end of the talk and a playlist stopped
# keep all like this # keep all like this
Log3( $hash, 1, "SB_PLAYER: stop talking - talkStatus was " . Log3( $hash, 5, "SB_PLAYER: stop talking - talkStatus was " .
"$hash->{READINGS}{talkStatus}{VAL}" ); "$hash->{READINGS}{talkStatus}{VAL}" );
readingsSingleUpdate( $hash, "talkStatus", "stopped", 1 ); readingsBulkUpdate( $hash, "talkStatus", "stopped" );
} else { } else {
# Should be an ordinary playlist stop # Should be an ordinary playlist stop
Log3( $hash, 1, "SB_PLAYER: no recall pending - talkstatus " . Log3( $hash, 5, "SB_PLAYER: no recall pending - talkstatus " .
"= $hash->{READINGS}{talkStatus}{VAL}" ); "= $hash->{READINGS}{talkStatus}{VAL}" );
} }
@ -674,24 +677,24 @@ sub SB_PLAYER_Parse( $$ ) {
} elsif( $cmd eq "power" ) { } elsif( $cmd eq "power" ) {
if (!(@args)) { if (!(@args)) {
# power toggle : should only happen when called with SB CLI # power toggle : should only happen when called with SB CLI
if (ReadingsVal($hash->{NAME}, "state", "off") eq "on") { if (ReadingsVal($hash->{NAME}, "state", "off") eq "on") {
readingsSingleUpdate( $hash, "presence", "absent", 0 ); readingsBulkUpdate( $hash, "presence", "absent" );
readingsSingleUpdate( $hash, "state", "off", 1 ); readingsBulkUpdate( $hash, "state", "off" );
readingsSingleUpdate( $hash, "power", "off", 1 ); readingsBulkUpdate( $hash, "power", "off" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} else { } else {
readingsSingleUpdate( $hash, "state", "on", 1 ); readingsBulkUpdate( $hash, "state", "on" );
readingsSingleUpdate( $hash, "power", "on", 1 ); readingsBulkUpdate( $hash, "power", "on" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} }
} elsif( $args[ 0 ] eq "1" ) { } elsif( $args[ 0 ] eq "1" ) {
readingsSingleUpdate( $hash, "state", "on", 1 ); readingsBulkUpdate( $hash, "state", "on" );
readingsSingleUpdate( $hash, "power", "on", 1 ); readingsBulkUpdate( $hash, "power", "on" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} elsif( $args[ 0 ] eq "0" ) { } elsif( $args[ 0 ] eq "0" ) {
readingsSingleUpdate( $hash, "presence", "absent", 0 ); readingsBulkUpdate( $hash, "presence", "absent" );
readingsSingleUpdate( $hash, "state", "off", 1 ); readingsBulkUpdate( $hash, "state", "off" );
readingsSingleUpdate( $hash, "power", "off", 1 ); readingsBulkUpdate( $hash, "power", "off" );
SB_PLAYER_Amplifier( $hash ); SB_PLAYER_Amplifier( $hash );
} else { } else {
# should be "?" normally # should be "?" normally
@ -736,7 +739,7 @@ sub SB_PLAYER_Parse( $$ ) {
# to be ignored, we get two hashes # to be ignored, we get two hashes
} elsif( ($cmd eq "unknownir" ) || ($cmd eq "ir" ) ) { } elsif( ($cmd eq "unknownir" ) || ($cmd eq "ir" ) ) {
readingsSingleUpdate( $hash, "lastir", $args[ 0 ], 1 ); readingsBulkUpdate( $hash, "lastir", $args[ 0 ] );
} elsif( $cmd eq "status" ) { } elsif( $cmd eq "status" ) {
SB_SERVER_ParsePlayerStatus( $hash, \@args ); SB_SERVER_ParsePlayerStatus( $hash, \@args );
@ -750,10 +753,12 @@ sub SB_PLAYER_Parse( $$ ) {
if( $args[ 0 ] eq "server" ) { if( $args[ 0 ] eq "server" ) {
if( $args[ 1 ] eq "currentSong" ) { if( $args[ 1 ] eq "currentSong" ) {
readingsBulkUpdate( $hash, "currentMedia", $args[ 2 ] ); readingsBulkUpdate( $hash, "currentMedia", $args[ 2 ] );
} elsif( $args[ 1 ] eq "volume" ) {
SB_SERVER_UpdateVolumeReadings( $hash, $args[ 2 ], true );
} }
} else { } else {
readingsSingleUpdate( $hash, "lastunkowncmd", readingsBulkUpdate( $hash, "lastunkowncmd",
$cmd . " " . join( " ", @args ), 1 ); $cmd . " " . join( " ", @args ) );
} }
@ -763,8 +768,8 @@ sub SB_PLAYER_Parse( $$ ) {
} else { } else {
# unkown command, we push it to the last command thingy # unkown command, we push it to the last command thingy
readingsSingleUpdate( $hash, "lastunkowncmd", readingsBulkUpdate( $hash, "lastunkowncmd",
$cmd . " " . join( " ", @args ), 1 ); $cmd . " " . join( " ", @args ) );
} }
# and signal the end of the readings update # and signal the end of the readings update
@ -820,20 +825,26 @@ sub SB_PLAYER_Shutdown( $$ ) {
sub SB_PLAYER_Get( $@ ) { sub SB_PLAYER_Get( $@ ) {
my ($hash, @a) = @_; my ($hash, @a) = @_;
#my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log3( $hash, 1, "SB_PLAYER_Get: called with @a" ); Log3( $hash, 1, "SB_PLAYER_Get: called with @a" );
my $name = shift( @a ); if( @a < 2 ) {
my $msg = "SB_PLAYER_Get: $name: wrong number of arguments";
Log3( $hash, 5, $msg );
return( $msg );
}
#my $name = shift( @a );
shift( @a ); # name
my $cmd = shift( @a ); my $cmd = shift( @a );
# if( int( @a ) != 2 ) { if( $cmd eq "?" ) {
# my $msg = "SB_PLAYER_Get: $name: wrong number of arguments"; my $res = "Unknown argument ?, choose one of " .
# Log3( $hash, 5, $msg ); "volume " . $hash->{FAVSET} . " ";
# return( $msg ); return( $res );
# }
} elsif( $cmd eq "volume" ) {
if( $cmd eq "volume" ) {
return( scalar( ReadingsVal( "$name", "volumeStraight", 25 ) ) ); return( scalar( ReadingsVal( "$name", "volumeStraight", 25 ) ) );
} elsif( $cmd eq $hash->{FAVSET} ) { } elsif( $cmd eq $hash->{FAVSET} ) {
@ -930,7 +941,12 @@ sub SB_PLAYER_Set( $@ ) {
} }
# set the volume to the desired level. Needs to be 0..100 # set the volume to the desired level. Needs to be 0..100
# no error checking here, as the server does this # no error checking here, as the server does this
IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume $arg[ 0 ]\n" ); if( $arg[ 0 ] <= AttrVal( $name, "volumeLimit", 100 ) ) {
IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume $arg[ 0 ]\n" );
} else {
IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume " .
AttrVal( $name, "volumeLimit", 50 ) . "\n" );
}
} elsif( $cmd eq $hash->{FAVSET} ) { } elsif( $cmd eq $hash->{FAVSET} ) {
if( defined( $SB_PLAYER_Favs{$name}{$arg[0]}{ID} ) ) { if( defined( $SB_PLAYER_Favs{$name}{$arg[0]}{ID} ) ) {
@ -944,16 +960,20 @@ sub SB_PLAYER_Set( $@ ) {
} elsif( ( $cmd eq "volumeUp" ) || ( $cmd eq "VOLUMEUP" ) || } elsif( ( $cmd eq "volumeUp" ) || ( $cmd eq "VOLUMEUP" ) ||
( $cmd eq "VolumeUp" ) ) { ( $cmd eq "VolumeUp" ) ) {
#SB_PLAYER_HTTPWrite( $hash, "mixer", "volume", # increase volume
#"%2B$attr{$name}{volumeStep} " ); if( ( ReadingsVal( $name, "volumeStraight", 50 ) +
my $volstr = sprintf( "+%02d", $attr{$name}{volumeStep} ); AttrVal( $name, "volumeStep", 10 ) ) <=
IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume $volstr\n" ); AttrVal( $name, "volumeLimit", 100 ) ) {
my $volstr = sprintf( "+%02d", AttrVal( $name, "volumeStep", 10 ) );
IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume $volstr\n" );
} else {
IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume " .
AttrVal( $name, "volumeLimit", 50 ) . "\n" );
}
} elsif( ( $cmd eq "volumeDown" ) || ( $cmd eq "VOLUMEDOWN" ) || } elsif( ( $cmd eq "volumeDown" ) || ( $cmd eq "VOLUMEDOWN" ) ||
( $cmd eq "VolumeDown" ) ) { ( $cmd eq "VolumeDown" ) ) {
#SB_PLAYER_HTTPWrite( $hash, "mixer", "volume", my $volstr = sprintf( "-%02d", AttrVal( $name, "volumeStep", 10 ) );
# "%2D$attr{$name}{volumeStep}" );
my $volstr = sprintf( "-%02d", $attr{$name}{volumeStep} );
IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume $volstr\n" ); IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume $volstr\n" );
} elsif( ( $cmd eq "mute" ) || ( $cmd eq "MUTE" ) || ( $cmd eq "Mute" ) ) { } elsif( ( $cmd eq "mute" ) || ( $cmd eq "MUTE" ) || ( $cmd eq "Mute" ) ) {
@ -1034,7 +1054,7 @@ sub SB_PLAYER_Set( $@ ) {
. "&q=". $outstr; . "&q=". $outstr;
Log3( $hash, 1, "SB_PLAYER_Set: talk: $name: $outstr" ); Log3( $hash, 1, "SB_PLAYER_Set: talk: $name: $outstr" );
#readingsSingleUpdate( $hash, "talkStatus", "requested", 1 ); #readingsSingleUpdate( $hash, "talkStatus", "requested", 1 );
# example for making it speak some google text-to-speech # example for making it speak some google text-to-speech
#IOWrite( $hash, "$hash->{PLAYERMAC} playlist play " . $outstr . "\n" ); #IOWrite( $hash, "$hash->{PLAYERMAC} playlist play " . $outstr . "\n" );
@ -1051,7 +1071,7 @@ sub SB_PLAYER_Set( $@ ) {
Log3( $hash, 1, "SB_PLAYER: talkStatus = $hash->{READINGS}{talkStatus}{VAL}" ); Log3( $hash, 1, "SB_PLAYER: talkStatus = $hash->{READINGS}{talkStatus}{VAL}" );
Log3( $hash, 1, "SB_PLAYER: talk: add $outstr" ); Log3( $hash, 1, "SB_PLAYER: talk: add $outstr" );
} }
readingsSingleUpdate( $hash, "talkStatus", "requested", 1 ); readingsSingleUpdate( $hash, "talkStatus", "requested", 1 );
} elsif( ( $cmd eq "playlist" ) || } elsif( ( $cmd eq "playlist" ) ||
( $cmd eq "PLAYLIST" ) || ( $cmd eq "PLAYLIST" ) ||
@ -1126,8 +1146,14 @@ sub SB_PLAYER_Set( $@ ) {
# saves player's context # saves player's context
Log3( $hash, 5, "SB_PLAYER_Set: save " ); Log3( $hash, 5, "SB_PLAYER_Set: save " );
readingsSingleUpdate( $hash, "savedState", $hash->{READINGS}{state}{VAL}, 1 ); readingsSingleUpdate( $hash,
readingsSingleUpdate( $hash, "savedPlayStatus", $hash->{READINGS}{playStatus}{VAL}, 1 ); "savedState",
$hash->{READINGS}{state}{VAL},
1 );
readingsSingleUpdate( $hash,
"savedPlayStatus",
$hash->{READINGS}{playStatus}{VAL},
1 );
IOWrite( $hash, "$hash->{PLAYERMAC} playlist save fhem_$hash->{NAME}\n" ); IOWrite( $hash, "$hash->{PLAYERMAC} playlist save fhem_$hash->{NAME}\n" );
# if( $hash->{READINGS}{savedState}{VAL} eq "pause" ) { # if( $hash->{READINGS}{savedState}{VAL} eq "pause" ) {
# # last commands changed the status to stopped ??? # # last commands changed the status to stopped ???
@ -1198,7 +1224,7 @@ sub SB_PLAYER_Set( $@ ) {
} elsif( $cmd eq "unsync" ) { } elsif( $cmd eq "unsync" ) {
IOWrite( $hash, "$hash->{PLAYERMAC} sync -\n" ); IOWrite( $hash, "$hash->{PLAYERMAC} sync -\n" );
SB_PLAYER_GetStatus( $hash ); SB_PLAYER_GetStatus( $hash );
} elsif( $cmd eq "playlists" ) { } elsif( $cmd eq "playlists" ) {
if( @arg == 1 ) { if( @arg == 1 ) {
my $msg; my $msg;
@ -1449,7 +1475,7 @@ sub SB_PLAYER_RecBroadcast( $$@ ) {
} elsif( $cmd eq "PLAYLISTS" ) { } elsif( $cmd eq "PLAYLISTS" ) {
if( $args[ 0 ] eq "ADD" ) { if( $args[ 0 ] eq "ADD" ) {
Log3( $hash, 5, "SB_PLAYER_RecbroadCast($name): PLAYLISTS ADD " . Log3( $hash, 5, "SB_PLAYER_RecbroadCast($name): PLAYLISTS ADD " .
"name:$args[1] id:$args[2] uid:$args[3]" ); "name:$args[1] id:$args[2] uid:$args[3]" );
$SB_PLAYER_Playlists{$name}{$args[3]}{ID} = $args[ 2 ]; $SB_PLAYER_Playlists{$name}{$args[3]}{ID} = $args[ 2 ];
$SB_PLAYER_Playlists{$name}{$args[3]}{NAME} = $args[ 1 ]; $SB_PLAYER_Playlists{$name}{$args[3]}{NAME} = $args[ 1 ];
if( $hash->{SERVERPLAYLISTS} eq "" ) { if( $hash->{SERVERPLAYLISTS} eq "" ) {
@ -1571,7 +1597,7 @@ sub SB_PLAYER_Amplifier( $ ) {
} }
} else { } else {
Log3( $hash, 4, "SB_PLAYER_Amplifier($name): ATTR amplifier " . Log3( $hash, 4, "SB_PLAYER_Amplifier($name): ATTR amplifier " .
"set to wrong value [on|play]" ); "set to wrong value [on|play]" );
} }
fhem( "set $hash->{AMPLIFIER} $setvalue" ); fhem( "set $hash->{AMPLIFIER} $setvalue" );
@ -1616,7 +1642,7 @@ sub SB_PLAYER_CoverArt( $ ) {
$hash->{COVERARTURL} ); $hash->{COVERARTURL} );
} }
} }
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Handle the return for a playerstatus query # Handle the return for a playerstatus query
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
@ -1746,15 +1772,12 @@ sub SB_SERVER_ParsePlayerStatus( $$ ) {
next; next;
} elsif( $_ =~ /^(mixervolume:)(.*)/ ) { } elsif( $_ =~ /^(mixervolume:)(.*)/ ) {
if( scalar( $2 ) > 0 ) { if( ( index( $2, "+" ) != -1 ) || ( index( $2, "-" ) != -1 ) ) {
readingsBulkUpdate( $hash, "volume", # that was a relative value. We do nothing and fire an update
scalar( $2 ) ); IOWrite( $hash, "$hash->{PLAYERMAC} mixer volume ?\n" );
} else { } else {
readingsBulkUpdate( $hash, "volume", SB_SERVER_UpdateVolumeReadings( $hash, $2, true );
"muted" );
} }
readingsBulkUpdate( $hash, "volumeStraight",
scalar( $2 ) );
next; next;
} elsif( $_ =~ /^(playlistshuffle:)(.*)/ ) { } elsif( $_ =~ /^(playlistshuffle:)(.*)/ ) {
@ -1811,6 +1834,34 @@ sub SB_SERVER_ParsePlayerStatus( $$ ) {
} }
# ----------------------------------------------------------------------------
# update the volume readings
# ----------------------------------------------------------------------------
sub SB_SERVER_UpdateVolumeReadings( $$$ ) {
my( $hash, $vol, $bulk ) = @_;
my $name = $hash->{NAME};
if( $bulk == true ) {
readingsBulkUpdate( $hash, "volumeStraight", $vol );
if( $vol > 0 ) {
readingsBulkUpdate( $hash, "volume", $vol );
} else {
readingsBulkUpdate( $hash, "volume", "muted" );
}
} else {
readingsSingleUpdate( $hash, "volumeStraight", $vol, 0 );
if( $vol > 0 ) {
readingsSingleUpdate( $hash, "volume", $vol, 0 );
} else {
readingsSingleUpdate( $hash, "volume", "muted", 0 );
}
}
return;
}
# DO NOT WRITE BEYOND THIS LINE # DO NOT WRITE BEYOND THIS LINE
1; 1;