2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

Log() deprecated/replaced by Log3()

GetStatus() is called after set volume/mute to update readings immediately

git-svn-id: https://svn.fhem.de/fhem/trunk@3752 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
teevau 2013-08-19 18:41:27 +00:00
parent 36e04d8cd2
commit 54c5c27b78

View File

@ -8,9 +8,13 @@
# written 2013 by Tobias Vaupel <fhem at 622 mbit dot de> # written 2013 by Tobias Vaupel <fhem at 622 mbit dot de>
# #
# #
# Version = 1.20 # Version = 1.21
# #
# Version History: # Version History:
# - 1.21 - 2013-08-19
# -- Log() deprecated/replaced by Log3()
# -- GetStatus() is called after set volume/mute to update readings immediately
#
# - 1.20 - 2013-08-16 # - 1.20 - 2013-08-16
# -- added support according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV # -- added support according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV
# #
@ -117,7 +121,7 @@ sub VIERA_Define($$){
if(int(@args) < 3 && int(@args) > 4) { if(int(@args) < 3 && int(@args) > 4) {
my $msg = "wrong syntax: define <name> VIERA <host> [<interval>]"; my $msg = "wrong syntax: define <name> VIERA <host> [<interval>]";
Log GetLogLevel($name, 2), $msg; Log3 $name, 2, "VIERA: $msg";
return $msg; return $msg;
} }
@ -132,7 +136,7 @@ sub VIERA_Define($$){
} }
CommandAttr(undef,$name.' webCmd off') if( !defined( AttrVal($hash->{NAME}, "webCmd", undef) ) ); CommandAttr(undef,$name.' webCmd off') if( !defined( AttrVal($hash->{NAME}, "webCmd", undef) ) );
Log GetLogLevel($name, 2), "VIERA: defined with host: $hash->{helper}{HOST} and interval: $hash->{helper}{INTERVAL}"; Log3 $name, 2, "VIERA: defined with host: $hash->{helper}{HOST} and interval: $hash->{helper}{INTERVAL}";
InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "VIERA_GetStatus", $hash, 0); InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "VIERA_GetStatus", $hash, 0);
return undef; return undef;
@ -158,36 +162,40 @@ sub VIERA_Set($@){
given($what) { given($what) {
when("mute"){ when("mute"){
Log GetLogLevel($name, 3), "VIERA: Set mute $state"; Log3 $name, 3, "VIERA: Set mute $state";
if ($state eq "on") {$state = 1;} else {$state = 0;} if ($state eq "on") {$state = 1;} else {$state = 0;}
VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Set", "Mute", $state), $host); VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Set", "Mute", $state), $host);
VIERA_GetStatus($hash, 1);
break; break;
} }
when("volume"){ when("volume"){
return "VIERA: Volume range is too high! Use Value 0 till 100 for volume." if($state < 0 || $state > 100); return "VIERA: Volume range is too high! Use Value 0 till 100 for volume." if($state < 0 || $state > 100);
Log GetLogLevel($name, 3), "VIERA: Set volume $state"; Log3 $name, 3, "VIERA: Set volume $state";
VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Set", "Volume", $state), $host); VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Set", "Volume", $state), $host);
VIERA_GetStatus($hash, 1);
break; break;
} }
when("volumeup"){ when("volumeup"){
return "VIERA: Volume range is too high!" if(ReadingsVal($name, "volume", "0") > 100); return "VIERA: Volume range is too high!" if(ReadingsVal($name, "volume", "0") > 100);
Log GetLogLevel($name, 3), "VIERA: Set volumeUp"; Log3 $name, 3, "VIERA: Set volumeUp";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"VOLUP"), $host); VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"VOLUP"), $host);
VIERA_GetStatus($hash, 1);
break; break;
} }
when("volumedown"){ when("volumedown"){
return "VIERA: Volume range is too low!" if(ReadingsVal($name, "volume", "0") < 1); return "VIERA: Volume range is too low!" if(ReadingsVal($name, "volume", "0") < 1);
Log GetLogLevel($name, 3), "VIERA: Set volumeDown"; Log3 $name, 3, "VIERA: Set volumeDown";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"VOLDOWN"), $host); VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"VOLDOWN"), $host);
VIERA_GetStatus($hash, 1);
break; break;
} }
when("channel"){ when("channel"){
return "VIERA: Channel is too high or low!" if($state < 1 || $state > 9999); return "VIERA: Channel is too high or low!" if($state < 1 || $state > 9999);
Log GetLogLevel($name, 3), "VIERA: Set channel $state"; Log3 $name, 3, "VIERA: Set channel $state";
for(my $i = 0; $i <= length($state)-1; $i++) { for(my $i = 0; $i <= length($state)-1; $i++) {
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"D" . substr($state, $i, 1)), $host); VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"D" . substr($state, $i, 1)), $host);
sleep 0.1; sleep 0.1;
@ -197,13 +205,13 @@ sub VIERA_Set($@){
} }
when("channelup"){ when("channelup"){
Log GetLogLevel($name, 3), "VIERA: Set channelUp"; Log3 $name, 3, "VIERA: Set channelUp";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"CH_UP"), $host); VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"CH_UP"), $host);
break; break;
} }
when("channeldown"){ when("channeldown"){
Log GetLogLevel($name, 3), "VIERA: Set channelDown"; Log3 $name, 3, "VIERA: Set channelDown";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"CH_DOWN"), $host); VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"CH_DOWN"), $host);
break; break;
} }
@ -220,21 +228,21 @@ sub VIERA_Set($@){
} }
else{ else{
$state = uc($state); $state = uc($state);
Log GetLogLevel($name, 3), "VIERA: Set remoteControl $state"; Log3 $name, 3, "VIERA: Set remoteControl $state";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,$state), $host); VIERA_connection(VIERA_BuildXML_NetCtrl($hash,$state), $host);
} }
break; break;
} }
when("off"){ when("off"){
Log GetLogLevel($name, 3), "VIERA: Set off"; Log3 $name, 3, "VIERA: Set off";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"POWER"), $host); VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"POWER"), $host);
break; break;
} }
when("statusrequest"){ when("statusrequest"){
Log GetLogLevel($name, 3), "VIERA: Set statusRequest"; Log3 $name, 3, "VIERA: Set statusRequest";
VIERA_GetStatus($hash); VIERA_GetStatus($hash, 1);
break; break;
} }
@ -244,7 +252,7 @@ sub VIERA_Set($@){
} }
default{ default{
Log GetLogLevel($name, 3), "VIERA: Unknown argument $what, $usage"; Log3 $name, 3, "VIERA: Unknown argument $what, $usage";
return "Unknown argument $what, $usage"; return "Unknown argument $what, $usage";
}; };
} }
@ -287,14 +295,16 @@ sub VIERA_GetStatus($;$){
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $host = $hash->{helper}{HOST}; my $host = $hash->{helper}{HOST};
InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "VIERA_GetStatus", $hash, 0); #if $local is set to 1 just fetch informations from device without interupting InternalTimer
$local = 0 unless(defined($local));
InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "VIERA_GetStatus", $hash, 0) unless($local == 1);
return "" if(!defined($hash->{helper}{HOST}) or !defined($hash->{helper}{INTERVAL})); return "" if(!defined($hash->{helper}{HOST}) or !defined($hash->{helper}{INTERVAL}));
my $returnVol = VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Get", "Volume", ""), $host); my $returnVol = VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Get", "Volume", ""), $host);
Log GetLogLevel($name, 5), "VIERA: GetStatusVol-Request returned: $returnVol" if(defined($returnVol)); Log3 $name, 5, "VIERA: GetStatusVol-Request returned: $returnVol" if(defined($returnVol));
if(not defined($returnVol) or $returnVol eq "") { if(not defined($returnVol) or $returnVol eq "") {
Log GetLogLevel($name, 4), "VIERA: GetStatusVol-Request NO SOCKET!"; Log3 $name, 4, "VIERA: GetStatusVol-Request NO SOCKET!";
if( ReadingsVal($name,"state","absent") ne "absent") { if( ReadingsVal($name,"state","absent") ne "absent") {
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "state", "absent"); readingsBulkUpdate($hash, "state", "absent");
@ -306,9 +316,9 @@ sub VIERA_GetStatus($;$){
} }
my $returnMute = VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Get", "Mute", ""), $host); my $returnMute = VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Get", "Mute", ""), $host);
Log GetLogLevel($name, 5), "VIERA: GetStatusMute-Request returned: $returnMute" if(defined($returnMute)); Log3 $name, 5, "VIERA: GetStatusMute-Request returned: $returnMute" if(defined($returnMute));
if(not defined($returnMute) or $returnMute eq "") { if(not defined($returnMute) or $returnMute eq "") {
Log GetLogLevel($name, 4), "VIERA: GetStatusMute-Request NO SOCKET!"; Log3 $name, 4, "VIERA: GetStatusMute-Request NO SOCKET!";
if( ReadingsVal($name,"state","absent") ne "absent") { if( ReadingsVal($name,"state","absent") ne "absent") {
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "state", "absent"); readingsBulkUpdate($hash, "state", "absent");
@ -321,14 +331,14 @@ sub VIERA_GetStatus($;$){
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
if($returnVol =~ /<CurrentVolume>(.+)<\/CurrentVolume>/){ if($returnVol =~ /<CurrentVolume>(.+)<\/CurrentVolume>/){
Log GetLogLevel($name, 4), "VIERA: GetStatus-Set reading volume to $1"; Log3 $name, 4, "VIERA: GetStatus-Set reading volume to $1";
if( $1 != ReadingsVal($name, "volume", "0") ) {readingsBulkUpdate($hash, "volume", $1);} if( $1 != ReadingsVal($name, "volume", "0") ) {readingsBulkUpdate($hash, "volume", $1);}
} }
if($returnMute =~ /<CurrentMute>(.+)<\/CurrentMute>/){ if($returnMute =~ /<CurrentMute>(.+)<\/CurrentMute>/){
my $myMute = $1; my $myMute = $1;
if ($myMute == 0) { $myMute = "off"; } else { $myMute = "on";} if ($myMute == 0) { $myMute = "off"; } else { $myMute = "on";}
Log GetLogLevel($name, 4), "VIERA: GetStatus-Set reading mute to $myMute"; Log3 $name, 4, "VIERA: GetStatus-Set reading mute to $myMute";
if( $myMute ne ReadingsVal($name, "mute", "0") ) {readingsBulkUpdate($hash, "mute", $myMute);} if( $myMute ne ReadingsVal($name, "mute", "0") ) {readingsBulkUpdate($hash, "mute", $myMute);}
} }
if( ReadingsVal($name,"state","absent") ne "on") { if( ReadingsVal($name,"state","absent") ne "on") {
@ -338,7 +348,7 @@ sub VIERA_GetStatus($;$){
} }
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
#Log GetLogLevel($name,4), "VIERA $name: $hash->{STATE}"; #Log3 $name, 4, "VIERA $name: $hash->{STATE}";
return $hash->{STATE}; return $hash->{STATE};
} }
@ -354,7 +364,7 @@ sub VIERA_connection($$){
Timeout => 2 Timeout => 2
); );
#Log 5, "VIERA: connection message: $tmp"; #Log3 $name, 5, "VIERA: connection message: $tmp";
if(defined ($sock)){ if(defined ($sock)){
print $sock $tmp; print $sock $tmp;
@ -365,13 +375,13 @@ sub VIERA_connection($$){
} }
my @tmp2 = split (/\n/,$buffer); my @tmp2 = split (/\n/,$buffer);
#Log 4, "VIERA: $TV response: $tmp2[0]"; #Log3 $name, 4, "VIERA: $TV response: $tmp2[0]";
#Log 5, "VIERA: $TV buffer response: $buffer"; #Log3 $name, 5, "VIERA: $TV buffer response: $buffer";
$sock->close(); $sock->close();
return $buffer; return $buffer;
} }
else{ else{
#Log 4, "VIERA: $TV: not able to open socket"; #Log3 $name, 4, "VIERA: $TV: not able to open socket";
return undef; return undef;
} }
} }
@ -383,7 +393,7 @@ sub VIERA_RCmakenotify($$) {
my $nname="notify_$nam"; my $nname="notify_$nam";
fhem("define $nname notify $nam set $ndev remoteControl ".'$EVENT',1); fhem("define $nname notify $nam set $ndev remoteControl ".'$EVENT',1);
Log 2, "[remotecontrol:VIERA] Notify created: $nname"; Log3 undef, 2, "[remotecontrol:VIERA] Notify created: $nname";
return "Notify created by VIERA: $nname"; return "Notify created by VIERA: $nname";
} }
@ -426,7 +436,6 @@ sub VIERA_BuildXML_NetCtrl($$){
my $head = ""; my $head = "";
my $size = ""; my $size = "";
#Log 1, "DEBUG: $command, $host";
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; $callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"; $callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
$callsoap .= "<s:Body>"; $callsoap .= "<s:Body>";
@ -447,6 +456,7 @@ sub VIERA_BuildXML_NetCtrl($$){
$message .= $head; $message .= $head;
$message .= $callsoap; $message .= $callsoap;
Log3 $hash, 5, "VIERA: Building XML SOAP (NetworkControl) for command $command to host $host:\n$message";
return $message; return $message;
} }
@ -459,7 +469,7 @@ sub VIERA_BuildXML_RendCtrl($$$$){
my $head = ""; my $head = "";
my $size = ""; my $size = "";
#Log 1, "DEBUG: $command with $value to $host"; Log3 $hash, 5, "DEBUG: $command with $value to $host";
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; $callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n"; $callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
@ -483,6 +493,7 @@ sub VIERA_BuildXML_RendCtrl($$$$){
$message .= $head; $message .= $head;
$message .= $callsoap; $message .= $callsoap;
Log3 $hash, 5, "VIERA: Building XML SOAP (RenderingControl) for command $command with value $value to host $host:\n$message";
return $message; return $message;
} }
1; 1;