mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-08 01:14:19 +00:00
PHTV: add sequential query and fix issue from forum post #27681
git-svn-id: https://svn.fhem.de/fhem/trunk@6890 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
3bf2bbbbff
commit
b725f47bec
@ -24,7 +24,7 @@
|
|||||||
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
|
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Version: 1.2.4
|
# Version: 1.2.5
|
||||||
#
|
#
|
||||||
# Major Version History:
|
# Major Version History:
|
||||||
# - 1.2.0 - 2014-03-12
|
# - 1.2.0 - 2014-03-12
|
||||||
@ -76,7 +76,7 @@ sub PHTV_Initialize($) {
|
|||||||
$hash->{UndefFn} = "PHTV_Undefine";
|
$hash->{UndefFn} = "PHTV_Undefine";
|
||||||
|
|
||||||
$hash->{AttrList} =
|
$hash->{AttrList} =
|
||||||
"disable:0,1 timeout inputs ambiHueLeft ambiHueRight ambiHueTop ambiHueBottom ambiHueLatency:150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000 "
|
"disable:0,1 timeout sequentialQuery:0,1 inputs ambiHueLeft ambiHueRight ambiHueTop ambiHueBottom ambiHueLatency:150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000 "
|
||||||
. $readingFnAttributes;
|
. $readingFnAttributes;
|
||||||
|
|
||||||
$data{RC_layout}{PHTV_SVG} = "PHTV_RClayout_SVG";
|
$data{RC_layout}{PHTV_SVG} = "PHTV_RClayout_SVG";
|
||||||
@ -92,8 +92,11 @@ sub PHTV_Initialize($) {
|
|||||||
#####################################
|
#####################################
|
||||||
sub PHTV_GetStatus($;$) {
|
sub PHTV_GetStatus($;$) {
|
||||||
my ( $hash, $update ) = @_;
|
my ( $hash, $update ) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $interval = $hash->{INTERVAL};
|
my $interval = $hash->{INTERVAL};
|
||||||
|
my $sequential = ( defined( $attr{$name}{sequentialQuery} )
|
||||||
|
&& $attr{$name}{sequentialQuery} == 1 ) ? 1 : 0;
|
||||||
|
my $querySent = 0;
|
||||||
|
|
||||||
Log3 $name, 5, "PHTV $name: called function PHTV_GetStatus()";
|
Log3 $name, 5, "PHTV $name: called function PHTV_GetStatus()";
|
||||||
|
|
||||||
@ -108,65 +111,98 @@ sub PHTV_GetStatus($;$) {
|
|||||||
if ( defined( $attr{$name}{disable} ) && $attr{$name}{disable} == 1 );
|
if ( defined( $attr{$name}{disable} ) && $attr{$name}{disable} == 1 );
|
||||||
|
|
||||||
# try to fetch only some information to check device availability
|
# try to fetch only some information to check device availability
|
||||||
PHTV_SendCommand( $hash, "audio/volume" ) if ( !$update );
|
if ( !$update ) {
|
||||||
|
PHTV_SendCommand( $hash, "audio/volume" );
|
||||||
|
|
||||||
|
# in case we should query the device gently, mark we already sent a query
|
||||||
|
$querySent = 1 if $sequential;
|
||||||
|
$hash->{helper}{sequentialQueryCounter} = 1 if $sequential;
|
||||||
|
}
|
||||||
|
|
||||||
# fetch other info if device is on
|
# fetch other info if device is on
|
||||||
if (
|
if (
|
||||||
(
|
!$querySent
|
||||||
defined( $hash->{READINGS}{state}{VAL} )
|
&& (
|
||||||
&& $hash->{READINGS}{state}{VAL} eq "on"
|
(
|
||||||
|
defined( $hash->{READINGS}{state}{VAL} )
|
||||||
|
&& $hash->{READINGS}{state}{VAL} eq "on"
|
||||||
|
)
|
||||||
|
|| $update
|
||||||
)
|
)
|
||||||
|| $update
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
# Read device info every 15 minutes only
|
# Read device info every 15 minutes only
|
||||||
if ( !defined( $hash->{helper}{lastFullUpdate} )
|
if (
|
||||||
|| ( !$update && $hash->{helper}{lastFullUpdate} + 900 le time() ) )
|
!$querySent
|
||||||
|
&& (
|
||||||
|
!defined( $hash->{helper}{lastFullUpdate} )
|
||||||
|
|| ( !$update
|
||||||
|
&& $hash->{helper}{lastFullUpdate} + 900 le time() )
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
PHTV_SendCommand( $hash, "system" );
|
PHTV_SendCommand( $hash, "system" );
|
||||||
PHTV_SendCommand( $hash, "ambilight/topology" );
|
PHTV_SendCommand( $hash, "ambilight/topology" );
|
||||||
|
$querySent = 1 if $sequential;
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
|
|
||||||
# Update state
|
# Update state
|
||||||
$hash->{helper}{lastFullUpdate} = time();
|
$hash->{helper}{lastFullUpdate} = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# read ambilight details
|
||||||
|
if ( !$querySent ) {
|
||||||
|
|
||||||
|
# read ambilight mode
|
||||||
|
PHTV_SendCommand( $hash, "ambilight/mode" );
|
||||||
|
$querySent = 1 if $sequential;
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
|
|
||||||
|
# read ambilight RGB value
|
||||||
|
PHTV_SendCommand( $hash, "ambilight/cached" )
|
||||||
|
if ( defined( $hash->{READINGS}{ambiMode}{VAL} )
|
||||||
|
&& $hash->{READINGS}{ambiMode}{VAL} ne "internal" );
|
||||||
|
}
|
||||||
|
|
||||||
# read all sources if not existing
|
# read all sources if not existing
|
||||||
if ( !defined( $hash->{helper}{device}{sourceName} )
|
if (
|
||||||
|| !defined( $hash->{helper}{device}{sourceID} ) )
|
!$querySent
|
||||||
|
&& ( !defined( $hash->{helper}{device}{sourceName} )
|
||||||
|
|| !defined( $hash->{helper}{device}{sourceID} ) )
|
||||||
|
)
|
||||||
{
|
{
|
||||||
PHTV_SendCommand( $hash, "sources" );
|
PHTV_SendCommand( $hash, "sources" );
|
||||||
|
$querySent = 1 if $sequential;
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
}
|
}
|
||||||
|
|
||||||
# otherwise read current source
|
# otherwise read current source
|
||||||
else {
|
elsif ( !$querySent ) {
|
||||||
PHTV_SendCommand( $hash, "sources/current" );
|
PHTV_SendCommand( $hash, "sources/current" );
|
||||||
|
$querySent = 1 if $sequential;
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
}
|
}
|
||||||
|
|
||||||
# read all channels if not existing
|
# read all channels if not existing
|
||||||
if ( !defined( $hash->{helper}{device}{channelName} )
|
if (
|
||||||
|| !defined( $hash->{helper}{device}{channelID} ) )
|
!$querySent
|
||||||
|
&& ( !defined( $hash->{helper}{device}{channelName} )
|
||||||
|
|| !defined( $hash->{helper}{device}{channelID} ) )
|
||||||
|
)
|
||||||
{
|
{
|
||||||
PHTV_SendCommand( $hash, "channels" );
|
PHTV_SendCommand( $hash, "channels" );
|
||||||
|
$querySent = 1 if $sequential;
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
}
|
}
|
||||||
|
|
||||||
# otherwise read current channel
|
# otherwise read current channel
|
||||||
else {
|
elsif ( !$querySent ) {
|
||||||
PHTV_SendCommand( $hash, "channels/current" );
|
PHTV_SendCommand( $hash, "channels/current" );
|
||||||
|
$querySent = 1 if $sequential;
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
}
|
}
|
||||||
|
|
||||||
# read all channellists if not existing
|
|
||||||
if ( !defined( $hash->{helper}{device}{channellists} ) ) {
|
|
||||||
PHTV_SendCommand( $hash, "channellists" );
|
|
||||||
}
|
|
||||||
|
|
||||||
# read ambilight mode
|
|
||||||
PHTV_SendCommand( $hash, "ambilight/mode" );
|
|
||||||
|
|
||||||
# read ambilight RGB value
|
|
||||||
PHTV_SendCommand( $hash, "ambilight/cached" )
|
|
||||||
if ( defined( $hash->{READINGS}{ambiMode}{VAL} )
|
|
||||||
&& $hash->{READINGS}{ambiMode}{VAL} ne "internal" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Input alias handling
|
# Input alias handling
|
||||||
@ -279,9 +315,12 @@ sub PHTV_Set($@) {
|
|||||||
my $count = scalar( keys %{ $hash->{helper}{device}{channelPreset} } );
|
my $count = scalar( keys %{ $hash->{helper}{device}{channelPreset} } );
|
||||||
$count = 80 if ( $count > 80 );
|
$count = 80 if ( $count > 80 );
|
||||||
while ( $i <= $count ) {
|
while ( $i <= $count ) {
|
||||||
|
if ( defined($hash->{helper}{device}{channelPreset}{$i}{name}) &&
|
||||||
|
$hash->{helper}{device}{channelPreset}{$i}{name} != "" ) {
|
||||||
$channels .=
|
$channels .=
|
||||||
$hash->{helper}{device}{channelPreset}{$i}{name} . ",";
|
$hash->{helper}{device}{channelPreset}{$i}{name} . ",";
|
||||||
$i++;
|
}
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( $channel ne ""
|
if ( $channel ne ""
|
||||||
@ -955,7 +994,7 @@ sub PHTV_Set($@) {
|
|||||||
Log3 $name, 2, "PHTV set $name " . $a[1];
|
Log3 $name, 2, "PHTV set $name " . $a[1];
|
||||||
|
|
||||||
if ( $hash->{READINGS}{state}{VAL} eq "on" ) {
|
if ( $hash->{READINGS}{state}{VAL} eq "on" ) {
|
||||||
if ( lc( $a[1] ) eq "volumeUp" ) {
|
if ( lc( $a[1] ) eq "volumeup" ) {
|
||||||
$cmd = PHTV_GetRemotecontrolCommand("VOLUP");
|
$cmd = PHTV_GetRemotecontrolCommand("VOLUP");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1359,10 +1398,12 @@ sub PHTV_SendCommand($$;$$) {
|
|||||||
###################################
|
###################################
|
||||||
sub PHTV_ReceiveCommand($$$) {
|
sub PHTV_ReceiveCommand($$$) {
|
||||||
my ( $param, $err, $data ) = @_;
|
my ( $param, $err, $data ) = @_;
|
||||||
my $hash = $param->{hash};
|
my $hash = $param->{hash};
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $service = $param->{service};
|
my $service = $param->{service};
|
||||||
my $cmd = $param->{cmd};
|
my $cmd = $param->{cmd};
|
||||||
|
my $sequential = ( defined( $attr{$name}{sequentialQuery} )
|
||||||
|
&& $attr{$name}{sequentialQuery} == 1 ) ? 1 : 0;
|
||||||
|
|
||||||
my $state =
|
my $state =
|
||||||
( $hash->{READINGS}{state}{VAL} )
|
( $hash->{READINGS}{state}{VAL} )
|
||||||
@ -1564,7 +1605,10 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $newstate eq "on" && $newstate ne $state ) {
|
# trigger query cascade in case the device just came up or sequential query is enabled
|
||||||
|
if ( $sequential
|
||||||
|
|| ( $newstate eq "on" && $newstate ne $state ) )
|
||||||
|
{
|
||||||
PHTV_GetStatus( $hash, 1 );
|
PHTV_GetStatus( $hash, 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1642,6 +1686,9 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
$hash->{model} = $return->{model};
|
$hash->{model} = $return->{model};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# continue query cascade in case sequential query is enabled
|
||||||
|
PHTV_GetStatus( $hash, 1 ) if $sequential;
|
||||||
}
|
}
|
||||||
|
|
||||||
# sources
|
# sources
|
||||||
@ -1668,6 +1715,7 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PHTV_SendCommand( $hash, "sources/current" );
|
PHTV_SendCommand( $hash, "sources/current" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1702,6 +1750,24 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
readingsBulkUpdate( $hash, "input", $cmd );
|
readingsBulkUpdate( $hash, "input", $cmd );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# SEQUENTIAL QUERY CASCADE - next: channels
|
||||||
|
# read all channels if not existing
|
||||||
|
if (
|
||||||
|
$sequential
|
||||||
|
&& ( !defined( $hash->{helper}{device}{channelName} )
|
||||||
|
|| !defined( $hash->{helper}{device}{channelID} ) )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PHTV_SendCommand( $hash, "channels" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++;
|
||||||
|
}
|
||||||
|
|
||||||
|
# otherwise read current channel
|
||||||
|
elsif ($sequential) {
|
||||||
|
PHTV_SendCommand( $hash, "channels/current" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# channels
|
# channels
|
||||||
@ -1738,6 +1804,7 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PHTV_SendCommand( $hash, "channels/current" );
|
PHTV_SendCommand( $hash, "channels/current" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1764,8 +1831,17 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
readingsBulkUpdate( $hash, "channel", $cmd );
|
readingsBulkUpdate( $hash, "channel", $cmd );
|
||||||
}
|
}
|
||||||
|
|
||||||
PHTV_SendCommand( $hash, "channels/" . $return->{id} )
|
# read channel details if type is known
|
||||||
if ( defined( $return->{id} ) && $return->{id} ne "" );
|
if ( defined( $return->{id} ) && $return->{id} ne "" ) {
|
||||||
|
PHTV_SendCommand( $hash, "channels/" . $return->{id} );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
|
}
|
||||||
|
|
||||||
|
# read all channellists if not existing
|
||||||
|
elsif ( !defined( $hash->{helper}{device}{channellists} ) ) {
|
||||||
|
PHTV_SendCommand( $hash, "channellists" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elsif ( $return eq "ok" ) {
|
elsif ( $return eq "ok" ) {
|
||||||
$cmd =
|
$cmd =
|
||||||
@ -1779,8 +1855,17 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
readingsBulkUpdate( $hash, "channel", $cmd );
|
readingsBulkUpdate( $hash, "channel", $cmd );
|
||||||
}
|
}
|
||||||
|
|
||||||
PHTV_SendCommand( $hash, "channels/" . $type )
|
# read channel details if type is known
|
||||||
if ( defined($type) && $type ne "" );
|
if ( defined($type) && $type ne "" ) {
|
||||||
|
PHTV_SendCommand( $hash, "channels/" . $type );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
|
}
|
||||||
|
|
||||||
|
# read all channellists if not existing
|
||||||
|
elsif ( !defined( $hash->{helper}{device}{channellists} ) ) {
|
||||||
|
PHTV_SendCommand( $hash, "channellists" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1915,6 +2000,12 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# read all channellists if not existing
|
||||||
|
if ( !defined( $hash->{helper}{device}{channellists} ) ) {
|
||||||
|
PHTV_SendCommand( $hash, "channellists" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# channellists
|
# channellists
|
||||||
@ -1930,6 +2021,7 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
PHTV_SendCommand( $hash, "channellists/$item", undef,
|
PHTV_SendCommand( $hash, "channellists/$item", undef,
|
||||||
$item );
|
$item );
|
||||||
}
|
}
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++ if $sequential;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2048,6 +2140,24 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
readingsBulkUpdate( $hash, "ambiMode", $type );
|
readingsBulkUpdate( $hash, "ambiMode", $type );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# SEQUENTIAL QUERY CASCADE - next: sources
|
||||||
|
# read all sources if not existing
|
||||||
|
if (
|
||||||
|
$sequential
|
||||||
|
&& ( !defined( $hash->{helper}{device}{sourceName} )
|
||||||
|
|| !defined( $hash->{helper}{device}{sourceID} ) )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PHTV_SendCommand( $hash, "sources" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++;
|
||||||
|
}
|
||||||
|
|
||||||
|
# otherwise read current source
|
||||||
|
elsif ($sequential) {
|
||||||
|
PHTV_SendCommand( $hash, "sources/current" );
|
||||||
|
$hash->{helper}{sequentialQueryCounter}++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# ambilight/cached (rgb)
|
# ambilight/cached (rgb)
|
||||||
@ -2373,11 +2483,11 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
my $satF =
|
my $satF =
|
||||||
( $sat && $sat > 0 && $sat < 100 )
|
( $sat && $sat > 0 && $sat < 100 )
|
||||||
? $sat / 100
|
? $sat / 100
|
||||||
: 1;
|
: 0;
|
||||||
my $briF =
|
my $briF =
|
||||||
( $bri && $bri > 0 && $bri < 100 )
|
( $bri && $bri > 0 && $bri < 100 )
|
||||||
? $bri / 100
|
? $bri / 100
|
||||||
: 1;
|
: 0;
|
||||||
|
|
||||||
my ( $hDec, $sDec, $bDec, $h, $s, $b );
|
my ( $hDec, $sDec, $bDec, $h, $s, $b );
|
||||||
if ( $countLEDs > 0 ) {
|
if ( $countLEDs > 0 ) {
|
||||||
@ -2745,6 +2855,11 @@ sub PHTV_ReceiveCommand($$$) {
|
|||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
Log3 $name, 4,
|
||||||
|
"PHTV $name: sequentialQuery - finished round "
|
||||||
|
. $hash->{helper}{sequentialQueryCounter}
|
||||||
|
if $sequential;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3309,6 +3424,7 @@ sub PHTV_min {
|
|||||||
<li><b>ambiHueLatency</b> - Controls the update interval for HUE devices in milliseconds; defaults to 200 ms.</li>
|
<li><b>ambiHueLatency</b> - Controls the update interval for HUE devices in milliseconds; defaults to 200 ms.</li>
|
||||||
<li><b>disable</b> - Disable polling (true/false)</li>
|
<li><b>disable</b> - Disable polling (true/false)</li>
|
||||||
<li><b>inputs</b> - Presents the inputs read from device. Inputs can be renamed by adding <code>,NewName</code> right after the original name.</li>
|
<li><b>inputs</b> - Presents the inputs read from device. Inputs can be renamed by adding <code>,NewName</code> right after the original name.</li>
|
||||||
|
<li><b>sequentialQuery</b> - avoid parallel queries for low-performance devices</li>
|
||||||
<li><b>timeout</b> - Set different polling timeout in seconds (default=7)</li>
|
<li><b>timeout</b> - Set different polling timeout in seconds (default=7)</li>
|
||||||
</ul></ul>
|
</ul></ul>
|
||||||
<br>
|
<br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user