2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

Changed several commands and readings according to DevelopmentGuidelinesAV

git-svn-id: https://svn.fhem.de/fhem/trunk@3717 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
teevau 2013-08-16 14:37:07 +00:00
parent b66758f71a
commit dff76274ec
2 changed files with 167 additions and 85 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII
- SVN
- change: VIERA: changed several readings/commands according to
DevelopmentGuidelinesAV. See FHEM Wiki and commandref for more details.
- change: YAMAHA_AVR: changed several readings/commands and introduced new
volume handling. please see the commandref for more details
- change: weblink fileplot/dbplot converted to SVG device (+FHEMWEB cleanup)

View File

@ -8,9 +8,12 @@
# written 2013 by Tobias Vaupel <fhem at 622 mbit dot de>
#
#
# Version = 1.11
# Version = 1.20
#
# Version History:
# - 1.20 - 2013-08-16
# -- added support according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV
#
# - 1.11 - 2013-08-13
# -- added "noArg" at get/set-command
# -- changed format of return() in VIERA_Get() for get-command dropdown menu in FHEMWEB
@ -24,24 +27,13 @@
# -- First release
#
##############################################################################
#
# define <name> VIERA <host>
#
# set <name> <key> <value>
#
# where <key> is one of mute, volume, remoteControl or off
# examples:
# set <name> mute on < This will switch mute on
# set <name> volume 20 < This will set volume level to 20, mute will be set to off if enabled
# set <name> remoteControl mute < This is equal to push the mute button at remote control. State of muting will be toggeled!
# set <name> remoteControl ? < Print an overview of remotecontrol buttons
#
##############################################################################
package main;
use strict;
use warnings;
use IO::Socket::INET;
use feature qw/say switch/;
use Time::HiRes qw(gettimeofday sleep);
#########################
# Forward declaration for remotecontrol module
@ -151,72 +143,127 @@ sub VIERA_Set($@){
my $name = $hash->{NAME};
my $host = $hash->{helper}{HOST};
my $count = @a;
my $ret = "";
my $key = "";
my $tab = "";
my $usage = "choose one of off:noArg mute:on,off volume:slider,0,1,100 remoteControl:" . join(",", sort keys %VIERA_remoteControl_args);
my $usage = "choose one of off:noArg mute:on,off " .
"remoteControl:" . join(",", sort keys %VIERA_remoteControl_args) . " " .
"volume:slider,0,1,100 volumeUp:noArg volumeDown:noArg ".
"channel channelUp:noArg channelDown:noArg";
$usage =~ s/(NRC_|-ONOFF)//g;
my $what = lc($a[1]);
return "VIERA: Device is not present or reachable, power on or check ethernet connection" if(ReadingsVal($name,"presence","absent")ne "present" && $what ne "?");
return "VIERA: No argument given, $usage" if(!defined($a[1]));
my $what = $a[1];
my $state = lc($a[2]) if(defined($a[2]));
return "VIERA: No state given, $usage" if(!defined($a[2]) && $what ne "off");
my $state = $a[2];
if($what eq "mute"){
Log GetLogLevel($name, 3), "VIERA: Set mute $state";
if ($state eq "on") {$state = 1;} else {$state = 0;}
$ret = connection(VIERA_BuildXML_RendCtrl($hash, "Set", "Mute", $state), $host);
}
elsif($what eq "volume"){
if($state < 0 || $state > 100){
return "Range is too high! Use Value 0 till 100 for volume.";
given($what) {
when("mute"){
Log GetLogLevel($name, 3), "VIERA: Set mute $state";
if ($state eq "on") {$state = 1;} else {$state = 0;}
VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Set", "Mute", $state), $host);
break;
}
Log GetLogLevel($name, 3), "VIERA: Set volume $state";
$ret = connection(VIERA_BuildXML_RendCtrl($hash, "Set", "Volume", $state), $host);
}
elsif($what eq "remoteControl"){
if($state eq "?"){
$usage = "choose one of the states:\n";
foreach $key (sort keys %VIERA_remoteControl_args){
if(length($key) < 17){ $tab = "\t\t"; }else{ $tab = "\t"; }
$usage .= "$key $tab=> $VIERA_remoteControl_args{$key}\n";
when("volume"){
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";
VIERA_connection(VIERA_BuildXML_RendCtrl($hash, "Set", "Volume", $state), $host);
break;
}
when("volumeup"){
return "VIERA: Volume range is too high!" if(ReadingsVal($name, "volume", "0") > 100);
Log GetLogLevel($name, 3), "VIERA: Set volumeUp";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"VOLUP"), $host);
break;
}
when("volumedown"){
return "VIERA: Volume range is too low!" if(ReadingsVal($name, "volume", "0") < 1);
Log GetLogLevel($name, 3), "VIERA: Set volumeDown";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"VOLDOWN"), $host);
break;
}
when("channel"){
return "VIERA: Channel is too high or low!" if($state < 1 || $state > 9999);
Log GetLogLevel($name, 3), "VIERA: Set channel $state";
for(my $i = 0; $i <= length($state)-1; $i++) {
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"D" . substr($state, $i, 1)), $host);
sleep 0.1;
}
$usage =~ s/(NRC_|-ONOFF)//g;
return $usage;
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"ENTER"), $host);
break;
}
else{
$state = uc($state);
Log GetLogLevel($name, 3), "VIERA: Set remoteControl $state";
$ret = connection(VIERA_BuildXML_NetCtrl($hash,$state), $host);
when("channelup"){
Log GetLogLevel($name, 3), "VIERA: Set channelUp";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"CH_UP"), $host);
break;
}
when("channeldown"){
Log GetLogLevel($name, 3), "VIERA: Set channelDown";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"CH_DOWN"), $host);
break;
}
when("remoteControl"){
if($state eq "?"){
$usage = "choose one of the states:\n";
foreach $key (sort keys %VIERA_remoteControl_args){
if(length($key) < 17){ $tab = "\t\t"; }else{ $tab = "\t"; }
$usage .= "$key $tab=> $VIERA_remoteControl_args{$key}\n";
}
$usage =~ s/(NRC_|-ONOFF)//g;
return $usage;
}
else{
$state = uc($state);
Log GetLogLevel($name, 3), "VIERA: Set remoteControl $state";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,$state), $host);
}
break;
}
when("off"){
Log GetLogLevel($name, 3), "VIERA: Set off";
VIERA_connection(VIERA_BuildXML_NetCtrl($hash,"POWER"), $host);
break;
}
when("statusrequest"){
Log GetLogLevel($name, 3), "VIERA: Set statusRequest";
VIERA_GetStatus($hash);
break;
}
when("?"){
return "$usage";
break;
}
default{
Log GetLogLevel($name, 3), "VIERA: Unknown argument $what, $usage";
return "Unknown argument $what, $usage";
};
}
elsif($what eq "off"){
Log GetLogLevel($name, 3), "VIERA: Set off";
$ret = connection(VIERA_BuildXML_NetCtrl($hash,"POWER"), $host);
}
else{
Log GetLogLevel($name, 3), "VIERA: $usage";
return "Unknown argument $what, $usage";
}
return;
return undef;
}
sub VIERA_Get($@){
my ($hash, @a) = @_;
my $what;
my $usage = "choose one of mute:noArg volume:noArg";
my $usage = "choose one of mute:noArg volume:noArg power:noArg presence:noArg";
my $name = $hash->{NAME};
return "VIERA: No argument given, $usage" if(int(@a) != 2);
$what = $a[1];
$what = lc($a[1]);
if($what =~ /^(volume|mute)$/) {
if($what =~ /^(volume|mute|power|presence)$/) {
if (defined($hash->{READINGS}{$what})) {
return $hash->{READINGS}{$what}{VAL};
ReadingsVal($name, $what, "undefined");
}
else{
return "no such reading: $what";
@ -244,45 +291,58 @@ sub VIERA_GetStatus($;$){
return "" if(!defined($hash->{helper}{HOST}) or !defined($hash->{helper}{INTERVAL}));
my $returnVol = 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));
if(not defined($returnVol) or $returnVol eq "") {
Log GetLogLevel($name, 4), "VIERA: GetStatusVol-Request NO SOCKET!";
#readingsSingleUpdate($hash,"state","off",1);
if( $hash->{STATE} ne "off") {readingsSingleUpdate($hash,"state","off",1);}
if( ReadingsVal($name,"state","absent") ne "absent") {
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "state", "absent");
readingsBulkUpdate($hash, "power", "off");
readingsBulkUpdate($hash, "presence", "absent");
readingsEndUpdate($hash, 1);
}
return;
}
my $returnMute = 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));
if(not defined($returnMute) or $returnMute eq "") {
Log GetLogLevel($name, 4), "VIERA: GetStatusMute-Request NO SOCKET!";
#readingsSingleUpdate($hash,"state","off",1);
if( $hash->{STATE} ne "off") {readingsSingleUpdate($hash,"state","off",1);}
if( ReadingsVal($name,"state","absent") ne "absent") {
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "state", "absent");
readingsBulkUpdate($hash, "power", "off");
readingsBulkUpdate($hash, "presence", "absent");
readingsEndUpdate($hash, 1);
}
return;
}
readingsBeginUpdate($hash);
if($returnVol =~ /<CurrentVolume>(.+)<\/CurrentVolume>/){
Log GetLogLevel($name, 4), "VIERA: GetStatus-Set reading volume to $1";
if( $1 != $hash->{READINGS}{volume}{VAL} ) {readingsBulkUpdate($hash, "volume", $1);}
if( $1 != ReadingsVal($name, "volume", "0") ) {readingsBulkUpdate($hash, "volume", $1);}
}
if($returnMute =~ /<CurrentMute>(.+)<\/CurrentMute>/){
my $myMute = $1;
if ($myMute == 0) { $myMute = "off"; } else { $myMute = "on";}
Log GetLogLevel($name, 4), "VIERA: GetStatus-Set reading volume to $myMute";
if( $myMute ne $hash->{READINGS}{mute}{VAL} ) {readingsBulkUpdate($hash, "mute", $myMute);}
Log GetLogLevel($name, 4), "VIERA: GetStatus-Set reading mute to $myMute";
if( $myMute ne ReadingsVal($name, "mute", "0") ) {readingsBulkUpdate($hash, "mute", $myMute);}
}
if( ReadingsVal($name,"state","absent") ne "on") {
readingsBulkUpdate($hash, "state", "on");
readingsBulkUpdate($hash, "power", "on");
readingsBulkUpdate($hash, "presence", "present");
}
#readingsBulkUpdate($hash, "state", "on");
if( $hash->{STATE} ne "on") {readingsBulkUpdate($hash, "state", "on");}
readingsEndUpdate($hash, 1);
Log GetLogLevel($name,4), "VIERA $name: $hash->{STATE}";
#Log GetLogLevel($name,4), "VIERA $name: $hash->{STATE}";
return $hash->{STATE};
}
sub connection($$){
sub VIERA_connection($$){
my $tmp = shift ;
my $TV = shift;
my $buffer = "";
@ -461,12 +521,20 @@ sub VIERA_BuildXML_RendCtrl($$$$){
<code>set &lt;name&gt; &lt;command&gt; [&lt;value&gt;]</code>
<br><br>
Currently, the following commands are defined.
<ul><code>
off<br>
mute [on|off]<br>
volume &lt;value&gt;<br>
remoteControl &lt;command&gt;<br>
</code></ul>
<ul>
<code>
off<br>
mute [on|off]<br>
volume [0-100]<br>
volumeUp<br>
volumeDown<br>
channel [1-9999]<br>
channelUp<br>
channelDown<br>
statusRequest<br>
remoteControl &lt;command&gt;<br>
</code>
</ul>
</ul>
<ul>
<br>
@ -551,6 +619,8 @@ sub VIERA_BuildXML_RendCtrl($$$$){
<ul><code>
mute<br>
volume<br>
power<br>
presence<br>
</code></ul>
</ul>
@ -563,10 +633,11 @@ sub VIERA_BuildXML_RendCtrl($$$$){
<a name="VIERAevents"></a>
<b>Generated events:</b>
<ul>
<li>on</li>
<li>off</li>
<li>volume</li>
<li>mute</li>
<li>presence</li>
<li>power</li>
<li>state</li>
</ul>
</ul>
@ -609,8 +680,14 @@ sub VIERA_BuildXML_RendCtrl($$$$){
<ul><code>
off<br>
mute [on|off]<br>
volume &lt;Wert&gt;<br>
remoteControl &lt;Befehl&gt;<br>
volume [0-100]<br>
volumeUp<br>
volumeDown<br>
channel [1-9999]<br>
channelUp<br>
channelDown<br>
statusRequest<br>
remoteControl &lt;command&gt;<br>
</code></ul>
</ul>
<ul>
@ -694,8 +771,10 @@ sub VIERA_BuildXML_RendCtrl($$$$){
<br><br>
Die folgenden Befehle sind definiert und geben den entsprechenden Wert zur&uuml;ck, der vom Fernseher zur&uuml;ckgegeben wurde.
<ul><code>
mute<br>
volume<br>
mute<br>
volume<br>
power<br>
presence<br>
</code></ul>
</ul>
@ -708,10 +787,11 @@ sub VIERA_BuildXML_RendCtrl($$$$){
<a name="VIERAevents"></a>
<b>Generierte events:</b>
<ul>
<li>on</li>
<li>off</li>
<li>volume</li>
<li>mute</li>
<li>presence</li>
<li>power</li>
<li>state</li>
</ul>
</ul>