diff --git a/CHANGED b/CHANGED index ecf4e4257..492238d7f 100644 --- a/CHANGED +++ b/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - changed: enabled authentication with the logitech myharmony server + for hub firmware version 4.x, version 3.x still works without. - feature: YAMAHA_BD: support 95_remotecontrol.pm module features - changed: Reverted to previous version. Module not working on RPi - feature: 71_PHILIPS_AUDIO: Implemented UPNP/DLNA player discovery. diff --git a/FHEM/37_harmony.pm b/FHEM/37_harmony.pm index 3941e79f0..d1a09d9ce 100644 --- a/FHEM/37_harmony.pm +++ b/FHEM/37_harmony.pm @@ -485,6 +485,8 @@ harmony_Set($$@) return undef; } elsif( $cmd eq "reconnect" ) { + delete $hash->{helper}{UserAuthToken} if( $param eq "all" ); + delete $hash->{identity} if( $param eq "all" ); harmony_connect($hash); return undef; @@ -857,21 +859,25 @@ harmony_Read($) if( $line eq "" ) { $hash->{ConnectionState} = "LoggedIn"; - #harmony_sendIq($hash, ""); - #harmony_sendIq($hash, ""); - #harmony_sendIq($hash, ""); - #harmony_sendIq($hash, ""); - #harmony_sendIq($hash, "format=json"); - #harmony_sendIq($hash, "format=json"); - #harmony_sendIq($hash, "format=json"); - #harmony_sendIq($hash, "format=json"); - #harmony_sendIq($hash, "hetag= :uri=dynamite:://HomeAutomationService/Config/:encode=true"); - #harmony_sendIq($hash, ""); + if( $hash->{helper}{UserAuthToken} ) { + harmony_getSessionToken($hash); + } else { + #harmony_sendIq($hash, ""); + #harmony_sendIq($hash, ""); + #harmony_sendIq($hash, ""); + #harmony_sendIq($hash, ""); + #harmony_sendIq($hash, "format=json"); + #harmony_sendIq($hash, "format=json"); + #harmony_sendIq($hash, "format=json"); + #harmony_sendIq($hash, "format=json"); + #harmony_sendIq($hash, "hetag= :uri=dynamite:://HomeAutomationService/Config/:encode=true"); + #harmony_sendIq($hash, ""); - #harmony_sendIq($hash, "name=1vm7ATw/tN6HXGpQcCs/A5MkuvI#iOS6.0.1#iPhone"); + #harmony_sendIq($hash, "name=1vm7ATw/tN6HXGpQcCs/A5MkuvI#iOS6.0.1#iPhone"); - harmony_sendIq($hash, "format=json"); - #harmony_sendEngineGet($hash, "config"); + harmony_sendIq($hash, "format=json"); + #harmony_sendEngineGet($hash, "config"); + } RemoveInternalTimer($hash); InternalTimer(gettimeofday()+50, "harmony_ping", $hash, 0); @@ -967,14 +973,14 @@ harmony_Read($) Log3 $name, 2, "$name: error ($1): $2"; } elsif( $content =~ m/vnd.logitech.pair/ ) { -#Log 3, Dumper $decoded; if( !$hash->{identity} && $decoded->{identity} ) { $hash->{identity} = $decoded->{identity}; harmony_connect($hash); } else { - harmony_sendEngineGet($hash, "config"); + harmony_sendIq($hash, "format=json"); + #harmony_sendEngineGet($hash, "config"); } @@ -1097,7 +1103,7 @@ Log 3, Dumper decode_json($decoded->{resource}) if( !$json && $decoded->{resourc } elsif( $line =~ m/^<\?xml.*PLAIN.*>/ ) { my $identity = $hash->{identity}?$hash->{identity}:"guest"; - my $auth = encode_base64("\0$identity\0$identity",''); + my $auth = encode_base64("\0$identity\@connect.logitech.com\0gatorade.",''); harmony_send($hash, "$auth"); $data = ""; @@ -1106,7 +1112,7 @@ Log 3, Dumper decode_json($decoded->{resource}) if( !$json && $decoded->{resourc Log3 $name, 4, "$name: unknown: $line"; } elsif( $line ) { - Log3 $name, 5, "$name: $line"; + #Log3 $name, 5, "$name: $line"; } } @@ -1172,11 +1178,23 @@ harmony_connect($) } else { harmony_disconnect( $hash ); - InternalTimer(gettimeofday()+2, "harmony_connect", $hash, 0); + InternalTimer(gettimeofday()+10, "harmony_connect", $hash, 0); } } } +sub +harmony_getSessionToken($) +{ + my ($hash) = @_; + my $name = $hash->{NAME}; + + my $unique_id = '1vm7ATw/tN6HXGpQcCs/A5MkuvI'; + my $device = 'iOS6.0.1#iPhone'; + + harmony_sendPair($hash, "token=$hash->{helper}{UserAuthToken}:name=$unique_id#$device"); +} + sub harmony_send($$) { @@ -1198,11 +1216,22 @@ harmony_sendIq($$;$) ++$id; - my $iq = "$xml"; + my $iq = "$xml"; + $iq = "$xml"; harmony_send($hash,$iq); } sub +harmony_sendPair($$) +{ + my ($hash, $payload) = @_; + $payload = '' if ( !$payload ); + + my $xml = "$payload"; + + harmony_sendIq($hash,$xml); +} +sub harmony_sendEngineGet($$;$) { my ($hash, $endpoint, $payload) = @_; @@ -1240,7 +1269,8 @@ harmony_sendEngineRender($$$) { my ($hash, $endpoint, $payload) = @_; - my $xml = "$payload"; + #my $xml = "$payload"; + my $xml = "$payload"; harmony_sendIq($hash,$xml, "render"); } @@ -1284,10 +1314,6 @@ harmony_dispatch($$$) $json = JSON->new->utf8(0)->decode($data); } - if( $json->{error} ) { - #$hash->{lastError} = $json->{error}{message}; - } - if( $param->{type} eq 'token' ) { harmony_parseToken($hash,$json); @@ -1349,19 +1375,28 @@ sub harmony_parseToken($$) { my($hash, $json) = @_; + my $name = $hash->{NAME}; RemoveInternalTimer($hash); + my $error = $json->{ErrorCode}; +Log 1, $error; + if( $error && $error != 200 ) { + Log3 $name, 2, "$name: error ($error): $json->{Message}"; + $hash->{lastError} = $json->{Message}; + } + my $had_token = $hash->{helper}{UserAuthToken}; - #$hash->{helper}{AccountId} = $json->{GetUserAuthTokenResult}->{AccountId}; + $hash->{helper}{AccountId} = $json->{GetUserAuthTokenResult}->{AccountId}; $hash->{helper}{UserAuthToken} = $json->{GetUserAuthTokenResult}->{UserAuthToken}; - if( $json->{GetUserAuthTokenResult} ) { + if( $hash->{helper}{UserAuthToken} ) { $hash->{ConnectionState} = "GotToken"; } else { - $hash->{ConnectionState} = "Error" if( !$hash->{helper}{UserAuthToken} ); + $hash->{STATE} = "Error"; + $hash->{ConnectionState} = "Error"; RemoveInternalTimer($hash); InternalTimer(gettimeofday()+60, "harmony_connect", $hash, 0); @@ -1646,7 +1681,10 @@ harmony_Attr($$$) Notes:
@@ -1702,8 +1740,8 @@ harmony_Attr($$$) request the current activity from the hub
  • off
    switch current activity off
  • -
  • reconnect
    - close connection to the hub and reconnect
  • +
  • reconnect [all]
    + close connection to the hub and reconnect, if all is given also reconnect to the logitech server
  • sleeptimer [<timeout>]
    <timeout> -> timeout in minutes
    -1 -> timer off