diff --git a/CHANGED b/CHANGED index 968f71a0c..7cc6b963e 100644 --- a/CHANGED +++ b/CHANGED @@ -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. + - feature: 71_PHILIPS_AUDIO Improved usability. New preset/fav attributes. - bugfix: 71_YAMAHA_NP Minor code correction - bugfix: SYSMON: attribute disable does not work properly - fixed: 10_pilight_ctrl send long raw codes diff --git a/FHEM/71_PHILIPS_AUDIO.pm b/FHEM/71_PHILIPS_AUDIO.pm index b84f8a5b2..0a3252934 100755 --- a/FHEM/71_PHILIPS_AUDIO.pm +++ b/FHEM/71_PHILIPS_AUDIO.pm @@ -50,7 +50,7 @@ sub PHILIPS_AUDIO_Initialize $hash->{AttrFn} = "PHILIPS_AUDIO_Attr"; $hash->{UndefFn} = "PHILIPS_AUDIO_Undefine"; - $hash->{AttrList} = "do_not_notify:0,1 disable:0,1 model request-timeout:1,2,3,4,5 ".$readingFnAttributes; + $hash->{AttrList} = "do_not_notify:0,1 disable:0,1 model max-device-presets max-device-favorites request-timeout:1,2,3,4,5 ".$readingFnAttributes; return; } @@ -68,6 +68,29 @@ sub PHILIPS_AUDIO_GetStatus my $device = $hash->{IP_ADDRESS}; + + # Check for Presets availability + if(not defined($hash->{READINGS}{"totalInetRadioPresets"})) + { + # Hierarchichal navigation through the contents mandatory + $hash->{helper}{cmdStep} = 1; + PHILIPS_AUDIO_SendCommand($hash, "/index", "", "getInetRadioPresets", "noArg"); + # Wait 10 seconds for next http request due to slow command processing of the streamium devices. + PHILIPS_AUDIO_ResetTimer($hash, 10); + return; + } + + # Check for Favorites availability + if(not defined($hash->{READINGS}{"totalInetRadioFavorites"})) + { + # Hierarchichal navigation through the contents mandatory + $hash->{helper}{cmdStep} = 1; + PHILIPS_AUDIO_SendCommand($hash, "/index", "", "getInetRadioFavorites", "noArg"); + # Wait 10 seconds for next http request due to slow command processing of the streamium devices. + PHILIPS_AUDIO_ResetTimer($hash, 10); + return; + } + PHILIPS_AUDIO_SendCommand($hash, "/nowplay", "","nowplay", "noArg"); PHILIPS_AUDIO_ResetTimer($hash) unless($local == 1); @@ -133,19 +156,25 @@ sub PHILIPS_AUDIO_Set return "No Argument given" if(!defined($a[1])); - if (not defined($hash->{helper}{PRESETS}) or length($hash->{helper}{PRESETS}) == 0) - { - PHILIPS_AUDIO_updatePresets($hash); - } - - if (not defined($hash->{helper}{FAVORITES}) or length($hash->{helper}{FAVORITES}) == 0) - { - PHILIPS_AUDIO_updateFavorites($hash); - } - - my $what = $a[1]; + my $index; + # Provide number of selectable presets according to the given attribute + my $inetRadioPreset = "inetRadioPreset:"; + for ($index = 1; $index < AttrVal($name, "max-device-presets", "24"); $index++) + { + $inetRadioPreset .= $index . ","; + } + $inetRadioPreset .= $index . " "; + + # Provide number of selectable favorites according to the given attribute + my $inetRadioFavorite = "inetRadioFavorite:"; + for ($index = 1; $index < AttrVal($name, "max-device-favorites", "24"); $index++) + { + $inetRadioFavorite .= $index . ","; + } + $inetRadioFavorite .= $index . " "; + my $usage; $usage = "Unknown argument $what, choose one of ". @@ -162,8 +191,8 @@ sub PHILIPS_AUDIO_Set "shuffle:on,off ". "aux:noArg ". #"input:aux,internetRadio,mediaLibrary,onlineServices ". - "inetRadioPreset:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 ". - "inetRadioFavorite:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 ". + $inetRadioPreset. + $inetRadioFavorite. "statusRequest:noArg ". "getInetRadioPresets:noArg ". "getInetRadioFavorites:noArg ". @@ -347,7 +376,10 @@ sub PHILIPS_AUDIO_Set else { return $usage; - } + } + + PHILIPS_AUDIO_ResetTimer($hash); + return; } @@ -868,7 +900,7 @@ sub PHILIPS_AUDIO_ParseResponse my $listedItems; # Visible Items in the display. Max 8 my $nextreqURL; my $i; - my $presetID; + my $presetID = 0; my $presetName; # Parse first 8 Presets @@ -876,6 +908,9 @@ sub PHILIPS_AUDIO_ParseResponse { # In case on presets defined the player returns an Error # Do nothing + + $hash->{helper}{TOTALINETRADIOPRESETS} = 0; + readingsBulkUpdate($hash, "totalInetRadioPresets", "0"); } else { @@ -913,7 +948,7 @@ sub PHILIPS_AUDIO_ParseResponse } if ($presetID ne "" and $presetName ne "") { - readingsBulkUpdate($hash, "inetRadioPreset$presetID", $presetName); + readingsBulkUpdate($hash, sprintf("inetRadioPreset%02d", $presetID), $presetName); } } else @@ -940,11 +975,10 @@ sub PHILIPS_AUDIO_ParseResponse #Log3 $name, 5, "Presets: $debug"; } } - } + } } elsif ($cmd eq "getInetRadioFavorites") { - # This command must be processed hierarchicaly through the navigation path if($hash->{helper}{cmdStep} == 1) { @@ -964,13 +998,15 @@ sub PHILIPS_AUDIO_ParseResponse { # In case on presets defined the player returns an Error # Do nothing + $hash->{helper}{TOTALINETRADIOFAVORITES} = 0; + readingsBulkUpdate($hash, "totalInetRadioFavorites", "0"); } else { my $listedItems; # Visible Items in the display. Max 8 my $nextreqURL; my $i; - my $favoriteID; + my $favoriteID = 0; my $favoriteName; # Parse first 8 Presets @@ -1009,7 +1045,7 @@ sub PHILIPS_AUDIO_ParseResponse } if ($favoriteID ne "" and $favoriteName ne "") { - readingsBulkUpdate($hash, "inetRadioFavorite$favoriteID", $favoriteName); + readingsBulkUpdate($hash, sprintf("inetRadioFavorite%02d", $favoriteID), $favoriteName); } } else @@ -1036,7 +1072,7 @@ sub PHILIPS_AUDIO_ParseResponse #Log3 $name, 5, "Favorites: $debug"; } } - } + } } readingsEndUpdate($hash, 1); @@ -1104,21 +1140,22 @@ sub PHILIPS_AUDIO_STREAMIUMNP2txt sub PHILIPS_AUDIO_updatePresets { my ($hash) = @_; + my $name = $hash->{NAME}; if((not defined($hash->{helper}{PRESETS}) or length($hash->{helper}{PRESETS}) == 0)) { my $presetName; - for(my $i = 1; $i < 11; $i++) + for(my $i = 1; $i < (AttrVal($name, "max-device-presets", "24") + 1); $i++) { - if(exists($hash->{READINGS}{"inetRadioPreset$i"})) + if(exists($hash->{READINGS}{sprintf("inetRadioPreset%02d", $i)})) { if($i != 1) { $presetName = ","; } - $presetName .= $i . ":"; - $presetName .= $hash->{READINGS}{"inetRadioPreset$i"}{VAL}; + $presetName .= sprintf("%02d", $i) . ":"; + $presetName .= $hash->{READINGS}{sprintf("inetRadioPreset%02d", $i)}{VAL}; $presetName =~ s/ /_/g; # Replace blank by underscore $hash->{helper}{PRESETS} .= $presetName; } @@ -1141,21 +1178,22 @@ sub PHILIPS_AUDIO_updatePresets sub PHILIPS_AUDIO_updateFavorites { my ($hash) = @_; + my $name = $hash->{NAME}; if((not defined($hash->{helper}{FAVORITES}) or length($hash->{helper}{FAVORITES}) == 0)) { my $favoriteName; - for(my $i = 1; $i < 11; $i++) + for(my $i = 1; $i < (AttrVal($name, "max-device-favorites", "24") + 1); $i++) { - if(exists($hash->{READINGS}{"inetRadioFavorite$i"})) + if(exists($hash->{READINGS}{sprintf("inetRadioFavorite%02d", $i)})) { if($i != 1) { $favoriteName = ","; } - $favoriteName .= $i . ":"; - $favoriteName .= $hash->{READINGS}{"inetRadioFavorite$i"}{VAL}; + $favoriteName .= sprintf("%02d", $i) . ":"; + $favoriteName .= $hash->{READINGS}{sprintf("inetRadioFavorite%02d" , $i)}{VAL}; $favoriteName =~ s/ /_/g; # Replace blank by underscore $hash->{helper}{FAVORITES} .= $favoriteName; } @@ -1302,6 +1340,10 @@ sub PHILIPS_AUDIO_updateFavorites