1
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-04 22:19:38 +00:00

71_ONKYO_AVR_ZONE.pm: fix input alias handling and add more flexible channel handling

git-svn-id: https://svn.fhem.de/fhem/trunk@12256 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2016-10-03 13:54:02 +00:00
parent 0083b2ece1
commit aa53a1776d

View File

@ -153,6 +153,26 @@ sub ONKYO_AVR_ZONE_Define($$$) {
&& AttrVal( $IOname, "group", "" ) ne "" ); && AttrVal( $IOname, "group", "" ) ne "" );
} }
# Input alias handling
#
if ( defined( $attr{$name}{inputs} ) ) {
my @inputs = split( ':', $attr{$name}{inputs} );
if (@inputs) {
foreach (@inputs) {
if (m/[^,\s]+(,[^,\s]+)+/) {
my @input_names = split( ',', $_ );
$input_names[1] =~ s/\s/_/g;
$hash->{helper}{receiver}{input_aliases}{ $input_names[0] }
= $input_names[1];
$hash->{helper}{receiver}{input_names}{ $input_names[1] } =
$input_names[0];
}
}
}
}
ONKYO_AVR_ZONE_SendCommand( $hash, "power", "query" ); ONKYO_AVR_ZONE_SendCommand( $hash, "power", "query" );
ONKYO_AVR_ZONE_SendCommand( $hash, "input", "query" ); ONKYO_AVR_ZONE_SendCommand( $hash, "input", "query" );
ONKYO_AVR_ZONE_SendCommand( $hash, "mute", "query" ); ONKYO_AVR_ZONE_SendCommand( $hash, "mute", "query" );
@ -236,12 +256,13 @@ sub ONKYO_AVR_ZONE_Parse($$) {
) )
{ {
Log3 $name, 4, Log3 $name, 4,
"ONKYO_AVR $name: Input aliasing '$value' to '" "ONKYO_AVR_AVR $name: Input aliasing '$value' to '"
. $hash->{helper}{receiver}{input_aliases}{$value} . $hash->{helper}{receiver}{input_aliases}{$value}
. "'"; . "'";
$value = $value =
$hash->{helper}{receiver}{input_aliases}{$value}; $hash->{helper}{receiver}{input_aliases}{$value};
} }
} }
# power # power
@ -503,10 +524,10 @@ sub ONKYO_AVR_ZONE_Set($$$) {
my @input_names = split( ',', $_ ); my @input_names = split( ',', $_ );
$inputs_txt .= $input_names[1] . ","; $inputs_txt .= $input_names[1] . ",";
$input_names[1] =~ s/\s/_/g; $input_names[1] =~ s/\s/_/g;
$IOhash->{helper}{receiver}{input_aliases} $hash->{helper}{receiver}{input_aliases}{ $input_names[0] }
{ $input_names[0] } = $input_names[1]; = $input_names[1];
$IOhash->{helper}{receiver}{input_names}{ $input_names[1] } $hash->{helper}{receiver}{input_names}{ $input_names[1] } =
= $input_names[0]; $input_names[0];
} }
else { else {
$inputs_txt .= $_ . ","; $inputs_txt .= $_ . ",";
@ -557,28 +578,28 @@ sub ONKYO_AVR_ZONE_Set($$$) {
} }
# list of network channels/services # list of network channels/services
if ( defined( $IOhash->{helper}{receiver} ) my $channels_src = "internal";
&& ref( $IOhash->{helper}{receiver} ) eq "HASH" if ( defined( $hash->{helper}{receiver} )
&& defined( $IOhash->{helper}{receiver}{device}{netservicelist}{count} ) && ref( $hash->{helper}{receiver} ) eq "HASH"
&& $IOhash->{helper}{receiver}{device}{netservicelist}{count} > 0 ) && defined( $hash->{helper}{receiver}{device}{netservicelist}{count} )
&& $hash->{helper}{receiver}{device}{netservicelist}{count} > 0 )
{ {
foreach my $id ( foreach my $id (
sort keys sort keys
%{ $IOhash->{helper}{receiver}{device}{netservicelist}{netservice} } %{ $hash->{helper}{receiver}{device}{netservicelist}{netservice} } )
)
{ {
if ( if (
defined( defined(
$IOhash->{helper}{receiver}{device}{netservicelist} $hash->{helper}{receiver}{device}{netservicelist}
{netservice}{$id}{value} {netservice}{$id}{value}
) )
&& $IOhash->{helper}{receiver}{device}{netservicelist} && $hash->{helper}{receiver}{device}{netservicelist}
{netservice}{$id}{value} eq "1" {netservice}{$id}{value} eq "1"
) )
{ {
$channels_txt .= $channels_txt .=
trim( $IOhash->{helper}{receiver}{device}{netservicelist} trim( $hash->{helper}{receiver}{device}{netservicelist}
{netservice}{$id}{name} ) {netservice}{$id}{name} )
. ","; . ",";
} }
@ -586,6 +607,21 @@ sub ONKYO_AVR_ZONE_Set($$$) {
$channels_txt =~ s/\s/_/g; $channels_txt =~ s/\s/_/g;
$channels_txt = substr( $channels_txt, 0, -1 ); $channels_txt = substr( $channels_txt, 0, -1 );
$channels_src = "receiver";
}
# use general list of possible channels
else {
# Find out valid channels
my $channels =
ONKYOdb::ONKYO_GetRemotecontrolValue( "1",
ONKYOdb::ONKYO_GetRemotecontrolCommand( "1", "net-service" ) );
foreach my $channel ( sort keys %{$channels} ) {
$channels_txt .= $channel . ","
if ( !( $channel =~ /^(up|down|query)$/ ) );
}
$channels_txt = substr( $channels_txt, 0, -1 );
} }
# for each reading, check if there is a known command for it # for each reading, check if there is a known command for it
@ -709,7 +745,14 @@ sub ONKYO_AVR_ZONE_Set($$$) {
# create channelList reading for frontends # create channelList reading for frontends
readingsBulkUpdate( $hash, "channelList", $channels_txt ) readingsBulkUpdate( $hash, "channelList", $channels_txt )
if ( ReadingsVal( $name, "channelList", "-" ) ne $channels_txt ); if (
(
$channels_src eq "internal"
&& ReadingsVal( $name, "channelList", "-" ) eq "-"
)
|| ( $channels_src eq "receiver"
&& ReadingsVal( $name, "channelList", "-" ) ne $channels_txt )
);
# channel # channel
if ( lc( @$a[1] ) eq "channel" ) { if ( lc( @$a[1] ) eq "channel" ) {
@ -725,55 +768,75 @@ sub ONKYO_AVR_ZONE_Set($$$) {
$return = ONKYO_AVR_ZONE_SendCommand( $hash, "input", "2B" ); $return = ONKYO_AVR_ZONE_SendCommand( $hash, "input", "2B" );
$return .= fhem "sleep 1;set $name channel " . @$a[2]; $return .= fhem "sleep 1;set $name channel " . @$a[2];
} }
elsif ( elsif ( ReadingsVal( $name, "channel", "" ) ne @$a[2]
ReadingsVal( $name, "channel", "" ) ne @$a[2] || ( defined( @$a[3] ) && defined( @$a[4] ) ) )
&& defined(
$IOhash->{helper}{receiver}{device}{netservicelist}
{netservice}
)
)
{ {
my $servicename = ""; my $servicename = "";
my $channelname = @$a[2]; my $channelname = @$a[2];
$channelname =~ s/_/ /g;
foreach my $id ( if (
sort keys %{ defined( $hash->{helper}{receiver} )
$IOhash->{helper}{receiver}{device}{netservicelist} && ref( $hash->{helper}{receiver} ) eq "HASH"
{netservice} && defined(
} $hash->{helper}{receiver}{device}{netservicelist}{count}
)
&& $hash->{helper}{receiver}{device}{netservicelist}{count}
> 0
) )
{ {
if (
defined( $channelname =~ s/_/ /g;
$IOhash->{helper}{receiver}{device}
{netservicelist}{netservice}{$id}{value} foreach my $id (
) sort keys %{
&& $IOhash->{helper}{receiver}{device} $hash->{helper}{receiver}{device}{netservicelist}
{netservicelist}{netservice}{$id}{value} eq "1" {netservice}
&& $IOhash->{helper}{receiver}{device} }
{netservicelist}{netservice}{$id}{name} eq $channelname
) )
{ {
$servicename .= uc($id); if (
$servicename .= "0" if ( !defined( @$a[3] ) ); defined(
$servicename .= @$a[3] if ( defined( @$a[3] ) ); $hash->{helper}{receiver}{device}
$servicename .= @$a[4] if ( defined( @$a[4] ) ); {netservicelist}{netservice}{$id}{value}
)
last; && $hash->{helper}{receiver}{device}
{netservicelist}{netservice}{$id}{value} eq "1"
&& $hash->{helper}{receiver}{device}
{netservicelist}{netservice}{$id}{name} eq
$channelname
)
{
$servicename .= uc($id);
last;
}
} }
} }
else {
my $channels = ONKYOdb::ONKYO_GetRemotecontrolValue(
"1",
ONKYOdb::ONKYO_GetRemotecontrolCommand(
"1", "net-service"
)
);
$return = "Unknown network service name " . @$a[2] $servicename = $channels->{$channelname}
if ( $servicename eq "" ); if ( defined( $channels->{$channelname} ) );
}
Log3 $name, 3, Log3 $name, 3,
"ONKYO_AVR_ZONE set $name " . @$a[1] . " " . @$a[2]; "ONKYO_AVR_ZONE set $name " . @$a[1] . " " . @$a[2];
$servicename = uc($channelname)
if ( $servicename eq "" );
$servicename .= "0" if ( !defined( @$a[3] ) );
$servicename .= "1" . @$a[3] if ( defined( @$a[3] ) );
$servicename .= @$a[4] if ( defined( @$a[4] ) );
$return = $return =
ONKYO_AVR_SendCommand( $IOhash, "net-service", $servicename ) ONKYO_AVR_ZONE_SendCommand( $hash, "net-service",
if ( $servicename ne "" ); $servicename );
} }
} }
} }
@ -1373,17 +1436,15 @@ sub ONKYO_AVR_ZONE_SendCommand($$$) {
$value =~ s/_/ /g; $value =~ s/_/ /g;
if ( if (
defined( defined(
$IOhash->{helper}{receiver}{device}{selectorlist}{selector} $hash->{helper}{receiver}{device}{selectorlist}{selector}
) )
&& ref( && ref( $hash->{helper}{receiver}{device}{selectorlist}{selector} )
$IOhash->{helper}{receiver}{device}{selectorlist}{selector} )
eq "ARRAY" eq "ARRAY"
) )
{ {
foreach my $input ( foreach my $input (
@{ $IOhash->{helper}{receiver}{device}{selectorlist}{selector} } @{ $hash->{helper}{receiver}{device}{selectorlist}{selector} } )
)
{ {
if ( $input->{value} eq "1" if ( $input->{value} eq "1"
&& $input->{zone} ne "00" && $input->{zone} ne "00"