71_LISTENLIVE update

git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@3497 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen
2013-07-24 23:27:58 +00:00
parent 9ad1438a38
commit a674c5b658

View File

@@ -25,10 +25,24 @@
# #
############################################################################## ##############################################################################
# Changelog: # Changelog:
# 2013-07-21 Logging vereinheitlich #
# 2013-07-21
# Logging vereinheitlich
# Meldungen komplett auf englisch umgestellt # Meldungen komplett auf englisch umgestellt
# pod (EN) erstellt # pod (EN) erstellt
# #
# 2013-07-25
# Anbindung an remotecontrol
# Bereitstellung von Standardlayout und makenotify
# neue commandGroup rc für Zugriff von 95_remotecontrol
# Übersetzungstabelle für remoteCommands definiert
#
# Beginn Redesign des Command-Parsing
# neues Parsing für power erstellt
# neues Parsing für reset erstellt
# neues Parsing für cursor erstellt
# neues Parsing für audio erstellt
#
############################################################################## ##############################################################################
package main; package main;
@@ -83,17 +97,14 @@ sub
LISTENLIVE_Initialize($) LISTENLIVE_Initialize($)
{ {
my ($hash) = @_; my ($hash) = @_;
$hash->{GetFn} = "LISTENLIVE_Get"; $hash->{GetFn} = "LISTENLIVE_Get";
$hash->{SetFn} = "LISTENLIVE_Set"; $hash->{SetFn} = "LISTENLIVE_Set";
$hash->{DefFn} = "LISTENLIVE_Define"; $hash->{DefFn} = "LISTENLIVE_Define";
$hash->{UndefFn} = "LISTENLIVE_Undefine"; $hash->{UndefFn} = "LISTENLIVE_Undefine";
$hash->{AttrList} = "do_not_notify:0,1 loglevel:0,1,2,3,4,5 ". $hash->{AttrList} = "do_not_notify:0,1 loglevel:0,1,2,3,4,5 ".
$readingFnAttributes; $readingFnAttributes;
$data{RC_layout}{HMT350} = "HMT350_RClayout"; $data{RC_layout}{HMT350} = "HMT350_RClayout";
$data{RC_makenotify}{LISTENLIVE} = "HMT350_RCmakenotify"; $data{RC_makenotify}{LISTENLIVE}= "HMT350_RCmakenotify";
} }
################################### ###################################
@@ -106,453 +117,188 @@ LISTENLIVE_Set($@)
my $loglevel = GetLogLevel($name, 3); my $loglevel = GetLogLevel($name, 3);
my $result; my $result;
my $response; my $response;
my $command;
return "No Argument given!\n\n".LISTENLIVE_HelpSet() if(!defined($a[1])); return "No Argument given!\n\n".LISTENLIVE_HelpSet() if(!defined($a[1]));
my %powerGroup = (on => "POWER", off => "POWER");
my %muteGroup = (on => "MUTE", off => "MUTE");
my %cursorGroup = (left => "LEFT", right => "RIGHT", up => "UP", down => "DOWN",
home => "HOME", enter => "OK", ok => "OK", "exit" => "RETURN");
my %audioGroup = (mute => "MUTE", unmute => "MUTE", volp => "VOLp", volm => "VOLm");
my $pstat = $hash->{READINGS}{power}{VAL}; my $pstat = $hash->{READINGS}{power}{VAL};
my $mute = $hash->{READINGS}{mute}{VAL}; my $mute = $hash->{READINGS}{mute}{VAL};
# my @b = split(/\./, $a[1]); # my @b = split(/\./, $a[1]);
# my $area = $b[0]; # my $cmdGroup = $b[0];
# my $doit = $b[1]; # my $cmd = $b[1];
# if(!defined($doit) && defined($a[2])) { $doit = $a[2]; } # if(!defined($cmd) && defined($a[2])) { $cmd = $a[2]; }
my $area = $a[1]; my $cmdGroup = $a[1];
my $doit = $a[2]; my $cmd = $a[2];
my $usage = "Unknown argument, choose one of help statusRequest power:on,off audio:volp,volm,mute,unmute cursor:up,down,left,right,enter,exit,home,ok reset:power,mute,menupos app:weather raw user"; my $usage = "Unknown argument, choose one of help statusRequest power:on,off audio:volp,volm,mute,unmute cursor:up,down,left,right,enter,exit,home,ok reset:power,mute,menupos app:weather raw user";
given ($area){ given ($cmdGroup){
#
# commandGroup = rc
# verarbeitet Steuerbefehle aus 95_remotecontrol
#
when("rc"){ when("rc"){
$g = "raw"; $g = "raw";
$c = $HMT350_RCtranslate{$doit}; $c = $HMT350_RCtranslate{$cmd};
Log $loglevel, "LISTENLIVE $name rc_translate: >$area $doit< translated to: >$g $c<"; Log $loglevel, "LISTENLIVE $name rc_translate: >$cmdGroup $cmd< translated to: >$g $c<";
fhem("set $name $g $c"); fhem("set $name $g $c");
break; break;
} }
# #
# AREA = user <userDefFunction> # commandGroup = user <userDefFunction>
# ruft eine userdefinierte Funktion, z.B. aus 99_myUtils.pm auf # ruft eine userdefinierte Funktion, z.B. aus 99_myUtils.pm auf
# #
when("user"){ when("user"){
if(defined($doit)){
Log $loglevel, "LISTENLIVE $name input: $area $doit"; if(defined($cmd)){
$result = &{$doit}; Log $loglevel, "LISTENLIVE $name input: $cmdGroup $cmd";
$result = &{$cmd};
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit"); readingsBulkUpdate($hash, "lastCmd","$cmdGroup $cmd");
readingsBulkUpdate($hash, "lastResult",$result); readingsBulkUpdate($hash, "lastResult",$result);
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
} else {
return $usage;
} }
else
{ return $usage; }
break; break;
} # end user }
# #
# AREA = raw <command> # commandGroup = raw <command>
# sendet einfach das <command> per http an das Gerät # sendet einfach das <command> per http an das Gerät
# und schreibt die Rückmeldung in das Reading "rawresult"
# (hauptsächlich für Debugging vorgesehen)
# #
when("raw"){ when("raw"){
if(defined($doit)){
Log $loglevel, "LISTENLIVE $name input: $area $doit"; if(defined($cmd)){
$result = LISTENLIVE_SendCommand($hash, $doit); Log $loglevel, "LISTENLIVE $name input: $cmdGroup $cmd";
$result = LISTENLIVE_SendCommand($hash, $cmd);
if($result =~ m/OK/){ if($result =~ m/OK/){
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit"); readingsBulkUpdate($hash, "lastCmd","$cmdGroup $cmd");
readingsBulkUpdate($hash, "lastResult",$result); readingsBulkUpdate($hash, "lastResult",$result);
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
} else {
LISTENLIVE_rbuError($hash, $cmdGroup, $cmd);
} }
else } else {
{ return $usage;
LISTENLIVE_rbuError($hash, $area, $doit);
} }
}
else
{ return $usage; }
break; break;
} # end raw }
# #
# AREA = reset <power>|<mute>|<menupos> # commandGroup = reset <power>|<mute>
# sendet gnadenlos ein POWER oder MUTE oder setzt # setzt den Status von power und mute auf unbekannt,
# die MENUPOS auf 11 (oben links), damit man eine Chance hat, # der nächste Befehl setzt den Status dann neu
# den Gerätestatus zu synchronisieren
# #
when("reset"){ when("reset"){
given($doit){
when("power"){ Log $loglevel, "LISTENLIVE $name input: $cmdGroup $cmd";
Log $loglevel, "LISTENLIVE $name input: $area $doit";
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit"); readingsBulkUpdate($hash, "lastCmd","$cmdGroup $cmd");
readingsBulkUpdate($hash, "lastResult","OK"); readingsBulkUpdate($hash, "lastResult","OK");
readingsBulkUpdate($hash, "power","???"); readingsBulkUpdate($hash, $cmd,"???");
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
break; break;
} # end reset.power
when("mute"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit");
readingsBulkUpdate($hash, "lastResult","OK");
readingsBulkUpdate($hash, "mute","???");
readingsEndUpdate($hash, 1);
break;
} # end reset.mute
when("menupos"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "HOME");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit");
readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "menuPos","11");
readingsEndUpdate($hash, 1);
} }
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
break;
} # end reset.menupos
default:
{ return $usage; }
} # end doit
} # end area.reset
# #
# AREA power <on>|<off> # commandGroup power <on>|<off>
# Es wird vor dem Senden geprüft, ob der Befehl Sinn macht, # Es wird vor dem Senden geprüft, ob der Befehl Sinn macht
# da der gleiche Befehl für das Ein- und Ausschalten
# verwendet wird.
# Ein "power on" wird bei einem eingeschalteten Gerät nicht gesendet
# Ein "power off" wird bei einem ausgeschalteten Gerät nicht gesendet
# Als Basis für die Entscheidung dient das Reading power
# #
when("power"){ when("power"){
given ($doit){
when("on") {
if($pstat ne "on"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "POWER");
if($result =~ m/OK/)
{
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit");
readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "power","on");
readingsEndUpdate($hash, 1);
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit, " => device already on!");
}
break;
} # end power.on
when("off") { Log $loglevel, "LISTENLIVE $name input: $cmdGroup $cmd";
if($pstat ne "off") if($pstat ne $cmd) {
{ $xCmd = $powerGroup{$cmd};
Log $loglevel, "LISTENLIVE $name input: $area $doit"; $result = LISTENLIVE_SendCommand($hash, $xCmd);
$result = LISTENLIVE_SendCommand($hash, "POWER");
if($result =~ m/OK/){ if($result =~ m/OK/){
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit"); readingsBulkUpdate($hash, "lastCmd","$cmdGroup $cmd");
readingsBulkUpdate($hash, "lastResult",$result); readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "power","off"); readingsBulkUpdate($hash, "power",$cmd);
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
} else {
LISTENLIVE_rbuError($hash, $cmdGroup, $cmd);
} }
else } else {
{ LISTENLIVE_rbuError($hash, $cmdGroup, $cmd, " => device already $cmd!");
LISTENLIVE_rbuError($hash, $area, $doit);
}
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit, " => device already off!");
} }
break; break;
} # end power.off }
default:
{ return $usage; }
} # end power.doit
} # end area.power
# #
# AREA audio <mute>|<unmute>|<volp>|<volm> # commandGroup audio <mute>|<unmute>|<volp>|<volm>
# #
when("audio"){ when("audio"){
given($doit){
when("mute"){ Log $loglevel, "LISTENLIVE $name input: $cmdGroup $cmd";
if($mute ne "on"){ if($mute ne $cmd) {
Log $loglevel, "LISTENLIVE $name input: $area $doit"; $xCmd = $audioGroup{$cmd};
$result = LISTENLIVE_SendCommand($hash, "MUTE"); $result = LISTENLIVE_SendCommand($hash, $xCmd);
if($result =~ m/OK/){ if($result =~ m/OK/){
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit"); readingsBulkUpdate($hash, "lastCmd","$cmdGroup $cmd");
readingsBulkUpdate($hash, "lastResult",$result); readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "mute","on"); #
# ToDo: set mute state
#
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
} else {
LISTENLIVE_rbuError($hash, $cmdGroup, $cmd);
} }
else } else {
{ LISTENLIVE_rbuError($hash, $cmdGroup, $cmd, " => no action required!");
LISTENLIVE_rbuError($hash, $area, $doit);
}
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit, "Already muted!");
} }
break; break;
} # end mute
when("unmute"){
if($mute ne "off"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "MUTE");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "mute","off");
readingsEndUpdate($hash, 1);
} }
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit, "Already unmuted!");
}
break;
} # end unmute
when("volp"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "VOLp");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit");
readingsBulkUpdate($hash, "lastResult",$result);
readingsEndUpdate($hash, 1);
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
break;
} # end volp
when("volm"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "VOLm");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit");
readingsBulkUpdate($hash, "lastResult",$result);
readingsEndUpdate($hash, 1);
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
break;
} # end volm
default:
{ return $usage; }
} # end audio.doit
} # end area.audio
# #
# AREA cursor <up>|<down>|<left>|<right>|home|<enter>|<ok>|<exit> # commandGroup cursor <up>|<down>|<left>|<right>|home|<enter>|<ok>|<exit>
# #
when("cursor"){ when("cursor"){
given($doit){
when("up"){ Log $loglevel, "LISTENLIVE: $name input: $cmdGroup $cmd";
Log $loglevel, "LISTENLIVE $name $area $doit"; $xCmd = $cursorGroup{$cmd};
$result = LISTENLIVE_SendCommand($hash, "UP"); $result = LISTENLIVE_SendCommand($hash, $xCmd);
if($result =~ m/OK/){ if($result =~ m/OK/){
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]); readingsBulkUpdate($hash, "lastCmd","$cmdGroup $cmd");
readingsBulkUpdate($hash, "lastResult",$result); readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "menuPos",$hash->{READINGS}{menuPos}{VAL}-10);
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
return undef; } else {
} LISTENLIVE_rbuError($hash, $cmdGroup, $cmd);
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
} }
break; break;
} # end up
when("down"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "DOWN");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "menuPos",$hash->{READINGS}{menuPos}{VAL}+10);
readingsEndUpdate($hash, 1);
return undef;
} }
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
break;
} # end down
when("left"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "LEFT");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "menuPos",$hash->{READINGS}{menuPos}{VAL}-1);
readingsEndUpdate($hash, 1);
return undef;
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
break;
} # end left
when("right"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "RIGHT");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "menuPos",$hash->{READINGS}{menuPos}{VAL}+1);
readingsEndUpdate($hash, 1);
return undef;
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
break;
} # end right
when("home"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "HOME");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult",$result);
readingsBulkUpdate($hash, "menuPos","11");
readingsEndUpdate($hash, 1);
return undef;
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit)
}
break;
} # end home
when("enter"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "OK");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult",$result);
readingsEndUpdate($hash, 1);
return undef;
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
break;
} # end enter
when("ok"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "OK");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult",$result);
readingsEndUpdate($hash, 1);
return undef;
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
break;
} # end ok
when("exit"){
Log $loglevel, "LISTENLIVE $name input: $area $doit";
$result = LISTENLIVE_SendCommand($hash, "EXIT");
if($result =~ m/OK/){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult",$result);
readingsEndUpdate($hash, 1);
return undef;
}
else
{
LISTENLIVE_rbuError($hash, $area, $doit);
}
} # end cursor.exit
default:
{ return $usage; }
} # end cursor.doit
} # end area.cursor
# #
# AREA app # AREA app
# #
when ("app"){ when ("app"){
given($doit){
given($cmd){
when("weather"){ when("weather"){
Log $loglevel, "LISTENLIVE $name input: $area $doit"; Log $loglevel, "LISTENLIVE $name input: $cmdGroup $cmd";
$result = LISTENLIVE_SendCommand($hash, "HOME"); $result = LISTENLIVE_SendCommand($hash, "HOME");
select(undef, undef, undef, 0.2); select(undef, undef, undef, 0.2);
$result = LISTENLIVE_SendCommand($hash, "DOWN"); $result = LISTENLIVE_SendCommand($hash, "DOWN");
@@ -566,33 +312,25 @@ LISTENLIVE_Set($@)
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd",$a[1]); readingsBulkUpdate($hash, "lastCmd",$a[1]);
readingsBulkUpdate($hash, "lastResult","done"); readingsBulkUpdate($hash, "lastResult","done");
readingsBulkUpdate($hash, "menuPos", "32");
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
} # end doit.weather } # end doit.weather
default: default:
{ return $usage; } { return $usage; }
}
} # end doit }
} # end area.app
when("statusRequest") { break; } # wird automatisch aufgerufen! when("statusRequest") { break; } # wird automatisch aufgerufen!
when("?") { return $usage; }
when("help") { return LISTENLIVE_HelpSet(); }
when("present") { break; } when("present") { break; }
when("absent") { break; } when("absent") { break; }
when("online") { break; } when("online") { break; }
when("offline") { break; } when("offline") { break; }
when("help") { return LISTENLIVE_HelpSet(); }
when("?") { return $usage; }
default: { return $usage; } default: { return $usage; }
} # end area }
# Call the GetStatus() Function to retrieve the new values
LISTENLIVE_GetStatus($hash, 1); LISTENLIVE_GetStatus($hash, 1);
return $response; return $response;
@@ -608,44 +346,20 @@ LISTENLIVE_Get($@){
return "No Argument given" if(!defined($a[1])); return "No Argument given" if(!defined($a[1]));
my @b = split(/\./, $a[1]); my $cmdGroup = $a[1];
my $area = $b[0]; my $cmd = $a[2];
my $doit = $b[1];
my $usage = "Unknown argument $a[1], choose one of help list:commands";
given($area){
when("list"){
given("$doit"){
when("commands"){
$response = LISTENLIVE_HelpGet();
break;
}
default: { return $usage; }
} # end area.list.doit
} # end area.list
given($cmdGroup){
when("?") { return $usage; } when("?") { return $usage; }
when("help") { $response = LISTENLIVE_HelpGet(); }
when("help"){ $response = LISTENLIVE_HelpGet(); }
default: { return $usage; } default: { return $usage; }
}
} # end area return $response;
return $response;
} }
################################### ###################################
sub sub
LISTENLIVE_GetStatus($;$){ LISTENLIVE_GetStatus($;$){
my ($hash, $local) = @_; my ($hash, $local) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $presence; my $presence;
@@ -669,19 +383,16 @@ LISTENLIVE_GetStatus($;$){
InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "LISTENLIVE_GetStatus", $hash, 0) unless($local == 1); InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "LISTENLIVE_GetStatus", $hash, 0) unless($local == 1);
return $hash->{STATE}; return $hash->{STATE};
} }
############################# #############################
sub sub
LISTENLIVE_Define($$) LISTENLIVE_Define($$){
{
my ($hash, $def) = @_; my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def); my @a = split("[ \t][ \t]*", $def);
my $name = $hash->{NAME}; my $name = $hash->{NAME};
if(! @a >= 4) if(! @a >= 4){
{
my $msg = "wrong syntax: define <name> LISTENLIVE <ip-or-hostname>[:<port>] [<interval>]"; my $msg = "wrong syntax: define <name> LISTENLIVE <ip-or-hostname>[:<port>] [<interval>]";
Log 2, $msg; Log 2, $msg;
return $msg; return $msg;
@@ -703,31 +414,23 @@ LISTENLIVE_Define($$)
$interval = "60" unless(defined($interval)); $interval = "60" unless(defined($interval));
$hash->{helper}{INTERVAL} = $interval; $hash->{helper}{INTERVAL} = $interval;
if($address[0] ne "none") if($address[0] ne "none"){
{
# PRESENCE aus device pres_+NAME lesen # PRESENCE aus device pres_+NAME lesen
my $presence = ReadingsVal("pres_".$name,"state","noPresence"); my $presence = ReadingsVal("pres_".$name,"state","noPresence");
if($presence eq "noPresence") # PRESENCE nicht vorhanden if($presence eq "noPresence"){
{
$cmd = "pres_$name PRESENCE lan-ping $address[0]"; $cmd = "pres_$name PRESENCE lan-ping $address[0]";
$ret = CommandDefine(undef, $cmd); $ret = CommandDefine(undef, $cmd);
if($ret) if($ret){
{
Log 2, "LISTENLIVE ERROR $ret"; Log 2, "LISTENLIVE ERROR $ret";
} } else {
else
{
Log 3, "LISTENLIVE $name PRESENCE pres_$name created."; Log 3, "LISTENLIVE $name PRESENCE pres_$name created.";
} }
} } else {
else
{
Log 3, "LISTENLIVE $name PRESENCE pres_$name found."; Log 3, "LISTENLIVE $name PRESENCE pres_$name found.";
} }
} } else {
else # Gerät ist als dummy definiert # Gerät ist als dummy definiert
{
$presence = "present"; # dummy immer als online melden $presence = "present"; # dummy immer als online melden
} }
@@ -735,24 +438,26 @@ LISTENLIVE_Define($$)
# Readings anlegen und füllen # Readings anlegen und füllen
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
# readingsBulkUpdate($hash, "currentMedia","");
readingsBulkUpdate($hash, "lastCmd",""); readingsBulkUpdate($hash, "lastCmd","");
readingsBulkUpdate($hash, "lastResult",""); readingsBulkUpdate($hash, "lastResult","");
readingsBulkUpdate($hash, "menuPos","11"); # readingsBulkUpdate($hash, "menuPos","11");
readingsBulkUpdate($hash, "mute","???"); readingsBulkUpdate($hash, "mute","???");
# readingsBulkUpdate($hash, "playStatus","");
readingsBulkUpdate($hash, "power","???"); readingsBulkUpdate($hash, "power","???");
# readingsBulkUpdate($hash, "presence",$presence);
readingsBulkUpdate($hash, "state",$presence); readingsBulkUpdate($hash, "state",$presence);
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
$hash->{helper}{AVAILABLE} = 1; $hash->{helper}{AVAILABLE} = 1;
InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "LISTENLIVE_GetStatus", $hash, 0); InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "LISTENLIVE_GetStatus", $hash, 0);
return; return;
} }
############################# #############################
sub sub
LISTENLIVE_SendCommand($$;$) LISTENLIVE_SendCommand($$;$){
{
my ($hash, $command, $loglevel) = @_; my ($hash, $command, $loglevel) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $address = $hash->{helper}{ADDRESS}; my $address = $hash->{helper}{ADDRESS};
@@ -767,81 +472,47 @@ LISTENLIVE_SendCommand($$;$)
if (Value("$name") eq "online" && $hash->{helper}{ADDRESS} ne "none") { $modus = "online"; } if (Value("$name") eq "online" && $hash->{helper}{ADDRESS} ne "none") { $modus = "online"; }
if (Value("$name") eq "offline") { $modus = "offline"; } if (Value("$name") eq "offline") { $modus = "offline"; }
given($modus) given($modus) {
{ when("online") {
when("online")
{
#
# Create a socket object for the communication with the radio
#
$socket = new IO::Socket::INET ( $socket = new IO::Socket::INET (
PeerHost => $address, PeerHost => $address,
PeerPort => $port, PeerPort => $port,
Proto => 'tcp', Proto => 'tcp',
) or die "ERROR in Socket Creation : $!\n"; ) or die "ERROR in Socket Creation : $!\n";
#
# Send the given command into the socket
#
$socket->send($command); $socket->send($command);
#
# get the radio some time to execute the command (300ms )
#
usleep(30000); usleep(30000);
#
# get the answer of the radio
#
$socket->recv($response, 2); $socket->recv($response, 2);
if($response !~ m/OK/) { Log 2, "LISTENLIVE $name error: $response"; }
else { Log $loglevel, "LISTENLIVE $name response: $response"; }
if($response !~ m/OK/)
{
Log 2, "LISTENLIVE $name error: $response";
}
else
{
Log $loglevel, "LISTENLIVE $name response: $response";
}
$socket->close(); $socket->close();
$hash->{helper}{AVAILABLE} = (defined($response) ? 1 : 0); $hash->{helper}{AVAILABLE} = (defined($response) ? 1 : 0);
} }
when("offline") when("offline") {
{
Log 2, "LISTENLIVE $name error: device offline!"; Log 2, "LISTENLIVE $name error: device offline!";
$response = "device offline!"; $response = "device offline!";
} }
default: default:
{ { $response = "OK"; }
$response = "OK";
} }
}
return $response; return $response;
} }
sub sub
LISTENLIVE_rbuError($$;$$) LISTENLIVE_rbuError($$;$$){
{ my ($hash, $cmdGroup, $cmd, $parameter) = @_;
my ($hash, $area, $doit, $parameter) = @_; Log 2, "LISTENLIVE $hash->{NAME} error: $cmdGroup $cmd $parameter";
Log 2, "LISTENLIVE $hash->{NAME} error: $area $doit $parameter";
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "lastCmd","$area $doit $parameter"); readingsBulkUpdate($hash, "lastCmd","$cmdGroup $cmd $parameter");
readingsBulkUpdate($hash, "lastResult","Error: $area $doit $parameter"); readingsBulkUpdate($hash, "lastResult","Error: $cmdGroup $cmd $parameter");
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
return undef; return undef;
} }
sub sub
LISTENLIVE_HelpGet() LISTENLIVE_HelpGet(){
{
my $helptext = my $helptext =
'get <device> <commandGroup> [<command>] 'get <device> <commandGroup> [<command>]
@@ -853,8 +524,7 @@ return $helptext;
} }
sub sub
LISTENLIVE_HelpSet() LISTENLIVE_HelpSet(){
{
my $helptext = my $helptext =
'set <device> <commandGroup> [<command>] 'set <device> <commandGroup> [<command>]
@@ -875,7 +545,6 @@ set llradio cursor down
set llradio cursor left set llradio cursor left
set llradio cursor up set llradio cursor up
set llradio cursor right set llradio cursor right
set llradio cursor enter set llradio cursor enter
set llradio cursor exit set llradio cursor exit
set llradio cursor home set llradio cursor home
@@ -892,7 +561,6 @@ set llradio raw <command>
commandGroup "reset" commandGroup "reset"
set llradio reset menupos
set llradio reset mute set llradio reset mute
set llradio reset power set llradio reset power
@@ -913,11 +581,8 @@ return $helptext;
############################# #############################
sub sub
LISTENLIVE_Undefine($$) LISTENLIVE_Undefine($$){
{
my($hash, $name) = @_; my($hash, $name) = @_;
# Stop the internal GetStatus-Loop and exist
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
return undef; return undef;
} }
@@ -927,19 +592,10 @@ sub HMT350_RCmakenotify($$) {
my $loglevel = GetLogLevel($name, 3) unless(defined($loglevel)); my $loglevel = GetLogLevel($name, 3) unless(defined($loglevel));
my ($nam, $ndev) = @_; my ($nam, $ndev) = @_;
my $nname="notify_$nam"; my $nname="notify_$nam";
my $cmd = "$nname notify $nam set $ndev rc \$EVENT"; my $cmd = "$nname notify $nam set $ndev rc \$EVENT";
my $ret = CommandDefine(undef, $cmd); my $ret = CommandDefine(undef, $cmd);
if($ret) { Log 2, "remotecontrol ERROR $ret"; }
if($ret) else { Log $loglevel, "remotecontrol HMT350: $nname created as notify"; }
{
Log 2, "remotecontrol ERROR $ret";
}
else
{
Log $loglevel, "remotecontrol HMT350: $nname created as notify";
}
return "Notify created: $nname"; return "Notify created: $nname";
} }
@@ -954,15 +610,14 @@ sub HMT350_RClayout() {
$row[$rownum]="rewind:REWIND,left:LEFT,ok:OK,right:RIGHT,forward:FF"; $rownum++; $row[$rownum]="rewind:REWIND,left:LEFT,ok:OK,right:RIGHT,forward:FF"; $rownum++;
$row[$rownum]=":blank,:blank,down:DOWN,:blank,:blank"; $rownum++; $row[$rownum]=":blank,:blank,down:DOWN,:blank,:blank"; $rownum++;
$row[$rownum]="ret:RETURN,:blank,volmin:VOLDOWN,:blank,stop:STOP"; $rownum++; $row[$rownum]="ret:RETURN,:blank,volmin:VOLDOWN,:blank,stop:STOP"; $rownum++;
$row[$rownum]=":blank,:blank,:blank,:blank,:blank"; $rownum++; $row[$rownum]=":blank,:blank,:blank,:blank,:blank"; $rownum++;
$row[$rownum]="raw+PGUP:PAGEUP,:blank,raw+PAUSE:PAUSE,:blank,raw+ITV:ITV"; $rownum++; $row[$rownum]="raw+PGUP:PAGEUP,:blank,raw+PAUSE:PAUSE,:blank,raw+ITV:ITV"; $rownum++;
$row[$rownum]="raw+PGDN:PAGEDOWN,:blank,raw+MENU:MENU,:blank,raw+IRADIO:IRADIO"; $rownum++; $row[$rownum]="raw+PGDN:PAGEDOWN,:blank,raw+MENU:MENU,:blank,raw+IRADIO:IRADIO"; $rownum++;
$row[$rownum]=":FAV,:blank,raw+REPEAT:REPEAT,:blank,raw+FMRADIO:FMRADIO"; $rownum++; $row[$rownum]=":FAV,:blank,raw+REPEAT:REPEAT,:blank,raw+FMRADIO:FMRADIO"; $rownum++;
$row[19]="attr rc_iconpath icons/remotecontrol"; $row[19]="attr rc_iconpath icons/remotecontrol";
$row[20]="attr rc_iconprefix black_btn_"; $row[20]="attr rc_iconprefix black_btn_";
return @row; return @row;
} }