fix readings begin failed
This commit is contained in:
		@@ -57,7 +57,7 @@ use Encode qw(encode_utf8);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
my $version = "0.0.60";
 | 
					my $version = "0.0.61";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -305,10 +305,13 @@ sub LGTV_WebOS_TimerStatusRequest($) {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    RemoveInternalTimer($hash,'LGTV_WebOS_TimerStatusRequest');
 | 
					    RemoveInternalTimer($hash,'LGTV_WebOS_TimerStatusRequest');
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    readingsBeginUpdate($hash);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    if( !IsDisabled($name) and $hash->{CD} ) {
 | 
					    if( !IsDisabled($name) and $hash->{CD} ) {
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        Log3 $name, 4, "LGTV_WebOS ($name) - run get functions";
 | 
					        Log3 $name, 4, "LGTV_WebOS ($name) - run get functions";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        readingsBulkUpdate($hash,'state', 'on');
 | 
					        readingsBulkUpdate($hash,'state', 'on');
 | 
				
			||||||
        readingsBulkUpdate($hash,'presence', 'present');
 | 
					        readingsBulkUpdate($hash,'presence', 'present');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -332,6 +335,8 @@ sub LGTV_WebOS_TimerStatusRequest($) {
 | 
				
			|||||||
        readingsBulkUpdate($hash,'presence', 'absent');
 | 
					        readingsBulkUpdate($hash,'presence', 'absent');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    readingsEndUpdate($hash, 1);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    LGTV_WebOS_Open($hash) if( !IsDisabled($name) and not $hash->{CD} );
 | 
					    LGTV_WebOS_Open($hash) if( !IsDisabled($name) and not $hash->{CD} );
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    InternalTimer( gettimeofday()+15,"LGTV_WebOS_TimerStatusRequest", $hash, 1 );
 | 
					    InternalTimer( gettimeofday()+15,"LGTV_WebOS_TimerStatusRequest", $hash, 1 );
 | 
				
			||||||
@@ -344,14 +349,31 @@ sub LGTV_WebOS_Set($@) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    my $uri;
 | 
					    my $uri;
 | 
				
			||||||
    my %payload;
 | 
					    my %payload;
 | 
				
			||||||
 | 
					    #my $inputs = '';
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    #if ( defined( $hash->{helper}{device}{inputs}) and ref( $hash->{helper}{device}{inputs} ) eq "HASH" ) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    #    foreach my $id (sort keys %{ $hash->{helper}{device}{inputs} }) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    #        $inputs .= ',' if($id != 0);
 | 
				
			||||||
 | 
					    #        $inputs .= $hash->{helper}{device}{inputs}{$id}{input};
 | 
				
			||||||
 | 
					    #    }
 | 
				
			||||||
 | 
					    #}
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    if($cmd eq 'connect') {
 | 
					    if($cmd eq 'connect') {
 | 
				
			||||||
        return "usage: connect" if( @args != 0 );
 | 
					        return "usage: connect" if( @args != 0 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        LGTV_WebOS_Open($hash);
 | 
					        LGTV_WebOS_Open($hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return undef;
 | 
					        return undef;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    } elsif($cmd eq 'clearInputList') {
 | 
				
			||||||
 | 
					        return "usage: clearInputList" if( @args != 0 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        delete $hash->{helper}{device}{inputs};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return undef;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    } elsif($cmd eq 'pairing') {
 | 
					    } elsif($cmd eq 'pairing') {
 | 
				
			||||||
        return "usage: pairing" if( @args != 0 );
 | 
					        return "usage: pairing" if( @args != 0 );
 | 
				
			||||||
@@ -491,7 +513,7 @@ sub LGTV_WebOS_Set($@) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        my  $list = ""; 
 | 
					        my  $list = ""; 
 | 
				
			||||||
        $list .= "connect:noArg pairing:noArg screenMsg mute:on,off volume volumeUp:noArg volumeDown:noArg channelDown:noArg channelUp:noArg getServiceList:noArg on:noArg off:noArg launchApp:Maxdome,AmazonVideo,YouTube,Netflix,TV,GooglePlay,Browser,Chilieu,TVCast,Smartshare,Scheduler,Miracast,TVGuide,Timemachine,ARDMediathek,Arte,WetterMeteo,Notificationcenter 3D:on,off stop:noArg play:noArg pause:noArg rewind:noArg fastForward:noArg";
 | 
					        $list .= "connect:noArg pairing:noArg screenMsg mute:on,off volume volumeUp:noArg volumeDown:noArg channelDown:noArg channelUp:noArg getServiceList:noArg on:noArg off:noArg launchApp:Maxdome,AmazonVideo,YouTube,Netflix,TV,GooglePlay,Browser,Chilieu,TVCast,Smartshare,Scheduler,Miracast,TVGuide,Timemachine,ARDMediathek,Arte,WetterMeteo,Notificationcenter 3D:on,off stop:noArg play:noArg pause:noArg rewind:noArg fastForward:noArg clearInputList:noArg";
 | 
				
			||||||
        #$list .= "channel:" . join(' ',ReadingsVal($name,'channelName','none'));
 | 
					        #$list .= "channel:" . join(' ',ReadingsVal($name,'channelName','none'));
 | 
				
			||||||
        return "Unknown argument $cmd, choose one of $list";
 | 
					        return "Unknown argument $cmd, choose one of $list";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -779,17 +801,29 @@ sub LGTV_WebOS_WriteReadings($$) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    elsif( ref($decode_json->{payload}{devices}) eq "ARRAY" and scalar(@{$decode_json->{payload}{devices}}) > 0 ) {
 | 
					    elsif( ref($decode_json->{payload}{devices}) eq "ARRAY" and scalar(@{$decode_json->{payload}{devices}}) > 0 ) {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        #my $count = 0;
 | 
				
			||||||
        foreach my $devices ( @{$decode_json->{payload}{devices}} ) {
 | 
					        foreach my $devices ( @{$decode_json->{payload}{devices}} ) {
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
 | 
					            #if( not defined($hash->{helper}{device}{inputs}{$count}) ) {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            #    $hash->{helper}{device}{inputs}{$count}{input}     = $devices->{label};
 | 
				
			||||||
 | 
					            #    $hash->{helper}{device}{inputs}{$count}{appid}     = $devices->{appId};
 | 
				
			||||||
 | 
					            #}
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            #$count++;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            readingsBulkUpdate($hash,'extInput_'.$devices->{label},'connect_'.$devices->{connected});
 | 
					            readingsBulkUpdate($hash,'extInput_'.$devices->{label},'connect_'.$devices->{connected});
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    elsif( ref($decode_json->{payload}{programList}) eq "ARRAY" and scalar(@{$decode_json->{payload}{programList}}) > 0 ) {
 | 
					    elsif( ref($decode_json->{payload}{programList}) eq "ARRAY" and scalar(@{$decode_json->{payload}{programList}}) > 0 ) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        my $count = 0;
 | 
				
			||||||
        foreach my $programList ( @{$decode_json->{payload}{programList}} ) {
 | 
					        foreach my $programList ( @{$decode_json->{payload}{programList}} ) {
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
            readingsBulkUpdate($hash,'currentTitle',$programList->{programName});
 | 
					            $hash->{helper}{device}{channelguide}{$count}{programname}   = $programList->{programName};
 | 
				
			||||||
            return;
 | 
					            $count++
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -856,13 +890,16 @@ sub LGTV_WebOS_WriteReadings($$) {
 | 
				
			|||||||
        readingsBulkUpdate($hash,'channelId',$decode_json->{payload}{'channelNumber'});
 | 
					        readingsBulkUpdate($hash,'channelId',$decode_json->{payload}{'channelNumber'});
 | 
				
			||||||
        readingsBulkUpdate($hash,'channel',$decode_json->{payload}{'channelName'});
 | 
					        readingsBulkUpdate($hash,'channel',$decode_json->{payload}{'channelName'});
 | 
				
			||||||
        readingsBulkUpdate($hash,'channelMedia',$decode_json->{payload}{'channelTypeName'});
 | 
					        readingsBulkUpdate($hash,'channelMedia',$decode_json->{payload}{'channelTypeName'});
 | 
				
			||||||
 | 
					        readingsBulkUpdate($hash,'channelCurrentTitle',$hash->{helper}{device}{channelguide}{0}{programname});
 | 
				
			||||||
 | 
					        readingsBulkUpdate($hash,'channelNextTitle',$hash->{helper}{device}{channelguide}{1}{programname});
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        readingsBulkUpdate($hash,'channelId','-');
 | 
					        readingsBulkUpdate($hash,'channelId','-');
 | 
				
			||||||
        readingsBulkUpdate($hash,'channel','-');
 | 
					        readingsBulkUpdate($hash,'channel','-');
 | 
				
			||||||
        readingsBulkUpdate($hash,'channelMedia','-');
 | 
					        readingsBulkUpdate($hash,'channelMedia','-');
 | 
				
			||||||
        readingsBulkUpdate($hash,'currentTitle','-');
 | 
					        readingsBulkUpdate($hash,'channelCurrentTitle','-');
 | 
				
			||||||
 | 
					        readingsBulkUpdate($hash,'channelNextTitle','-');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    readingsEndUpdate($hash, 1);
 | 
					    readingsEndUpdate($hash, 1);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user