2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

37_harmony.pm: some cleanups

git-svn-id: https://svn.fhem.de/fhem/trunk@6837 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2014-10-30 12:02:20 +00:00
parent 2d0f6c3a29
commit 978a2d3695

View File

@ -287,7 +287,9 @@ harmony_Set($$@)
} else { } else {
$list = "command hidDevice:noArg text cursor:up,down,left,right,pageUp,pageDown,home,end special:previousTrack,nextTrack,stop,playPause,volumeUp,volumeDown,mute"; $list = "command hidDevice:noArg text cursor:up,down,left,right,pageUp,pageDown,home,end special:previousTrack,nextTrack,stop,playPause,volumeUp,volumeDown,mute";
return "Unknown argument $cmd, choose one of $list" if( defined($hash->{id}) ); #my $device = harmony_deviceOfId( $defs{$hash->{hub}}, $hash->{id} );
#$list .= " on off" if( !defined($device->{isManualPower}) || $device->{isManualPower} eq "false" || !$device->{isManualPower} );
return "Unknown argument $cmd, choose one of $list";
} }
} }
@ -306,6 +308,10 @@ harmony_Set($$@)
return undef; return undef;
} elsif( $cmd eq "channel" ) { } elsif( $cmd eq "channel" ) {
return "no current activity" if( !defined($hash->{currentActivityID}) || $hash->{currentActivityID} == -1 ); return "no current activity" if( !defined($hash->{currentActivityID}) || $hash->{currentActivityID} == -1 );
my $activity = harmony_activityOfId($hash, $hash->{currentActivityID});
return "no device with 'channel changing role' in current activity $activity->{label}" if( !$activity->{isTuningDefault} );
return "missing channel" if( !$param ); return "missing channel" if( !$param );
harmony_sendEngineGet($hash, "changeChannel", "channel=$param:timestamp=0"); harmony_sendEngineGet($hash, "changeChannel", "channel=$param:timestamp=0");
@ -363,7 +369,7 @@ harmony_Set($$@)
my $activity = harmony_activityOfId($hash, $hash->{currentActivityID}); my $activity = harmony_activityOfId($hash, $hash->{currentActivityID});
return "unknown activity" if( !$activity ); return "unknown activity" if( !$activity );
return "no KeyboardTextEntryActivityRole in current activity $activity->{label}" if( !$activity->{KeyboardTextEntryActivityRole} ); return "no device with 'keyboard text entry role' in current activity $activity->{label}" if( !$activity->{KeyboardTextEntryActivityRole} );
$id = $activity->{KeyboardTextEntryActivityRole}; $id = $activity->{KeyboardTextEntryActivityRole};
@ -392,7 +398,7 @@ harmony_Set($$@)
my $activity = harmony_activityOfId($hash, $hash->{currentActivityID}); my $activity = harmony_activityOfId($hash, $hash->{currentActivityID});
return "unknown activity" if( !$activity ); return "unknown activity" if( !$activity );
return "no KeyboardTextEntryActivityRole in current activity $activity->{label}" if( !$activity->{KeyboardTextEntryActivityRole} ); return "no device with 'keyboard text entry role' in current activity $activity->{label}" if( !$activity->{KeyboardTextEntryActivityRole} );
} }
if( $cmd eq "text" ) { if( $cmd eq "text" ) {
@ -457,6 +463,7 @@ harmony_Set($$@)
harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='setup.sync' token=''/>"); harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='setup.sync' token=''/>");
return undef; return undef;
} }
if( $hash->{config} ) { if( $hash->{config} ) {
@ -782,6 +789,7 @@ harmony_Read($)
$hash->{STATE} = "LoggedIn"; $hash->{STATE} = "LoggedIn";
$hash->{ConnectionState} = "LoggedIn"; $hash->{ConnectionState} = "LoggedIn";
#harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='connect.discoveryinfo?get'>format=json</oa>"); #harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='connect.discoveryinfo?get'>format=json</oa>");
#harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='vnd.logitech.connect/vnd.logitech.ping?get' token=''></oa>");
#harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='vnd.logitech.harmony/vnd.logitech.harmony.system?systeminfo' token=''></oa>"); #harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='vnd.logitech.harmony/vnd.logitech.harmony.system?systeminfo' token=''></oa>");
#harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='vnd.logitech.connect/vnd.logitech.deviceinfo?get' token=''></oa>"); #harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='vnd.logitech.connect/vnd.logitech.deviceinfo?get' token=''></oa>");
#harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='vnd.logitech.setup/vnd.logitech.account?getProvisionInfo' token=''></oa>"); #harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='vnd.logitech.setup/vnd.logitech.account?getProvisionInfo' token=''></oa>");
@ -1275,7 +1283,7 @@ harmony_data2string($)
return "" if( !defined($data) ); return "" if( !defined($data) );
return $data if( !ref($data) ); return $data if( !ref($data) );
return $data if( ref($data) eq "JSON::XS::Boolean" ); return $data if( ref($data) =~ m/JSON::..::Boolean/ );
return "[". join(',', @{$data}) ."]" if(ref($data) eq "ARRAY"); return "[". join(',', @{$data}) ."]" if(ref($data) eq "ARRAY");
return Dumper $data; return Dumper $data;
@ -1301,7 +1309,8 @@ harmony_GetPower($$)
sub sub
harmony_Get($$@) harmony_Get($$@)
{ {
my ($hash, $name, $cmd, $param) = @_; my ($hash, $name, $cmd, @params) = @_;
my ($param) = @params;
#$cmd = lc( $cmd ); #$cmd = lc( $cmd );
my $list = ""; my $list = "";
@ -1321,7 +1330,7 @@ harmony_Get($$@)
} else { } else {
$list = "commands:noArg"; $list = "commands:noArg";
return "Unknown argument $cmd, choose one of $list" if( defined($hash->{id}) ); return "Unknown argument $cmd, choose one of $list";
} }
@ -1337,7 +1346,9 @@ harmony_Get($$@)
next if( $activity->{label} eq "PowerOff" ); next if( $activity->{label} eq "PowerOff" );
$ret .= "\n" if( $ret ); $ret .= "\n" if( $ret );
$ret .= sprintf( "%s\t%-24s", $activity->{id}, $activity->{label}); $ret .= sprintf( "%s\t%-24s", $activity->{id}, $activity->{label});
foreach my $param (@params) {
$ret .= "\t". harmony_data2string($activity->{$param}) if( $param && defined($activity->{$param}) ); $ret .= "\t". harmony_data2string($activity->{$param}) if( $param && defined($activity->{$param}) );
}
if( $param eq "power" ) { if( $param eq "power" ) {
my $power = harmony_GetPower($hash, $activity); my $power = harmony_GetPower($hash, $activity);
@ -1362,8 +1373,10 @@ harmony_Get($$@)
foreach my $device (sort { $a->{id} <=> $b->{id} } @{$hash->{config}->{device}}) { foreach my $device (sort { $a->{id} <=> $b->{id} } @{$hash->{config}->{device}}) {
$ret .= "\n" if( $ret ); $ret .= "\n" if( $ret );
$ret .= sprintf( "%s\t%-20s\t%-20s\t%-15s\t%-15s", $device->{id}, $device->{label}, $device->{type}, $device->{manufacturer}, $device->{model}); $ret .= sprintf( "%s\t%-20s\t%-20s\t%-15s\t%-15s", $device->{id}, $device->{label}, $device->{type}, $device->{manufacturer}, $device->{model});
foreach my $param (@params) {
$ret .= "\t". harmony_data2string($device->{$param}) if( $param && defined($device->{$param}) ); $ret .= "\t". harmony_data2string($device->{$param}) if( $param && defined($device->{$param}) );
} }
}
#$ret = sprintf("%s\t\t%-20s\t%-20s\t%-15s\t%-15s\n", "ID", "LABEL", "TYPE", "MANUFACTURER", "MODEL"). $ret if( $ret ); #$ret = sprintf("%s\t\t%-20s\t%-20s\t%-15s\t%-15s\n", "ID", "LABEL", "TYPE", "MANUFACTURER", "MODEL"). $ret if( $ret );
return $ret; return $ret;