2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

YAMAHA_BD: fixing wrong "off" events when player is turned on via set command (Forum: #44618), replace \t with spaces, minor code makeup

git-svn-id: https://svn.fhem.de/fhem/trunk@9996 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2015-11-24 19:05:33 +00:00
parent 641b183bf2
commit 1804a84f47
2 changed files with 87 additions and 101 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- bugfix: YAMAHA_BD: fix power off events when player is turned on
via set command on
- bugfix: 95_Dashboard: fixed javascript bug causing tabs not to load - bugfix: 95_Dashboard: fixed javascript bug causing tabs not to load
- feature: 36_DavisVantage.zip (author: "habeIchVergessen") - feature: 36_DavisVantage.zip (author: "habeIchVergessen")
Receive Davis Vantage Weather Stations with JeeLink Receive Davis Vantage Weather Stations with JeeLink

View File

@ -76,7 +76,7 @@ YAMAHA_BD_GetStatus($;$)
# get the model informations if no informations are available # get the model informations if no informations are available
if((not defined($hash->{MODEL})) or (not defined($hash->{FIRMWARE}))) if((not defined($hash->{MODEL})) or (not defined($hash->{FIRMWARE})))
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Config>GetParam</Config></System></YAMAHA_AV>", "statusRequest","systemConfig"); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Config>GetParam</Config></System></YAMAHA_AV>", "statusRequest","systemConfig");
} }
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting system status"; Log3 $name, 4, "YAMAHA_BD ($name) - Requesting system status";
@ -85,10 +85,10 @@ YAMAHA_BD_GetStatus($;$)
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting power state"; Log3 $name, 4, "YAMAHA_BD ($name) - Requesting power state";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone></YAMAHA_AV>", "statusRequest","powerStatus"); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone></YAMAHA_AV>", "statusRequest","powerStatus");
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting playing info"; Log3 $name, 4, "YAMAHA_BD ($name) - Requesting playing info";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Play_Info>GetParam</Play_Info></Main_Zone></YAMAHA_AV>", "statusRequest","playInfo"); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Play_Info>GetParam</Play_Info></Main_Zone></YAMAHA_AV>", "statusRequest","playInfo");
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting trickPlay info"; Log3 $name, 4, "YAMAHA_BD ($name) - Requesting trickPlay info";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Play_Control>GetParam</Play_Control></Main_Zone></YAMAHA_AV>", "statusRequest","trickPlayInfo"); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Play_Control>GetParam</Play_Control></Main_Zone></YAMAHA_AV>", "statusRequest","trickPlayInfo");
# Reset timer if this is not a local run # Reset timer if this is not a local run
@ -103,7 +103,7 @@ YAMAHA_BD_Get($@)
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $what; my $what;
my $return; my $return;
return "argument is missing" if(int(@a) != 2); return "argument is missing" if(int(@a) != 2);
$what = $a[1]; $what = $a[1];
@ -114,24 +114,24 @@ YAMAHA_BD_Get($@)
if(defined($hash->{READINGS}{$what})) if(defined($hash->{READINGS}{$what}))
{ {
return $hash->{READINGS}{$what}{VAL}; return $hash->{READINGS}{$what}{VAL};
} }
else else
{ {
return "no such reading: $what"; return "no such reading: $what";
} }
} }
else else
{ {
$return = "unknown argument $what, choose one of"; $return = "unknown argument $what, choose one of";
foreach my $reading (keys %{$hash->{READINGS}}) foreach my $reading (keys %{$hash->{READINGS}})
{ {
$return .= " $reading:noArg"; $return .= " $reading:noArg";
} }
return $return; return $return;
} }
} }
@ -150,8 +150,8 @@ YAMAHA_BD_Set($@)
my $usage = "Unknown argument $what, choose one of on:noArg off:noArg statusRequest:noArg tray:open,close remoteControl:eject,up,down,left,right,return,enter,OSDonScreen,OSDstatus,topMenu,popupMenu,red,green,blue,yellow,0,1,2,3,4,5,6,7,8,9,setup,home,clear,program,search,repeat,repeat-AB,subtitle,angle,audio,pictureInPicture,secondVideo,secondAudio,power fast:forward,reverse slow:forward,reverse skip:forward,reverse play:noArg pause:noArg stop:noArg trickPlay:normal,repeatChapter,repeatTitle,repeatFolder,repeat-AB,randomChapter,randomTitle,randomAll,shuffleChapter,shuffleTitle,shuffleAll,setApoint"; my $usage = "Unknown argument $what, choose one of on:noArg off:noArg statusRequest:noArg tray:open,close remoteControl:eject,up,down,left,right,return,enter,OSDonScreen,OSDstatus,topMenu,popupMenu,red,green,blue,yellow,0,1,2,3,4,5,6,7,8,9,setup,home,clear,program,search,repeat,repeat-AB,subtitle,angle,audio,pictureInPicture,secondVideo,secondAudio,power fast:forward,reverse slow:forward,reverse skip:forward,reverse play:noArg pause:noArg stop:noArg trickPlay:normal,repeatChapter,repeatTitle,repeatFolder,repeat-AB,randomChapter,randomTitle,randomAll,shuffleChapter,shuffleTitle,shuffleAll,setApoint";
if($what eq "on") if($what eq "on")
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Power_Control><Power>On</Power></Power_Control></Main_Zone></YAMAHA_AV>","on",undef); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Power_Control><Power>On</Power></Power_Control></Main_Zone></YAMAHA_AV>","on",undef);
} }
elsif($what eq "off") elsif($what eq "off")
{ {
@ -384,7 +384,7 @@ YAMAHA_BD_Set($@)
elsif($a[2] eq "close") elsif($a[2] eq "close")
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Tray_Control><Tray>Close</Tray></Tray_Control></Main_Zone></YAMAHA_AV>","tray","close"); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Tray_Control><Tray>Close</Tray></Tray_Control></Main_Zone></YAMAHA_AV>","tray","close");
} }
} }
elsif($what eq "skip") elsif($what eq "skip")
{ {
@ -395,7 +395,7 @@ YAMAHA_BD_Set($@)
elsif($a[2] eq "reverse") elsif($a[2] eq "reverse")
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Skip>Rev</Skip></Play_Control></Main_Zone></YAMAHA_AV>","skip","reverse"); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Skip>Rev</Skip></Play_Control></Main_Zone></YAMAHA_AV>","skip","reverse");
} }
} }
elsif($what eq "fast") elsif($what eq "fast")
{ {
@ -406,7 +406,7 @@ YAMAHA_BD_Set($@)
elsif($a[2] eq "reverse") elsif($a[2] eq "reverse")
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Fast>Rev</Fast></Play_Control></Main_Zone></YAMAHA_AV>","fast","reverse"); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Fast>Rev</Fast></Play_Control></Main_Zone></YAMAHA_AV>","fast","reverse");
} }
} }
elsif($what eq "slow") elsif($what eq "slow")
{ {
@ -417,7 +417,7 @@ YAMAHA_BD_Set($@)
elsif($a[2] eq "reverse") elsif($a[2] eq "reverse")
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Slow>Rev</Slow></Play_Control></Main_Zone></YAMAHA_AV>","slow","reverse"); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Slow>Rev</Slow></Play_Control></Main_Zone></YAMAHA_AV>","slow","reverse");
} }
} }
elsif($what eq "play") elsif($what eq "play")
{ {
@ -435,13 +435,8 @@ YAMAHA_BD_Set($@)
{ {
return $usage; return $usage;
} }
# Call the GetStatus() Function to retrieve the new values after setting something (with local flag, so the internal timer is not getting interupted)
YAMAHA_BD_GetStatus($hash, 1);
return undef; return undef;
} }
@ -455,9 +450,9 @@ YAMAHA_BD_Define($$)
if(! @a >= 3) if(! @a >= 3)
{ {
my $msg = "wrong syntax: define <name> YAMAHA_BD <ip-or-hostname> [<statusinterval>] [<presenceinterval>]"; my $msg = "wrong syntax: define <name> YAMAHA_BD <ip-or-hostname> [<statusinterval>] [<presenceinterval>]";
Log 2, $msg; Log 2, $msg;
return $msg; return $msg;
} }
my $address = $a[2]; my $address = $a[2];
@ -467,27 +462,26 @@ YAMAHA_BD_Define($$)
# 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[3]) and $a[3] > 0) if(defined($a[3]) and $a[3] > 0)
{ {
$hash->{helper}{OFF_INTERVAL}=$a[3]; $hash->{helper}{OFF_INTERVAL}=$a[3];
} }
else else
{ {
$hash->{helper}{OFF_INTERVAL}=30; $hash->{helper}{OFF_INTERVAL}=30;
} }
# if a second update interval is given, use this as ON_INTERVAL, otherwise use OFF_INTERVAL instead. # if a second update interval is given, use this as ON_INTERVAL, otherwise use OFF_INTERVAL instead.
if(defined($a[4]) and $a[4] > 0) if(defined($a[4]) and $a[4] > 0)
{ {
$hash->{helper}{ON_INTERVAL}=$a[4]; $hash->{helper}{ON_INTERVAL}=$a[4];
} }
else else
{ {
$hash->{helper}{ON_INTERVAL}=$hash->{helper}{OFF_INTERVAL}; $hash->{helper}{ON_INTERVAL}=$hash->{helper}{OFF_INTERVAL};
} }
# start the status update timer # start the status update timer
$hash->{helper}{DISABLED} = 0 unless(exists($hash->{helper}{DISABLED})); $hash->{helper}{DISABLED} = 0 unless(exists($hash->{helper}{DISABLED}));
YAMAHA_BD_ResetTimer($hash, 2); YAMAHA_BD_ResetTimer($hash, 2);
return undef; return undef;
} }
@ -590,12 +584,11 @@ YAMAHA_BD_ParseResponse($$$)
Log3 $name, 4, "YAMAHA_BD ($name) - error while executing \"$cmd".(defined($arg) ? " ".$arg : "")."\": $err"; Log3 $name, 4, "YAMAHA_BD ($name) - error while executing \"$cmd".(defined($arg) ? " ".$arg : "")."\": $err";
if((not exists($hash->{helper}{AVAILABLE})) or (exists($hash->{helper}{AVAILABLE}) and $hash->{helper}{AVAILABLE} eq 1)) if((not exists($hash->{helper}{AVAILABLE})) or (exists($hash->{helper}{AVAILABLE}) and $hash->{helper}{AVAILABLE} eq 1))
{ {
Log3 $name, 3, "YAMAHA_BD ($name) - could not execute command on device $name. Please turn on your device in case of deactivated network standby or check for correct hostaddress: $err"; Log3 $name, 3, "YAMAHA_BD ($name) - could not execute command on device $name. Please turn on your device in case of deactivated network standby or check for correct hostaddress: $err";
readingsSingleUpdate($hash, "presence", "absent", 1); readingsSingleUpdate($hash, "presence", "absent", 1);
readingsSingleUpdate($hash, "state", "absent", 1); readingsSingleUpdate($hash, "state", "absent", 1);
} }
} }
elsif($data ne "") elsif($data ne "")
{ {
@ -603,40 +596,38 @@ YAMAHA_BD_ParseResponse($$$)
Log3 $name, 5, "YAMAHA_BD ($name) - got HTTP response for \"$cmd".(defined($arg) ? " ".$arg : "")."\": $data"; Log3 $name, 5, "YAMAHA_BD ($name) - got HTTP response for \"$cmd".(defined($arg) ? " ".$arg : "")."\": $data";
if (defined($hash->{helper}{AVAILABLE}) and $hash->{helper}{AVAILABLE} == 0) if (defined($hash->{helper}{AVAILABLE}) and $hash->{helper}{AVAILABLE} == 0)
{ {
Log3 $name, 3, "YAMAHA_BD: device $name reappeared"; Log3 $name, 3, "YAMAHA_BD: device $name reappeared";
readingsSingleUpdate($hash, "presence", "present", 1); readingsSingleUpdate($hash, "presence", "present", 1);
} }
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
if(not $data =~ /RC="0"/) if(not $data =~ /RC="0"/)
{ {
# if the returncode isn't 0, than the command was not successful # if the returncode isn't 0, than the command was not successful
Log3 $name, 3, "YAMAHA_BD ($name) - Could not execute \"$cmd".(defined($arg) ? " ".$arg : "")."\""; Log3 $name, 3, "YAMAHA_BD ($name) - Could not execute \"$cmd".(defined($arg) ? " ".$arg : "")."\"";
} }
if($cmd eq "statusRequest" and $arg eq "systemStatus") if($cmd eq "statusRequest" and $arg eq "systemStatus")
{ {
if($data =~ /<Error_Info>(.+?)<\/Error_Info>/) if($data =~ /<Error_Info>(.+?)<\/Error_Info>/)
{ {
readingsBulkUpdate($hash, "error", lc($1)); readingsBulkUpdate($hash, "error", lc($1));
} }
} }
elsif($cmd eq "statusRequest" and $arg eq "systemConfig") elsif($cmd eq "statusRequest" and $arg eq "systemConfig")
{ {
if($data =~ /<Model_Name>(.+?)<\/Model_Name>.*<Version>(.+?)<\/Version>/) if($data =~ /<Model_Name>(.+?)<\/Model_Name>.*<Version>(.+?)<\/Version>/)
{ {
$hash->{MODEL} = $1; $hash->{MODEL} = $1;
$hash->{FIRMWARE} = $2; $hash->{FIRMWARE} = $2;
$hash->{MODEL} =~ s/\s*YAMAHA\s*//g;
$attr{$name}{"model"} = $hash->{MODEL};
}
$hash->{MODEL} =~ s/\s*YAMAHA\s*//g;
$attr{$name}{"model"} = $hash->{MODEL};
}
} }
elsif($cmd eq "statusRequest" and $arg eq "powerStatus") elsif($cmd eq "statusRequest" and $arg eq "powerStatus")
{ {
@ -645,36 +636,33 @@ YAMAHA_BD_ParseResponse($$$)
my $power = $1; my $power = $1;
if($power eq "Standby" or $power eq "Network Standby") if($power eq "Standby" or $power eq "Network Standby")
{ {
$power = "off"; $power = "off";
} }
readingsBulkUpdate($hash, "power", lc($power)); readingsBulkUpdate($hash, "power", lc($power));
readingsBulkUpdate($hash, "state", lc($power)); readingsBulkUpdate($hash, "state", lc($power));
} }
} }
elsif($cmd eq "on") elsif($cmd eq "on")
{ {
if($data =~ /RC="0"/ and $data =~ /<Power><\/Power>/) if($data =~ /RC="0"/ and $data =~ /<Power><\/Power>/)
{ {
# As the player startup takes about 5 seconds, the status will be already set, if the return code of the command is 0. # As the player startup takes about 5 seconds, the status will be already set, if the return code of the command is 0.
readingsBulkUpdate($hash, "power", "on"); readingsBulkUpdate($hash, "power", "on");
readingsBulkUpdate($hash, "state","on"); readingsBulkUpdate($hash, "state","on");
} }
else else
{ {
Log3 $name, 3, "YAMAHA_BD ($name) - Could not set power to on"; Log3 $name, 3, "YAMAHA_BD ($name) - Could not set power to on";
} }
} }
elsif($cmd eq "statusRequest" and $arg eq "trickPlayInfo") elsif($cmd eq "statusRequest" and $arg eq "trickPlayInfo")
{ {
if($data =~ /<Trick_Play>(.+?)<\/Trick_Play>/) if($data =~ /<Trick_Play>(.+?)<\/Trick_Play>/)
{ {
readingsBulkUpdate($hash, "trickPlay", $1); readingsBulkUpdate($hash, "trickPlay", $1);
} }
} }
elsif($cmd eq "statusRequest" and $arg eq "playInfo") elsif($cmd eq "statusRequest" and $arg eq "playInfo")
@ -721,7 +709,7 @@ YAMAHA_BD_ParseResponse($$$)
if($data =~ /<Input_Info><Status>(.+?)<\/Status><\/Input_Info/) if($data =~ /<Input_Info><Status>(.+?)<\/Status><\/Input_Info/)
{ {
readingsBulkUpdate($hash, "input", $1); readingsBulkUpdate($hash, "input", $1);
} }
elsif($data =~ /<Input_Info>(.+?)<\/Input_Info/) elsif($data =~ /<Input_Info>(.+?)<\/Input_Info/)
{ {
@ -746,12 +734,10 @@ YAMAHA_BD_ParseResponse($$$)
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
YAMAHA_BD_GetStatus($hash, 1) if($cmd ne "statusRequest"); YAMAHA_BD_GetStatus($hash, 1) if($cmd ne "statusRequest" and $cmd ne "on");
} }
$hash->{helper}{AVAILABLE} = ($err ? 0 : 1); $hash->{helper}{AVAILABLE} = ($err ? 0 : 1);
} }
@ -834,8 +820,6 @@ sub YAMAHA_BD_formatTimestamp($)
my ($sec) = sprintf("%02d", unpack("s", pack "s", hex(substr($hex, 4, 2)))); my ($sec) = sprintf("%02d", unpack("s", pack "s", hex(substr($hex, 4, 2))));
return "$hour:$min:$sec"; return "$hour:$min:$sec";
} }
1; 1;
@ -976,7 +960,7 @@ sub YAMAHA_BD_formatTimestamp($)
<code>get &lt;name&gt; &lt;reading&gt;</code> <code>get &lt;name&gt; &lt;reading&gt;</code>
<br><br> <br><br>
Currently, the get command only returns the reading values. For a specific list of possible values, see section "Generated Readings/Events". Currently, the get command only returns the reading values. For a specific list of possible values, see section "Generated Readings/Events".
<br><br> <br><br>
</ul> </ul>
<a name="YAMAHA_BDattr"></a> <a name="YAMAHA_BDattr"></a>
<b>Attributes</b> <b>Attributes</b>
@ -984,13 +968,13 @@ sub YAMAHA_BD_formatTimestamp($)
<li><a href="#do_not_notify">do_not_notify</a></li> <li><a href="#do_not_notify">do_not_notify</a></li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li><br> <li><a href="#readingFnAttributes">readingFnAttributes</a></li><br>
<li><a name="disable">disable</a></li> <li><a name="disable">disable</a></li>
Optional attribute to disable the internal cyclic status update of the player. Manual status updates via statusRequest command is still possible. Optional attribute to disable the internal cyclic status update of the player. Manual status updates via statusRequest command is still possible.
<br><br> <br><br>
Possible values: 0 => perform cyclic status update, 1 => don't perform cyclic status updates.<br><br> Possible values: 0 => perform cyclic status update, 1 => don't perform cyclic status updates.<br><br>
<li><a name="request-timeout">request-timeout</a></li> <li><a name="request-timeout">request-timeout</a></li>
Optional attribute change the response timeout in seconds for all queries to the player. Optional attribute change the response timeout in seconds for all queries to the player.
<br><br> <br><br>
Possible values: 1-5 seconds. Default value is 4 seconds.<br><br> Possible values: 1-5 seconds. Default value is 4 seconds.<br><br>
</ul> </ul>
<b>Generated Readings/Events:</b><br> <b>Generated Readings/Events:</b><br>
<ul> <ul>
@ -1164,13 +1148,13 @@ sub YAMAHA_BD_formatTimestamp($)
<li><a href="#do_not_notify">do_not_notify</a></li> <li><a href="#do_not_notify">do_not_notify</a></li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li><br> <li><a href="#readingFnAttributes">readingFnAttributes</a></li><br>
<li><a name="disable">disable</a></li> <li><a name="disable">disable</a></li>
Optionales Attribut zur Deaktivierung des zyklischen Status-Updates. Ein manuelles Update via statusRequest-Befehl ist dennoch m&ouml;glich. Optionales Attribut zur Deaktivierung des zyklischen Status-Updates. Ein manuelles Update via statusRequest-Befehl ist dennoch m&ouml;glich.
<br><br> <br><br>
M&ouml;gliche Werte: 0 => zyklische Status-Updates, 1 => keine zyklischen Status-Updates.<br><br> M&ouml;gliche Werte: 0 => zyklische Status-Updates, 1 => keine zyklischen Status-Updates.<br><br>
<li><a name="request-timeout">request-timeout</a></li> <li><a name="request-timeout">request-timeout</a></li>
Optionales Attribut. Maximale Dauer einer Anfrage in Sekunden zum Player. Optionales Attribut. Maximale Dauer einer Anfrage in Sekunden zum Player.
<br><br> <br><br>
M&ouml;gliche Werte: 1-5 Sekunden. Standartwert ist 4 Sekunden<br><br> M&ouml;gliche Werte: 1-5 Sekunden. Standartwert ist 4 Sekunden<br><br>
</ul> </ul>
<b>Generierte Readings/Events:</b><br> <b>Generierte Readings/Events:</b><br>
<ul> <ul>