2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

70_ONKYO_AVR,71_ONKYO_AVR_ZONE,70_PHTV,70_Pushover,75_MSG,70_ENIGMA: improved loading of dependent perl modules

git-svn-id: https://svn.fhem.de/fhem/trunk@11616 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2016-06-05 12:30:42 +00:00
parent d3406e471a
commit ad945996fd
6 changed files with 31 additions and 23 deletions

View File

@ -57,10 +57,6 @@ sub ENIGMA2_Initialize($) {
Log3 $hash, 5, "ENIGMA2_Initialize: Entering";
eval 'use XML::Simple; 1';
return "Please install XML::Simple to use this module."
if ($@);
$hash->{GetFn} = "ENIGMA2_Get";
$hash->{SetFn} = "ENIGMA2_Set";
$hash->{DefFn} = "ENIGMA2_Define";
@ -758,6 +754,10 @@ sub ENIGMA2_Define($$) {
Log3 $name, 5, "ENIGMA2 $name: called function ENIGMA2_Define()";
eval { require XML::Simple; };
return "Please install Perl XML::Simple to use module ENIGMA2"
if ($@);
if ( int(@a) < 3 ) {
my $msg =
"Wrong syntax: define <name> ENIGMA2 <ip-or-hostname> [<port>] [<poll-interval>] [<http-user] [<http-password>]";

View File

@ -29,7 +29,6 @@ package main;
use strict;
use warnings;
use ONKYOdb;
use Time::HiRes qw(usleep);
use Symbol qw<qualify_to_ref>;
use File::Path;
@ -60,11 +59,8 @@ sub ONKYO_AVR_Initialize($) {
Log3 $hash, 5, "ONKYO_AVR_Initialize: Entering";
eval { use XML::Simple; };
return "Please install XML::Simple to use this module."
if ($@);
require "$attr{global}{modpath}/FHEM/DevIo.pm";
require "$attr{global}{modpath}/FHEM/ONKYOdb.pm";
# Provider
$hash->{ReadFn} = "ONKYO_AVR_Read";
@ -105,6 +101,10 @@ sub ONKYO_AVR_Define($$$) {
Log3 $name, 5, "ONKYO_AVR $name: called function ONKYO_AVR_Define()";
eval { require XML::Simple; };
return "Please install Perl XML::Simple to use module ONKYO_AVR"
if ($@);
if ( int(@$a) < 3 ) {
my $msg =
"Wrong syntax: define <name> ONKYO_AVR <ip-or-hostname> [<protocol-version>]";
@ -209,7 +209,6 @@ sub ONKYO_AVR_Notify($$) {
else {
DoTrigger( $name, "DISCONNECTED" );
}
}
# unknown event
@ -2129,21 +2128,21 @@ sub ONKYO_AVR_Set($$$) {
"Device power is turned off, this function is unavailable at that stage.";
}
elsif ( lc( @$a[2] ) eq "up" ) {
my $setVal;
my $setVal = "";
$setVal = "B" if ( $2 eq "bass" );
$setVal = "T" if ( $2 eq "treble" );
$return =
ONKYO_AVR_SendCommand( $hash, lc($1), $setVal . "UP" );
}
elsif ( lc( @$a[2] ) eq "down" ) {
my $setVal;
my $setVal = "";
$setVal = "B" if ( $2 eq "bass" );
$setVal = "T" if ( $2 eq "treble" );
$return =
ONKYO_AVR_SendCommand( $hash, lc($1), $setVal . "DOWN" );
}
elsif ( @$a[2] =~ /^-*\d+$/ ) {
my $setVal;
my $setVal = "";
$setVal = "B" if ( $2 eq "bass" );
$setVal = "T" if ( $2 eq "treble" );
$setVal .= "+" if ( @$a[2] > 0 );
@ -2182,7 +2181,7 @@ sub ONKYO_AVR_Set($$$) {
$return = ONKYO_AVR_SendCommand( $hash, lc($1), "DOWN" );
}
elsif ( @$a[2] =~ /^-*\d+$/ ) {
my $setVal;
my $setVal = "";
$setVal = "+" if ( @$a[2] > 0 );
$setVal = "-" if ( @$a[2] < 0 );

View File

@ -32,7 +32,6 @@ use strict;
use warnings;
use Data::Dumper;
use Time::HiRes qw(gettimeofday);
use JSON;
use HttpUtils;
use Color;
use SetExtensions;
@ -1502,6 +1501,13 @@ sub PHTV_Define($$) {
Log3 $name, 5, "PHTV $name: called function PHTV_Define()";
eval {
require JSON;
import JSON qw( decode_json );
};
return "Please install Perl JSON to use module PHTV"
if ($@);
if ( int(@a) < 3 ) {
my $msg =
"Wrong syntax: define <name> PHTV <ip-or-hostname> [<poll-interval>]";

View File

@ -382,7 +382,10 @@ sub Pushover_ReceiveCommand($$$) {
}
# Use JSON module if possible
eval 'use JSON qw( decode_json ); 1';
eval {
require JSON;
import JSON qw( decode_json );
};
$return = decode_json( Encode::encode_utf8($data) )
if ( !$@ );
}

View File

@ -29,13 +29,8 @@ package main;
use strict;
use warnings;
use ONKYOdb;
use Time::HiRes qw(usleep);
use Symbol qw<qualify_to_ref>;
use File::Path;
use File::stat;
use File::Temp;
use File::Copy;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
@ -59,6 +54,8 @@ sub ONKYO_AVR_ZONE_Initialize($) {
Log3 $hash, 5, "ONKYO_AVR_ZONE_Initialize: Entering";
require "$attr{global}{modpath}/FHEM/ONKYOdb.pm";
$hash->{Match} = ".+";
$hash->{DefFn} = "ONKYO_AVR_ZONE_Define";

View File

@ -161,7 +161,10 @@ s/^[\s\t]*([!]?(([A-Za-z0-9%+._-])*@([%+a-z0-9A-Z.-]+))[\w,@.!|:]*)[\s\t]+//
Log3 $globalDevName, 5, "msg: found options=$1";
# Use JSON module if possible
eval 'use JSON qw( decode_json ); 1';
eval {
require JSON;
import JSON qw( decode_json );
};
if ( !$@ ) {
eval '$advanced = decode_json( Encode::encode_utf8($1) ); 1';
if (!$@) {
@ -176,7 +179,7 @@ s/^[\s\t]*([!]?(([A-Za-z0-9%+._-])*@([%+a-z0-9A-Z.-]+))[\w,@.!|:]*)[\s\t]+//
}
else {
Log3 $globalDevName, 3,
"msg: To use advanced options, please install Perl::JSON.";
"msg: To use advanced options, please install Perl JSON.";
}
}