2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 12:58:13 +00:00

LGTV_IP12: added attribute disabledForIntervals, changed handling for disabled.* attributes, fixed commandref anchor, code makeup

git-svn-id: https://svn.fhem.de/fhem/trunk@10994 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2016-03-05 13:29:23 +00:00
parent 0e906601b1
commit 9194bdb563

View File

@ -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($$)
{
@ -161,19 +163,37 @@ LGTV_IP12_Define($$)
$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,8 +201,9 @@ LGTV_IP12_Notify($$)
my $name = $hash->{NAME};
return if($dev->{NAME} ne "global");
return if(!grep(m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}}));
if(!grep(m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}}))
{
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);
@ -191,7 +212,13 @@ LGTV_IP12_Notify($$)
LGTV_IP12_ResetTimer($hash, 0);
}
elsif(!grep(m/^(?:ATTR $name disable.*|DELETEATTR $name disable.*)$/, @{$dev->{CHANGED}}))
{
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, "<api type=\"pairing\"><name>byebye</name><port>8080</port></api>") 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>(.+?)<\/level>/)
@ -502,14 +527,13 @@ 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) = @_;
if(defined($data))
{
Log3 $hash->{NAME}, 5 , "LGTV_IP12 (".$hash->{NAME}.") - sending POST request for command \"$cmd".(defined($arg) ? " ".(split("\\|", $arg))[0] : "")."\" to url $path: $data";
@ -548,6 +572,7 @@ my ($hash, $path, $cmd, $arg, $data) = @_;
}
}
#################################
# sends the pairing request.
sub
LGTV_IP12_Pair($$)
@ -555,9 +580,10 @@ LGTV_IP12_Pair($$)
my ($hash, $code) = @_;
LGTV_IP12_HttpGet($hash, "/udap/api/pairing", "pairing", $code, "<api type=\"pairing\"><name>hello</name><value>$code</value><port>8080</port></api>");
}
#################################
# 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))
{
@ -733,6 +761,7 @@ sub LGTV_IP12_html2txt($)
<code>get &lt;name&gt; &lt;reading&gt;</code>
<br><br>
Currently, the get command only returns the reading values. For a specific list of possible values, see section "Generated Readings/Events".
<br><br>
</ul>
<br><br>
<a name="LGTV_IP12_attr"></a>
@ -740,12 +769,19 @@ sub LGTV_IP12_html2txt($)
<ul>
<li><a href="#do_not_notify">do_not_notify</a></li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li><br>
<li><a name="disable">disable</a></li>
Optional attribute to disable the internal cyclic status update of the player. Manual status updates via statusRequest command is still possible.
<li><a name="LGTV_IP12_disable">disable</a></li>
Optional attribute to disable the internal cyclic status update of the TV. Manual status updates via statusRequest command is still possible.
<br><br>
Possible values: 0 => perform cyclic status update, 1 => don't perform cyclic status updates.<br><br>
<li><a name="LGTV_IP12_disabledForIntervals">disabledForIntervals</a> HH:MM-HH:MM HH:MM-HH-MM...</li>
Optional attribute to disable the internal cyclic status update of the TV during a specific time interval. The attribute contains a space separated list of HH:MM tupels.
If the current time is between any of these time specifications, the cyclic update will be disabled.
Instead of HH:MM you can also specify HH or HH:MM:SS.
<br><br>To specify an interval spawning midnight, you have to specify two intervals, e.g.:
<pre>23:00-24:00 00:00-01:00</pre>
Default Value is <i>empty</i> (no intervals defined, cyclic update is always active)<br><br>
<li><a name="LGTV_IP12_request-timeout">request-timeout</a></li>
Optional attribute change the response timeout in seconds for all queries to the player.
Optional attribute change the response timeout in seconds for all queries to the TV.
<br><br>
Possible values: 1-5 seconds. Default value is 4 seconds.<br><br>
<li><a name="LGTV_IP12_pairingcode">pairingcode</a></li>
@ -844,6 +880,14 @@ sub LGTV_IP12_html2txt($)
Optionales Attribut zur Deaktivierung des zyklischen Status-Updates. Ein manuelles Update via statusRequest-Befehl ist dennoch m&ouml;glich.
<br><br>
M&ouml;gliche Werte: 0 => zyklische Status-Updates, 1 => keine zyklischen Status-Updates.<br><br>
<li><a name="LGTV_IP12_disabledForIntervals">disabledForIntervals</a> HH:MM-HH:MM HH:MM-HH-MM...</li>
Optionales Attribut zur Deaktivierung der zyklischen Status-Updates innerhalb von bestimmten Zeitintervallen.
Das Argument ist eine Leerzeichen-getrennte Liste von Minuszeichen-getrennten HH:MM Paaren (Stunde : Minute).
Falls die aktuelle Uhrzeit zwischen diese Werte f&auml;llt, dann werden zyklische Status-Updates, wie bei <a href="#LGTV_IP12_disable">disable</a>, ausgesetzt.
Statt HH:MM kann man auch HH oder HH:MM:SS angeben.<br><br>
Um einen Intervall um Mitternacht zu spezifizieren, muss man zwei einzelne Intervalle angeben, z.Bsp.:
<pre>23:00-24:00 00:00-01:00</pre>
Standardwert ist <i>nicht gesetzt</i> (dauerhaft aktiv)<br><br>
<li><a name="LGTV_IP12_request-timeout">request-timeout</a></li>
Optionales Attribut. Maximale Dauer einer Anfrage in Sekunden zum TV.
<br><br>