mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
37_harmony.pm: added some commands on the DEVICE level
git-svn-id: https://svn.fhem.de/fhem/trunk@6821 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
def18062cb
commit
ae1cf55fa1
@ -223,8 +223,45 @@ harmony_Set($$@)
|
|||||||
#$cmd = lc( $cmd );
|
#$cmd = lc( $cmd );
|
||||||
|
|
||||||
my $list = "";
|
my $list = "";
|
||||||
|
if( defined($hash->{id}) ) {
|
||||||
|
if( !$hash->{hub} ) {
|
||||||
|
$hash->{hub} = harmony_hubOfDevice($param);
|
||||||
|
|
||||||
|
return "no hub found for device $name ($param)" if( !$hash->{hub} );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( $cmd eq "command" ) {
|
||||||
|
$param2 = $param;
|
||||||
|
$param = $hash->{id};
|
||||||
|
|
||||||
|
$hash = $defs{$hash->{hub}};
|
||||||
|
|
||||||
|
} elsif( $cmd eq "hidDevice" || $cmd eq "text" || $cmd eq "cursor" || $cmd eq "special" || $cmd eq "hid" ) {
|
||||||
|
my $id = $hash->{id};
|
||||||
|
|
||||||
|
$hash = $defs{$hash->{hub}};
|
||||||
|
|
||||||
|
my $device = harmony_deviceOfId( $hash, $id );
|
||||||
|
return "unknown device" if( !$device );
|
||||||
|
|
||||||
|
return "no keyboard associated with device $device->{label}" if( !$device->{IsKeyboardAssociated} );
|
||||||
|
|
||||||
|
if( !$hash->{hidDevice} || $hash->{hidDevice} ne $id ) {
|
||||||
|
$hash->{hidDevice} = $id;
|
||||||
|
harmony_sendIq($hash, "<oa xmlns='connect.logitech.com' mime='harmony.engine?sethiddevice' token=''>deviceId=$id</oa>");
|
||||||
|
sleep( 3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return if( $cmd eq "hidDevice" );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$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}) );
|
return "Unknown argument $cmd, choose one of $list" if( defined($hash->{id}) );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( $cmd eq 'off' ) {
|
if( $cmd eq 'off' ) {
|
||||||
$cmd = "activity";
|
$cmd = "activity";
|
||||||
$param = "PowerOff";
|
$param = "PowerOff";
|
||||||
@ -416,13 +453,13 @@ harmony_Set($$@)
|
|||||||
if( $hidDevices ) {
|
if( $hidDevices ) {
|
||||||
$hidDevices =~ s/ /./g;
|
$hidDevices =~ s/ /./g;
|
||||||
|
|
||||||
$list .= " hidDevice:$hidDevices";
|
$list .= " hidDevice:,$hidDevices";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $autocreateDevices ) {
|
if( $autocreateDevices ) {
|
||||||
$autocreateDevices =~ s/ /./g;
|
$autocreateDevices =~ s/ /./g;
|
||||||
|
|
||||||
$list .= " autocreate:$autocreateDevices";
|
$list .= " autocreate:$autocreateDevices,";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1202,14 +1239,66 @@ harmony_data2string($)
|
|||||||
return Dumper $data;
|
return Dumper $data;
|
||||||
}
|
}
|
||||||
sub
|
sub
|
||||||
|
harmony_GetPower($$)
|
||||||
|
{
|
||||||
|
my ($hash, $activity) = @_;
|
||||||
|
|
||||||
|
my $power = "";
|
||||||
|
return $power if( !defined($activity->{fixit}) );
|
||||||
|
|
||||||
|
foreach my $id (keys %{$activity->{fixit}}) {
|
||||||
|
my $label = harmony_labelOfDevice($hash, $id);
|
||||||
|
my $state = $activity->{fixit}->{$id}->{Power};
|
||||||
|
$state = "Manual" if( !$state );
|
||||||
|
|
||||||
|
$power .= "\n\t\t\t$label: $state";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $power;
|
||||||
|
}
|
||||||
|
sub
|
||||||
|
harmony_hubOfDevice($)
|
||||||
|
{
|
||||||
|
my ($id) = @_;
|
||||||
|
|
||||||
|
foreach my $d (sort keys %defs) {
|
||||||
|
next if( !defined($defs{$d}) );
|
||||||
|
next if( $defs{$d}->{TYPE} ne "harmony" );
|
||||||
|
next if( $defs{$d}->{id} );
|
||||||
|
next if( !harmony_deviceOfId($defs{$d}, $id) );
|
||||||
|
Log3 undef, 3, "harmony: found IODev $d for device $id" ;
|
||||||
|
return $d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sub
|
||||||
harmony_Get($$@)
|
harmony_Get($$@)
|
||||||
{
|
{
|
||||||
my ($hash, $name, $cmd, $param) = @_;
|
my ($hash, $name, $cmd, $param) = @_;
|
||||||
#$cmd = lc( $cmd );
|
#$cmd = lc( $cmd );
|
||||||
|
|
||||||
my $list = "";
|
my $list = "";
|
||||||
|
|
||||||
|
if( defined($hash->{id}) ) {
|
||||||
|
if( !$hash->{hub} ) {
|
||||||
|
$hash->{hub} = harmony_hubOfDevice($hash->{id});
|
||||||
|
|
||||||
|
return "no IODev found for device $name ($hash->{id})" if( !$hash->{hub} );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $cmd eq "commands" || $cmd eq "deviceCommands" ) {
|
||||||
|
$cmd = "deviceCommands";
|
||||||
|
$param = $hash->{id};
|
||||||
|
|
||||||
|
$hash = $defs{$hash->{hub}};
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$list = "commands:noArg";
|
||||||
return "Unknown argument $cmd, choose one of $list" if( defined($hash->{id}) );
|
return "Unknown argument $cmd, choose one of $list" if( defined($hash->{id}) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
my $ret;
|
my $ret;
|
||||||
if( $cmd eq "activities" ) {
|
if( $cmd eq "activities" ) {
|
||||||
@ -1223,39 +1312,18 @@ harmony_Get($$@)
|
|||||||
$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 = "";
|
my $power = harmony_GetPower($hash, $activity);
|
||||||
foreach my $id (keys %{$activity->{fixit}}) {
|
$ret .= $power if( $power );
|
||||||
my $label = harmony_labelOfDevice($hash, $id);
|
|
||||||
$power .= "\n\t\t\t" if( $power );
|
|
||||||
$power .= "$label: ";
|
|
||||||
if( my $state = $activity->{fixit}->{$id}->{Power} ) {
|
|
||||||
$power .= $state;
|
|
||||||
} else {
|
|
||||||
$power .= "Manual";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$ret .= "\n\t\t\t$power" if( $power );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#$ret = sprintf("%s\t\t%-24s\n", "ID", "LABEL"). $ret if( $ret );
|
#$ret = sprintf("%s\t\t%-24s\n", "ID", "LABEL"). $ret if( $ret );
|
||||||
$ret .= "\n-1\t\tPowerOff";
|
$ret .= "\n-1\t\tPowerOff";
|
||||||
if( $param eq "power" ) {
|
if( $param eq "power" ) {
|
||||||
my $power = "";
|
|
||||||
if( my $activity = harmony_activityOfId($hash, -1) ) {
|
if( my $activity = harmony_activityOfId($hash, -1) ) {
|
||||||
foreach my $id (keys %{$activity->{fixit}}) {
|
my $power = harmony_GetPower($hash, $activity);
|
||||||
my $label = harmony_labelOfDevice($hash, $id);
|
$ret .= $power if( $power );
|
||||||
$power .= "\n\t\t\t" if( $power );
|
|
||||||
$power .= "$label: ";
|
|
||||||
if( my $state = $activity->{fixit}->{$id}->{Power} ) {
|
|
||||||
$power .= $state;
|
|
||||||
} else {
|
|
||||||
$power .= "Manual";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$ret .= "\n\t\t\t$power" if( $power );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
@ -1322,6 +1390,7 @@ harmony_Get($$@)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "no commands found" if( !$ret );
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
} elsif( $cmd eq "activityDetail"
|
} elsif( $cmd eq "activityDetail"
|
||||||
@ -1514,7 +1583,8 @@ harmony_Attr($$$)
|
|||||||
<li>autocreate [<id>|<name>]<br>
|
<li>autocreate [<id>|<name>]<br>
|
||||||
creates a fhem device for a single/all device(s) in the harmony hub. if activities are startet the state
|
creates a fhem device for a single/all device(s) in the harmony hub. if activities are startet the state
|
||||||
of these devices will be updatet with the power state defined in these activites.</li>
|
of these devices will be updatet with the power state defined in these activites.</li>
|
||||||
</ul><br>
|
</ul>
|
||||||
|
The command, hidDevice, text, cursor and special commmands are also available for the autocreated devices. The <id>|<name> paramter hast to be omitted.<br><br>
|
||||||
|
|
||||||
<a name="harmony_Get"></a>
|
<a name="harmony_Get"></a>
|
||||||
<b>Get</b>
|
<b>Get</b>
|
||||||
@ -1533,7 +1603,9 @@ harmony_Attr($$$)
|
|||||||
<li>configDetail</li>
|
<li>configDetail</li>
|
||||||
<li>currentActivity<br>
|
<li>currentActivity<br>
|
||||||
returns the current activity name</li>
|
returns the current activity name</li>
|
||||||
</ul><br>
|
</ul>
|
||||||
|
The commands commmand is also available for the autocreated devices. The <id>|<name> paramter hast to be omitted.<br><br>
|
||||||
|
|
||||||
|
|
||||||
<a name="harmony_Attr"></a>
|
<a name="harmony_Attr"></a>
|
||||||
<b>Attributes</b>
|
<b>Attributes</b>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user