diff --git a/fhem/FHEM/82_LGTV_IP12.pm b/fhem/FHEM/82_LGTV_IP12.pm index 2052d1ab3..71815cd27 100755 --- a/fhem/FHEM/82_LGTV_IP12.pm +++ b/fhem/FHEM/82_LGTV_IP12.pm @@ -109,6 +109,7 @@ my %LGTV_IP12_rcCodes = ( "myApps"=>417, ); +################################# sub LGTV_IP12_Initialize($) { @@ -121,9 +122,10 @@ LGTV_IP12_Initialize($) $hash->{AttrFn} = "LGTV_IP12_Attr"; $hash->{NotifyFn} = "LGTV_IP12_Notify"; $hash->{NOTIFYDEV} = "global"; - $hash->{AttrList} = "do_not_notify:0,1 pairingcode request-timeout:1,2,3,4,5 disable:0,1 ".$readingFnAttributes; + $hash->{AttrList} = "do_not_notify:0,1 pairingcode request-timeout:1,2,3,4,5 disable:0,1 disabledForIntervals ".$readingFnAttributes; } +################################# sub LGTV_IP12_Define($$) { @@ -160,20 +162,38 @@ LGTV_IP12_Define($$) $hash->{INTERVAL} = $hash->{helper}{OFF_INTERVAL}; $hash->{helper}{ON_INTERVAL} = $hash->{helper}{OFF_INTERVAL}; } - - $hash->{helper}{DISABLED} = 0 unless(exists($hash->{helper}{DISABLED})); - + $hash->{STATE} = 'defined'; return undef; } +################################# sub LGTV_IP12_Get($@) { - # not implemented yet + my ($hash, @a) = @_; + my $what; + my $return; + + return "argument is missing" if(int(@a) != 2); + + $what = $a[1]; + + return ReadingsVal($hash->{NAME}, $what, "") if(defined(ReadingsVal($hash->{NAME}, $what, undef))); + + $return = "unknown argument $what, choose one of"; + + foreach my $reading (keys %{$hash->{READINGS}}) + { + $return .= " $reading:noArg"; + } + + return $return; } + +################################# sub LGTV_IP12_Notify($$) { @@ -181,17 +201,24 @@ LGTV_IP12_Notify($$) my $name = $hash->{NAME}; return if($dev->{NAME} ne "global"); - return if(!grep(m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}})); - - if(defined(AttrVal($name, "pairingcode", undef)) and AttrVal($name, "pairingcode", undef) =~/^\d{6}$/) + + if(!grep(m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}})) { - Log3 $name, 3, "LGTV_IP12 ($name) - try pairing with pairingcode ".AttrVal($name, "pairingcode", undef); - LGTV_IP12_Pair($hash, AttrVal($name, "pairingcode", undef)); + if(defined(AttrVal($name, "pairingcode", undef)) and AttrVal($name, "pairingcode", undef) =~/^\d{6}$/) + { + Log3 $name, 3, "LGTV_IP12 ($name) - try pairing with pairingcode ".AttrVal($name, "pairingcode", undef); + LGTV_IP12_Pair($hash, AttrVal($name, "pairingcode", undef)); + } + + LGTV_IP12_ResetTimer($hash, 0); + } + elsif(!grep(m/^(?:ATTR $name disable.*|DELETEATTR $name disable.*)$/, @{$dev->{CHANGED}})) + { + LGTV_IP12_ResetTimer($hash, 0); } - - LGTV_IP12_ResetTimer($hash, 0); } +################################# sub LGTV_IP12_Set($@) { @@ -303,27 +330,21 @@ LGTV_IP12_Attr(@) if($a[0] eq "set" && $a[2] eq "disable") { - if($a[3] eq "0") + if($a[3] eq "1") { - $hash->{helper}{DISABLED} = 0; - } - elsif($a[3] eq "1") - { - $hash->{helper}{DISABLED} = 1; readingsSingleUpdate($hash, "state", "disabled",1); } LGTV_IP12_ResetTimer($hash, 0); } elsif($a[0] eq "del" && $a[2] eq "disable") { - $hash->{helper}{DISABLED} = 0; LGTV_IP12_ResetTimer($hash, 0); } return undef; } - +################################# sub LGTV_IP12_Delete($$) { @@ -332,10 +353,14 @@ LGTV_IP12_Delete($$) LGTV_IP12_HttpGet($hash, "/udap/api/pairing", "removePairing", undef, "byebye8080") if(exists($hash->{helper}{PAIRED}) and $hash->{helper}{PAIRED} == 1); } +############################################################################################################ +# +# Begin of helper functions +# +############################################################################################################ ################################# - # start a status request by starting the neccessary requests sub LGTV_IP12_GetStatus($) @@ -361,6 +386,8 @@ LGTV_IP12_GetStatus($) LGTV_IP12_ResetTimer($hash); } +################################# +# parses the HTTP response from the TV sub LGTV_IP12_ParseHttpResponse($$$) { @@ -429,8 +456,6 @@ LGTV_IP12_ParseHttpResponse($$$) if($cmd eq "statusRequest") { - - if($arg eq "volumeInfo") { if($data =~ /(.+?)<\/level>/) @@ -502,13 +527,12 @@ LGTV_IP12_ParseHttpResponse($$$) readingsEndUpdate($hash, 1); } +################################# # executes a http request with or without data and starts the HTTP request non-blocking to avoid timing problems for other modules (e.g. HomeMatic) sub LGTV_IP12_HttpGet($$$$;$) { -my ($hash, $path, $cmd, $arg, $data) = @_; - - + my ($hash, $path, $cmd, $arg, $data) = @_; if(defined($data)) { @@ -548,16 +572,18 @@ my ($hash, $path, $cmd, $arg, $data) = @_; } } +################################# # sends the pairing request. sub LGTV_IP12_Pair($$) { my ($hash, $code) = @_; - LGTV_IP12_HttpGet($hash, "/udap/api/pairing", "pairing", $code, "hello$code8080"); - + LGTV_IP12_HttpGet($hash, "/udap/api/pairing", "pairing", $code, "hello$code8080"); } +################################# +# retrieves the complete channel list including channel names sub LGTV_IP12_RetrieveChannelList($) { @@ -613,13 +639,15 @@ LGTV_IP12_RetrieveChannelList($) } } +################################# +# resets the status update timer according to the current state sub LGTV_IP12_ResetTimer($;$) { my ($hash, $interval) = @_; RemoveInternalTimer($hash); - if($hash->{helper}{DISABLED} == 0) + unless(IsDisabled($hash->{NAME})) { if(defined($interval)) { @@ -729,10 +757,11 @@ sub LGTV_IP12_html2txt($)

Get -