2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-28 11:01:59 +00:00

ENIGMA2: add *_next events, optimize XML fetch and evaluation for readings

git-svn-id: https://svn.fhem.de/fhem/trunk@4544 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2014-01-03 11:41:26 +00:00
parent 6286d4c5da
commit 52b9af4b4c

View File

@ -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.2 # Version: 1.2.3
# #
# Major Version History: # Major Version History:
# - 1.2.0 - 2013-12-21 # - 1.2.0 - 2013-12-21
@ -106,6 +106,7 @@ sub ENIGMA2_GetStatus($;$) {
my $boxinfo; my $boxinfo;
my $serviceinfo; my $serviceinfo;
my $eventinfo; my $eventinfo;
my $currsrvinfo;
my $signalinfo; my $signalinfo;
my $vol; my $vol;
my $changecount = 0; my $changecount = 0;
@ -113,7 +114,7 @@ sub ENIGMA2_GetStatus($;$) {
Log3 $name, 5, "ENIGMA2 $name: called function ENIGMA2_GetStatus()"; Log3 $name, 5, "ENIGMA2 $name: called function ENIGMA2_GetStatus()";
$local = 0 unless ( defined($local) ); $local = 0 unless ( defined($local) );
if ( defined( $attr{$name}{disable} ) && $attr{$name}{disable} eq "1" ) { if ( defined( $attr{$name}{disable} ) && $attr{$name}{disable} == 1 ) {
return $hash->{STATE}; return $hash->{STATE};
} }
@ -314,44 +315,20 @@ sub ENIGMA2_GetStatus($;$) {
else { else {
$state = "on"; $state = "on";
# Read Boxinfo # Read Boxinfo every 10 minutes only
if (
!defined( $hash->{helper}{lastStatusUpdate} )
|| ( defined( $hash->{helper}{lastStatusUpdate} )
&& $hash->{helper}{lastStatusUpdate} + 900 le time() )
)
{
$boxinfo = ENIGMA2_SendCommand( $hash, "about", "" ); $boxinfo = ENIGMA2_SendCommand( $hash, "about", "" );
$serviceinfo = ENIGMA2_SendCommand( $hash, "subservices", "" ); }
$signalinfo = ENIGMA2_SendCommand( $hash, "signal", "" );
# get current states
$currsrvinfo = ENIGMA2_SendCommand( $hash, "getcurrent", "" );
$vol = ENIGMA2_SendCommand( $hash, "vol", "" ); $vol = ENIGMA2_SendCommand( $hash, "vol", "" );
$signalinfo = ENIGMA2_SendCommand( $hash, "signal", "" );
# Read eventinfo
# multiple
if ( ref($serviceinfo) eq "HASH"
&& defined( $serviceinfo->{e2service} )
&& ref( $serviceinfo->{e2service} ) eq "ARRAY"
&& defined( $serviceinfo->{e2service}[0]{e2servicereference} )
&& $serviceinfo->{e2service}[0]{e2servicereference} ne "" )
{
$eventinfo = ENIGMA2_SendCommand(
$hash,
"epgservicenow",
"sRef="
. urlEncode(
$serviceinfo->{e2service}[0]{e2servicereference}
)
);
}
# single
elsif (ref($serviceinfo) eq "HASH"
&& defined( $serviceinfo->{e2service}{e2servicereference} )
&& $serviceinfo->{e2service}{e2servicereference} ne "" )
{
$eventinfo = ENIGMA2_SendCommand(
$hash,
"epgservicenow",
"sRef="
. urlEncode(
$serviceinfo->{e2service}{e2servicereference}
)
);
}
} }
} }
elsif ( $hash->{helper}{AVAILABLE} == 1 ) { elsif ( $hash->{helper}{AVAILABLE} == 1 ) {
@ -363,6 +340,10 @@ sub ENIGMA2_GetStatus($;$) {
$state = "absent"; $state = "absent";
} }
####
# update readings
#
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
# Set reading for power # Set reading for power
@ -374,7 +355,7 @@ sub ENIGMA2_GetStatus($;$) {
if ( !defined( $hash->{READINGS}{power}{VAL} ) if ( !defined( $hash->{READINGS}{power}{VAL} )
|| $hash->{READINGS}{power}{VAL} ne $readingPower ) || $hash->{READINGS}{power}{VAL} ne $readingPower )
{ {
readingsBulkUpdate( $hash, "power", $readingPower, 1 ); readingsBulkUpdate( $hash, "power", $readingPower );
} }
# Set reading for state # Set reading for state
@ -382,24 +363,20 @@ sub ENIGMA2_GetStatus($;$) {
if ( !defined( $hash->{READINGS}{state}{VAL} ) if ( !defined( $hash->{READINGS}{state}{VAL} )
|| $hash->{READINGS}{state}{VAL} ne $state ) || $hash->{READINGS}{state}{VAL} ne $state )
{ {
readingsBulkUpdate( $hash, "state", $state, 1 ); readingsBulkUpdate( $hash, "state", $state );
} }
# Set reading for Boxinfos
#
if ( ref($boxinfo) eq "HASH" ) {
my $reading; my $reading;
my $e2reading; my $e2reading;
# General # Boxinfo
#
if ( ref($boxinfo) eq "HASH" ) {
# General readings
foreach ( foreach (
"enigmaversion", "imageversion", "webifversion", "enigmaversion", "imageversion", "webifversion",
"fpversion", "lanmac", "model", "fpversion", "lanmac", "model",
"servicenamespace", "serviceaspect", "serviceprovider",
"servicevideosize", "videowidth", "videoheight",
"apid", "vpid", "pcrpid",
"servicevideosize", "pmtpid", "txtpid",
"tsid", "onid", "sid"
) )
{ {
$reading = $_; $reading = $_;
@ -414,7 +391,7 @@ sub ENIGMA2_GetStatus($;$) {
lc( $boxinfo->{e2about}{$e2reading} ) ) lc( $boxinfo->{e2about}{$e2reading} ) )
{ {
readingsBulkUpdate( $hash, $reading, readingsBulkUpdate( $hash, $reading,
lc( $boxinfo->{e2about}{$e2reading} ), 1 ); lc( $boxinfo->{e2about}{$e2reading} ) );
} }
} }
else { else {
@ -423,7 +400,7 @@ sub ENIGMA2_GetStatus($;$) {
$boxinfo->{e2about}{$e2reading} ) $boxinfo->{e2about}{$e2reading} )
{ {
readingsBulkUpdate( $hash, $reading, readingsBulkUpdate( $hash, $reading,
$boxinfo->{e2about}{$e2reading}, 1 ); $boxinfo->{e2about}{$e2reading} );
} }
} }
} }
@ -431,41 +408,16 @@ sub ENIGMA2_GetStatus($;$) {
if ( !defined( $hash->{READINGS}{$reading}{VAL} ) if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" ) || $hash->{READINGS}{$reading}{VAL} ne "-" )
{ {
readingsBulkUpdate( $hash, $reading, "-", 1 ); readingsBulkUpdate( $hash, $reading, "-" );
} }
} }
} }
# servicename + channel
$reading = "servicename";
$e2reading = "e2" . $reading;
if ( defined( $boxinfo->{e2about}{$e2reading} ) ) {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne
$boxinfo->{e2about}{$e2reading} )
{
readingsBulkUpdate( $hash, $reading,
$boxinfo->{e2about}{$e2reading}, 1 );
my $channel = $boxinfo->{e2about}{$e2reading};
$channel =~ s/\s/_/g;
readingsBulkUpdate( $hash, "channel", $channel, 1 );
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" )
{
readingsBulkUpdate( $hash, $reading, "-", 1 );
readingsBulkUpdate( $hash, "channel", "-", 1 );
}
}
# HDD # HDD
if ( defined( $boxinfo->{e2about}{e2hddinfo} ) ) {
# multiple # multiple
if ( defined( $boxinfo->{e2about}{e2hddinfo} ) if ( ref( $boxinfo->{e2about}{e2hddinfo} ) eq "ARRAY" ) {
&& ref( $boxinfo->{e2about}{e2hddinfo} ) eq "ARRAY" )
{
my $i = 0; my $i = 0;
my $arr_size = @{ $boxinfo->{e2about}{e2hddinfo} }; my $arr_size = @{ $boxinfo->{e2about}{e2hddinfo} };
@ -477,19 +429,21 @@ sub ENIGMA2_GetStatus($;$) {
$boxinfo->{e2about}{e2hddinfo}[$i]{model} ) $boxinfo->{e2about}{e2hddinfo}[$i]{model} )
{ {
readingsBulkUpdate( $hash, $readingname, readingsBulkUpdate( $hash, $readingname,
$boxinfo->{e2about}{e2hddinfo}[$i]{model}, 1 ); $boxinfo->{e2about}{e2hddinfo}[$i]{model} );
} }
$readingname = "hdd" . $counter . "_capacity"; $readingname = "hdd" . $counter . "_capacity";
my @value = my @value =
split( / /, $boxinfo->{e2about}{e2hddinfo}[$i]{capacity} ); split( / /,
$boxinfo->{e2about}{e2hddinfo}[$i]{capacity} );
if ( if (
!defined( $hash->{READINGS}{$readingname}{VAL} ) !defined( $hash->{READINGS}{$readingname}{VAL} )
|| ( ref(@value) eq "ARRAY" || ( ref(@value) eq "ARRAY"
&& $hash->{READINGS}{$readingname}{VAL} ne $value[0] ) && $hash->{READINGS}{$readingname}{VAL} ne
$value[0] )
) )
{ {
readingsBulkUpdate( $hash, $readingname, $value[0], 1 ); readingsBulkUpdate( $hash, $readingname, $value[0] );
} }
$readingname = "hdd" . $counter . "_free"; $readingname = "hdd" . $counter . "_free";
@ -498,28 +452,26 @@ sub ENIGMA2_GetStatus($;$) {
if ( if (
!defined( $hash->{READINGS}{$readingname}{VAL} ) !defined( $hash->{READINGS}{$readingname}{VAL} )
|| ( ref(@value) eq "ARRAY" || ( ref(@value) eq "ARRAY"
&& $hash->{READINGS}{$readingname}{VAL} ne $value[0] ) && $hash->{READINGS}{$readingname}{VAL} ne
$value[0] )
) )
{ {
readingsBulkUpdate( $hash, $readingname, $value[0], 1 ); readingsBulkUpdate( $hash, $readingname, $value[0] );
} }
$i++; $i++;
} }
} }
# single # single
elsif ( defined( $boxinfo->{e2about}{e2hddinfo} ) elsif ( ref( $boxinfo->{e2about}{e2hddinfo} ) eq "HASH" ) {
&& ref( $boxinfo->{e2about}{e2hddinfo} ) eq "HASH" )
{
my $readingname = "hdd1_model"; my $readingname = "hdd1_model";
if ( !defined( $hash->{READINGS}{$readingname}{VAL} ) if ( !defined( $hash->{READINGS}{$readingname}{VAL} )
|| $hash->{READINGS}{$readingname}{VAL} ne || $hash->{READINGS}{$readingname}{VAL} ne
$boxinfo->{e2about}{e2hddinfo}{model} ) $boxinfo->{e2about}{e2hddinfo}{model} )
{ {
readingsBulkUpdate( $hash, $readingname, readingsBulkUpdate( $hash, $readingname,
$boxinfo->{e2about}{e2hddinfo}{model}, 1 ); $boxinfo->{e2about}{e2hddinfo}{model} );
} }
$readingname = "hdd1_capacity"; $readingname = "hdd1_capacity";
@ -531,7 +483,7 @@ sub ENIGMA2_GetStatus($;$) {
&& $hash->{READINGS}{$readingname}{VAL} ne $value[0] ) && $hash->{READINGS}{$readingname}{VAL} ne $value[0] )
) )
{ {
readingsBulkUpdate( $hash, $readingname, $value[0], 1 ); readingsBulkUpdate( $hash, $readingname, $value[0] );
} }
$readingname = "hdd1_free"; $readingname = "hdd1_free";
@ -542,7 +494,8 @@ sub ENIGMA2_GetStatus($;$) {
&& $hash->{READINGS}{$readingname}{VAL} ne $value[0] ) && $hash->{READINGS}{$readingname}{VAL} ne $value[0] )
) )
{ {
readingsBulkUpdate( $hash, $readingname, $value[0], 1 ); readingsBulkUpdate( $hash, $readingname, $value[0] );
}
} }
} }
@ -559,8 +512,7 @@ sub ENIGMA2_GetStatus($;$) {
if ( !defined( $hash->{READINGS}{$tuner_name}{VAL} ) if ( !defined( $hash->{READINGS}{$tuner_name}{VAL} )
|| $hash->{READINGS}{$tuner_name}{VAL} ne $$tunerRef{type} ) || $hash->{READINGS}{$tuner_name}{VAL} ne $$tunerRef{type} )
{ {
readingsBulkUpdate( $hash, $tuner_name, readingsBulkUpdate( $hash, $tuner_name, $$tunerRef{type} );
$$tunerRef{type}, 1 );
} }
} }
@ -575,19 +527,272 @@ sub ENIGMA2_GetStatus($;$) {
if ( !defined( $hash->{READINGS}{$tuner_name}{VAL} ) if ( !defined( $hash->{READINGS}{$tuner_name}{VAL} )
|| $hash->{READINGS}{$tuner_name}{VAL} ne $tuner_type ) || $hash->{READINGS}{$tuner_name}{VAL} ne $tuner_type )
{ {
readingsBulkUpdate( $hash, $tuner_name, readingsBulkUpdate( $hash, $tuner_name, $tuner_type );
$tuner_type, 1 ); }
}
}
}
}
# Service and Event information
#
if ( ref($currsrvinfo) eq "HASH" ) {
my $reading;
my $e2reading;
# Service readings
foreach (
"servicereference", "servicename", "providername",
"servicevideosize", "videowidth", "videoheight",
"iswidescreen", "apid", "vpid",
"pcrpid", "pmtpid", "txtpid",
"tsid", "onid", "sid"
)
{
$reading = $_;
$e2reading = "e2" . $_;
if ( defined( $currsrvinfo->{e2service}{$e2reading} )
&& lc( $currsrvinfo->{e2service}{$e2reading} ) ne "n/a"
&& lc( $currsrvinfo->{e2service}{$e2reading} ) ne "n/axn/a" )
{
if ( $currsrvinfo->{e2service}{$e2reading} eq "False"
|| $currsrvinfo->{e2service}{$e2reading} eq "True" )
{
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne
lc( $currsrvinfo->{e2service}{$e2reading} ) )
{
readingsBulkUpdate( $hash, $reading,
lc( $currsrvinfo->{e2service}{$e2reading} ) );
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne
$currsrvinfo->{e2service}{$e2reading} )
{
readingsBulkUpdate( $hash, $reading,
$currsrvinfo->{e2service}{$e2reading} );
# channel
if ( $reading eq "servicename" ) {
my $val = $currsrvinfo->{e2service}{$e2reading};
$val =~ s/\s/_/g;
readingsBulkUpdate( $hash, "channel", $val );
}
# currentMedia
readingsBulkUpdate( $hash, "currentMedia",
$currsrvinfo->{e2service}{$e2reading} )
if $reading eq "servicereference";
}
}
# input
if ( $reading eq "servicereference" ) {
my @servicetype =
split( /:/, $currsrvinfo->{e2service}{$e2reading} );
if ( defined( $servicetype[2] )
&& $servicetype[2] eq "2" )
{
$hash->{helper}{lastInput} = "radio";
readingsBulkUpdate( $hash, "input", "radio" );
}
else {
$hash->{helper}{lastInput} = "tv";
readingsBulkUpdate( $hash, "input", "tv" );
}
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" )
{
readingsBulkUpdate( $hash, $reading, "-" );
# channel
readingsBulkUpdate( $hash, "channel", "-" )
if $reading eq "servicename";
# currentMedia
readingsBulkUpdate( $hash, "currentMedia", "-" )
if $reading eq "servicereference";
}
}
}
# Event readings
#
if ( defined( $currsrvinfo->{e2eventlist} ) ) {
my $eventNow;
my $eventNext;
if ( ref( $currsrvinfo->{e2eventlist}{e2event} ) eq "ARRAY" ) {
$eventNow = $currsrvinfo->{e2eventlist}{e2event}[0];
$eventNext = $currsrvinfo->{e2eventlist}{e2event}[1]
if ( defined( $currsrvinfo->{e2eventlist}{e2event}[1] ) );
}
else {
$eventNow = $currsrvinfo->{e2eventlist}{e2event};
}
foreach (
"eventstart", "eventduration", "eventremaining",
"eventcurrenttime", "eventdescription", "eventtitle",
"eventname",
)
{
$reading = $_;
$e2reading = "e2" . $_;
# current event
if ( defined( $eventNow->{$e2reading} )
&& lc( $eventNow->{$e2reading} ) ne "n/a"
&& $eventNow->{$e2reading} ne "0"
&& $eventNow->{$e2reading} ne "" )
{
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne
$eventNow->{$e2reading} )
{
readingsBulkUpdate( $hash, $reading,
$eventNow->{$e2reading} );
# currentTitle
readingsBulkUpdate( $hash, "currentTitle",
$eventNow->{$e2reading} )
if $reading eq "eventtitle";
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" )
{
readingsBulkUpdate( $hash, $reading, "-" );
# currentTitle
readingsBulkUpdate( $hash, "currentTitle", "-" )
if $reading eq "eventtitle";
}
}
# next event
$reading = $_ . "_next";
if ( defined( $eventNext->{$e2reading} )
&& lc( $eventNext->{$e2reading} ) ne "n/a"
&& $eventNext->{$e2reading} ne "0"
&& $eventNext->{$e2reading} ne "" )
{
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne
$eventNext->{$e2reading} )
{
readingsBulkUpdate( $hash, $reading,
$eventNext->{$e2reading} );
# nextTitle
readingsBulkUpdate( $hash, "nextTitle",
$eventNext->{$e2reading} )
if $reading eq "eventtitle_next";
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" )
{
readingsBulkUpdate( $hash, $reading, "-" );
# nextTitle
readingsBulkUpdate( $hash, "nextTitle", "-" )
if $reading eq "eventtitle_next";
}
}
}
# convert date+time into human readable formats
foreach (
"eventstart", "eventcurrenttime",
"eventduration", "eventremaining"
)
{
$reading = $_ . "_hr";
$e2reading = "e2" . $_;
# current event
if ( defined( $eventNow->{$e2reading} )
&& $eventNow->{$e2reading} ne "0"
&& $eventNow->{$e2reading} ne "" )
{
my $timestring;
if ( $_ eq "eventduration"
|| $_ eq "eventremaining" )
{
my @t = localtime( $eventNow->{$e2reading} );
$timestring =
sprintf( "%02d:%02d:%02d", $t[2] - 1, $t[1], $t[0] );
}
else {
$timestring =
substr( FmtDateTime( $eventNow->{$e2reading} ), 11 );
}
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne $timestring )
{
readingsBulkUpdate( $hash, $reading, $timestring );
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" )
{
readingsBulkUpdate( $hash, $reading, "-" );
}
}
# next event
$reading = $_ . "_next_hr";
if ( defined( $eventNext->{$e2reading} )
&& $eventNext->{$e2reading} ne "0"
&& $eventNext->{$e2reading} ne "" )
{
my $timestring;
if ( $_ eq "eventduration"
|| $_ eq "eventremaining" )
{
my @t = localtime( $eventNext->{$e2reading} );
$timestring =
sprintf( "%02d:%02d:%02d", $t[2] - 1, $t[1], $t[0] );
}
else {
$timestring =
substr( FmtDateTime( $eventNext->{$e2reading} ), 11 );
}
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne $timestring )
{
readingsBulkUpdate( $hash, $reading, $timestring );
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" )
{
readingsBulkUpdate( $hash, $reading, "-" );
}
} }
} }
} }
} }
# Volume # Volume
#
if ( ref($vol) eq "HASH" && defined( $vol->{e2current} ) ) { if ( ref($vol) eq "HASH" && defined( $vol->{e2current} ) ) {
if ( !defined( $hash->{READINGS}{volume}{VAL} ) if ( !defined( $hash->{READINGS}{volume}{VAL} )
|| $hash->{READINGS}{volume}{VAL} ne $vol->{e2current} ) || $hash->{READINGS}{volume}{VAL} ne $vol->{e2current} )
{ {
readingsBulkUpdate( $hash, "volume", $vol->{e2current}, 1 ); readingsBulkUpdate( $hash, "volume", $vol->{e2current} );
} }
} }
if ( ref($vol) eq "HASH" && defined( $vol->{e2ismuted} ) ) { if ( ref($vol) eq "HASH" && defined( $vol->{e2ismuted} ) ) {
@ -598,175 +803,12 @@ sub ENIGMA2_GetStatus($;$) {
if ( !defined( $hash->{READINGS}{mute}{VAL} ) if ( !defined( $hash->{READINGS}{mute}{VAL} )
|| $hash->{READINGS}{mute}{VAL} ne $muteState ) || $hash->{READINGS}{mute}{VAL} ne $muteState )
{ {
readingsBulkUpdate( $hash, "mute", $muteState, 1 ); readingsBulkUpdate( $hash, "mute", $muteState );
}
}
# servicereference + input + currentMedia
# multiple
if ( ref($serviceinfo) eq "HASH"
&& defined( $serviceinfo->{e2service} )
&& ref( $serviceinfo->{e2service} ) eq "ARRAY" )
{
if ( $serviceinfo->{e2service}[0]{e2servicereference} ne "" ) {
if ( !defined( $hash->{READINGS}{servicereference}{VAL} )
|| $hash->{READINGS}{servicereference}{VAL} ne
$serviceinfo->{e2service}[0]{e2servicereference} )
{
readingsBulkUpdate( $hash, "servicereference",
$serviceinfo->{e2service}[0]{e2servicereference}, 1 );
readingsBulkUpdate( $hash, "currentMedia",
$serviceinfo->{e2service}[0]{e2servicereference}, 1 );
my @servicetype = split( /:/,
$serviceinfo->{e2service}[0]{e2servicereference} );
if ( defined( $servicetype[2] )
&& $servicetype[2] eq "2" )
{
$hash->{helper}{lastInput} = "radio";
readingsBulkUpdate( $hash, "input", "radio", 1 );
}
else {
$hash->{helper}{lastInput} = "tv";
readingsBulkUpdate( $hash, "input", "tv", 1 );
}
}
}
elsif ( $hash->{READINGS}{servicereference}{VAL} ne "-" ) {
readingsBulkUpdate( $hash, "servicereference", "-", 1 );
readingsBulkUpdate( $hash, "currentMedia", "-", 1 );
}
}
# single
elsif ( ref($serviceinfo) eq "HASH"
&& defined( $serviceinfo->{e2service} ) )
{
if ( $serviceinfo->{e2service}{e2servicereference} ne "" ) {
if ( !defined( $hash->{READINGS}{servicereference}{VAL} )
|| $hash->{READINGS}{servicereference}{VAL} ne
$serviceinfo->{e2service}{e2servicereference} )
{
readingsBulkUpdate( $hash, "servicereference",
$serviceinfo->{e2service}{e2servicereference}, 1 );
readingsBulkUpdate( $hash, "currentMedia",
$serviceinfo->{e2service}{e2servicereference}, 1 );
my @servicetype =
split( /:/,
$serviceinfo->{e2service}{e2servicereference} );
if ( defined( $servicetype[2] )
&& $servicetype[2] eq "2" )
{
$hash->{helper}{lastInput} = "radio";
readingsBulkUpdate( $hash, "input", "radio", 1 );
}
else {
$hash->{helper}{lastInput} = "tv";
readingsBulkUpdate( $hash, "input", "tv", 1 );
}
}
}
elsif ( $hash->{READINGS}{servicereference}{VAL} ne "-" ) {
readingsBulkUpdate( $hash, "servicereference", "-", 1 );
readingsBulkUpdate( $hash, "currentMedia", "-", 1 );
}
}
# Event
if ( ref($eventinfo) eq "HASH" && defined( $eventinfo->{e2event} ) ) {
foreach (
"eventstart", "eventduration",
"eventcurrenttime", "eventdescription",
)
{
$reading = $_;
$e2reading = "e2" . $_;
if ( defined( $eventinfo->{e2event}{$e2reading} ) ) {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne
$eventinfo->{e2event}{$e2reading} )
{
readingsBulkUpdate( $hash, $reading,
$eventinfo->{e2event}{$e2reading}, 1 );
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" )
{
readingsBulkUpdate( $hash, $reading, "-", 1 );
}
}
}
# eventtitle + currentTitle
$reading = "eventtitle";
$e2reading = "e2" . $reading;
if ( defined( $eventinfo->{e2event}{$e2reading} )
&& $eventinfo->{e2event}{$e2reading} ne "N/A" )
{
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne
$eventinfo->{e2event}{$e2reading} )
{
readingsBulkUpdate( $hash, $reading,
$eventinfo->{e2event}{$e2reading}, 1 );
readingsBulkUpdate( $hash, "currentTitle",
$eventinfo->{e2event}{$e2reading}, 1 );
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne
$boxinfo->{e2about}{e2servicename} )
{
readingsBulkUpdate( $hash, $reading,
$boxinfo->{e2about}{e2servicename}, 1 );
readingsBulkUpdate( $hash, "currentTitle",
$boxinfo->{e2about}{e2servicename}, 1 );
}
}
# convert date+time into human readable formats
foreach ( "eventstart", "eventcurrenttime", "eventduration" ) {
$reading = $_ . "_hr";
$e2reading = "e2" . $_;
if ( defined( $eventinfo->{e2event}{$e2reading} )
&& $eventinfo->{e2event}{$e2reading} ne "0" )
{
my $timestring;
if ( $_ eq "eventduration" ) {
my @t = localtime( $eventinfo->{e2event}{$e2reading} );
$timestring =
sprintf( "%02d:%02d:%02d", $t[2] - 1, $t[1], $t[0] );
}
else {
$timestring =
substr(
FmtDateTime( $eventinfo->{e2event}{$e2reading} ),
11 );
}
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne $timestring )
{
readingsBulkUpdate( $hash, $reading, $timestring, 1 );
}
}
else {
if ( !defined( $hash->{READINGS}{$reading}{VAL} )
|| $hash->{READINGS}{$reading}{VAL} ne "-" )
{
readingsBulkUpdate( $hash, $reading, "-", 1 );
}
}
} }
} }
# Signal # Signal
#
if ( ref($signalinfo) eq "HASH" if ( ref($signalinfo) eq "HASH"
&& defined( $signalinfo->{e2snrdb} ) ) && defined( $signalinfo->{e2snrdb} ) )
{ {
@ -774,69 +816,82 @@ sub ENIGMA2_GetStatus($;$) {
$reading = $_; $reading = $_;
$e2reading = "e2" . $_; $e2reading = "e2" . $_;
if ( defined( $signalinfo->{$e2reading} ) ) { if ( defined( $signalinfo->{$e2reading} )
&& lc( $signalinfo->{$e2reading} ) ne "n/a" )
{
my @value = split( / /, $signalinfo->{$e2reading} ); my @value = split( / /, $signalinfo->{$e2reading} );
if ( defined( $value[1] ) || $reading eq "ber" ) { if ( defined( $value[1] ) || $reading eq "ber" ) {
readingsBulkUpdate( $hash, $reading, $value[0], 1 ); readingsBulkUpdate( $hash, $reading, $value[0] );
} }
else { else {
readingsBulkUpdate( $hash, $reading, "0", 1 ); readingsBulkUpdate( $hash, $reading, "0" );
} }
} }
else { else {
readingsBulkUpdate( $hash, $reading, "0", 1 ); readingsBulkUpdate( $hash, $reading, "0" );
} }
} }
} }
}
else {
# Set ENIGMA2 online-only readings to "-" in case box is in # Set ENIGMA2 online-only readings to "-" in case box is in
# offline or in standby mode # offline or in standby mode
if ( $state eq "off" || $state eq "absent" || $state eq "undefined" ) {
foreach ( foreach (
'servicename', 'servicenamespace', 'serviceaspect', 'servicename', 'providername',
'serviceprovider', 'servicereference', 'videowidth', 'servicereference', 'videowidth',
'videoheight', 'servicevideosize', 'apid', 'videoheight', 'servicevideosize',
'vpid', 'pcrpid', 'pmtpid', 'apid', 'vpid',
'txtpid', 'tsid', 'onid', 'pcrpid', 'pmtpid',
'sid', 'mute', 'volume', 'txtpid', 'tsid',
'channel', 'currentTitle', 'eventcurrenttime', 'onid', 'sid',
'eventcurrenttime_hr', 'eventdescription', 'eventduration', 'iswidescreen', 'mute',
'eventduration_hr', 'eventstart', 'eventstart_hr', 'volume', 'channel',
'eventtitle', 'currentMedia', 'currentTitle', 'nextTitle',
'currentMedia', 'eventcurrenttime',
'eventcurrenttime_hr', 'eventdescription',
'eventduration', 'eventduration_hr',
'eventremaining', 'eventremaining_hr',
'eventstart', 'eventstart_hr',
'eventtitle', 'eventname',
'eventcurrenttime_next', 'eventcurrenttime_next_hr',
'eventdescription_next', 'eventduration_next',
'eventduration_next_hr', 'eventremaining_next',
'eventremaining_next_hr', 'eventstart_next',
'eventstart_next_hr', 'eventtitle_next',
'eventname_next',
) )
{ {
if ( !defined( $hash->{READINGS}{$_}{VAL} ) if ( !defined( $hash->{READINGS}{$_}{VAL} )
|| $hash->{READINGS}{$_}{VAL} ne "-" ) || $hash->{READINGS}{$_}{VAL} ne "-" )
{ {
readingsBulkUpdate( $hash, $_, "-", 1 ); readingsBulkUpdate( $hash, $_, "-" );
}
}
# special handling for signal values
foreach ( 'acg', 'ber', 'snr', 'snrdb', ) {
if ( !defined( $hash->{READINGS}{$_}{VAL} )
|| $hash->{READINGS}{$_}{VAL} ne "0" )
{
readingsBulkUpdate( $hash, $_, "0" );
}
} }
} }
# Set ENIGMA2 online+standby readings to "-" in case box is in # Set ENIGMA2 online+standby readings to "-" in case box is in
# offline # offline mode
if ( $state eq "absent" || $state eq "undefined" ) { if ( $state eq "absent" || $state eq "undefined" ) {
foreach ( 'input', ) { foreach ( 'input', ) {
if ( !defined( $hash->{READINGS}{$_}{VAL} ) if ( !defined( $hash->{READINGS}{$_}{VAL} )
|| $hash->{READINGS}{$_}{VAL} ne "-" ) || $hash->{READINGS}{$_}{VAL} ne "-" )
{ {
readingsBulkUpdate( $hash, $_, "-", 1 ); readingsBulkUpdate( $hash, $_, "-" );
} }
} }
} }
# Set ENIGMA2 online-only readings to "0" in case box is in # Update state
# offline or in standby mode $hash->{helper}{lastStatusUpdate} = time();
foreach ( 'acg', 'ber', 'snr', 'snrdb', ) {
if ( !defined( $hash->{READINGS}{$_}{VAL} )
|| $hash->{READINGS}{$_}{VAL} ne "0" )
{
readingsBulkUpdate( $hash, $_, "0", 1 );
}
}
}
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
@ -946,9 +1001,11 @@ sub ENIGMA2_Set($@) {
. ", choose one of statusRequest:noArg toggle:noArg on:noArg off:noArg reboot:noArg restartGui:noArg shutdown:noArg volume:slider,0,1,100 volumeUp:noArg volumeDown:noArg mute:on,off msg remoteControl:UP,DOWN,LEFT,RIGHT,OK,MENU,EPG,ESC,EXIT,RECORD,RED,GREEN,YELLOW,BLUE,AUDIO channelUp:noArg channelDown:noArg play:noArg pause:noArg stop:noArg showText channel:" . ", choose one of statusRequest:noArg toggle:noArg on:noArg off:noArg reboot:noArg restartGui:noArg shutdown:noArg volume:slider,0,1,100 volumeUp:noArg volumeDown:noArg mute:on,off msg remoteControl:UP,DOWN,LEFT,RIGHT,OK,MENU,EPG,ESC,EXIT,RECORD,RED,GREEN,YELLOW,BLUE,AUDIO channelUp:noArg channelDown:noArg play:noArg pause:noArg stop:noArg showText channel:"
. $channels; . $channels;
$usage .= " input:-,tv,radio" $usage .= " input:-,tv,radio"
if ( $hash->{READINGS}{input}{VAL} eq "-" ); if ( defined( $hash->{READINGS}{input}{VAL} )
&& $hash->{READINGS}{input}{VAL} eq "-" );
$usage .= " input:tv,radio" $usage .= " input:tv,radio"
if ( $hash->{READINGS}{input}{VAL} ne "-" ); if ( defined( $hash->{READINGS}{input}{VAL} )
&& $hash->{READINGS}{input}{VAL} ne "-" );
my $cmd = ''; my $cmd = '';
my $result; my $result;