mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-07 19:04:20 +00:00
more flexible input recognition
git-svn-id: https://svn.fhem.de/fhem/trunk@2061 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
9da28d3748
commit
f3dbc0e270
@ -136,12 +136,17 @@ YAMAHA_AVR_Set($@)
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $address = $hash->{ADDRESS};
|
my $address = $hash->{ADDRESS};
|
||||||
my $result = "";
|
my $result = "";
|
||||||
my $inputs_piped = $hash->{INPUTS};
|
my $command;
|
||||||
|
my $inputs_piped = InputParamToFhemInput(lc($hash->{INPUTS}), 0);
|
||||||
|
my $inputs_comma = InputParamToFhemInput(lc($hash->{INPUTS}), 1);
|
||||||
|
|
||||||
return "No Argument given" if(!defined($a[1]));
|
return "No Argument given" if(!defined($a[1]));
|
||||||
|
Log 2, "inputs_piped: $inputs_piped";
|
||||||
|
Log 2, "inputs_comma: $inputs_comma";
|
||||||
|
|
||||||
|
|
||||||
my $what = $a[1];
|
my $what = $a[1];
|
||||||
my $usage = "Unknown argument $what, choose one of on off volume:slider,-80,1,16 input:".$hash->{INPUTS}." mute:on,off statusRequest";
|
my $usage = "Unknown argument $what, choose one of on off volume:slider,-80,1,16 input:".$inputs_comma." mute:on,off statusRequest";
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
if($what eq "on")
|
if($what eq "on")
|
||||||
@ -169,17 +174,14 @@ YAMAHA_AVR_Set($@)
|
|||||||
|
|
||||||
if($a[2] =~ /^($inputs_piped)$/)
|
if($a[2] =~ /^($inputs_piped)$/)
|
||||||
{
|
{
|
||||||
if($a[2] eq "netradio")
|
$command = getCommandParam($hash, $a[2]);
|
||||||
|
if(defined($command) and length($command) > 0)
|
||||||
{
|
{
|
||||||
$result = SendCommand($address,"<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>NET RADIO</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
|
$result = SendCommand($address,"<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>".$command."</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
|
||||||
}
|
|
||||||
elsif($a[2] eq "airplay")
|
|
||||||
{
|
|
||||||
$result = SendCommand($address,"<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>AirPlay</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$result = SendCommand($address,"<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>".uc($a[2])."</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
|
return "invalid input: ".$a[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(not $result =~ /RC="0"/)
|
if(not $result =~ /RC="0"/)
|
||||||
@ -325,20 +327,15 @@ YAMAHA_AVR_Define($$)
|
|||||||
|
|
||||||
foreach (sort @inputs)
|
foreach (sort @inputs)
|
||||||
{
|
{
|
||||||
if($_ =~ /<Param>(.+?)<\/Param>/ and not $1 =~ /iPod/)
|
if($_ =~ /<Param>(.+?)<\/Param>/)
|
||||||
{
|
{
|
||||||
if(defined($hash->{INPUTS}) and length($hash->{INPUTS}) > 0)
|
if(defined($hash->{INPUTS}) and length($hash->{INPUTS}) > 0)
|
||||||
{
|
{
|
||||||
$hash->{INPUTS} .= ",";
|
$hash->{INPUTS} .= "|";
|
||||||
}
|
|
||||||
if($1 eq "NET RADIO")
|
|
||||||
{
|
|
||||||
$hash->{INPUTS} .= "netradio";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$hash->{INPUTS} .= lc($1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hash->{INPUTS} .= $1;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,4 +374,43 @@ YAMAHA_AVR_Undefine($$)
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#############################
|
||||||
|
# Converts all Inputs to FHEM usable command lists
|
||||||
|
sub InputParamToFhemInput($$)
|
||||||
|
{
|
||||||
|
my ($inputs, $replace_pipes) = @_;
|
||||||
|
|
||||||
|
|
||||||
|
$inputs =~ s/\s+//g;
|
||||||
|
$inputs =~ s/,//g;
|
||||||
|
$inputs =~ s/\(.+?\)//g;
|
||||||
|
$inputs =~ s/\|/,/g if($replace_pipes == 1);
|
||||||
|
|
||||||
|
return $inputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
#############################
|
||||||
|
# Returns the Yamaha Parameter Name for the FHEM like input channel
|
||||||
|
sub getCommandParam($$)
|
||||||
|
{
|
||||||
|
my ($hash, $command) = @_;
|
||||||
|
my $item;
|
||||||
|
my @commands = split("\\|", $hash->{INPUTS});
|
||||||
|
|
||||||
|
foreach $item (@commands)
|
||||||
|
{
|
||||||
|
if(lc(InputParamToFhemInput($item, 0)) eq $command)
|
||||||
|
{
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user