From 983537df00faae4f72a5618c30b3fe4559fad8b5 Mon Sep 17 00:00:00 2001 From: loredo Date: Tue, 19 Feb 2019 02:26:02 +0000 Subject: [PATCH] 42_npmjs: add support for Meta.pm git-svn-id: https://svn.fhem.de/fhem/trunk@18636 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/42_npmjs.pm | 237 +++++++++++++++++++++++++++++++++++------- 1 file changed, 197 insertions(+), 40 deletions(-) diff --git a/fhem/FHEM/42_npmjs.pm b/fhem/FHEM/42_npmjs.pm index 1a5db905c..7a7a1b70b 100644 --- a/fhem/FHEM/42_npmjs.pm +++ b/fhem/FHEM/42_npmjs.pm @@ -4,54 +4,43 @@ # Based on 42_AptToDate.pm by CoolTux package main; - use strict; use warnings; +use FHEM::Meta; sub npmjs_Initialize($) { + my ($modHash) = @_; - my ($hash) = @_; - - $hash->{SetFn} = "npmjs::Set"; - $hash->{GetFn} = "npmjs::Get"; - $hash->{DefFn} = "npmjs::Define"; - $hash->{NotifyFn} = "npmjs::Notify"; - $hash->{UndefFn} = "npmjs::Undef"; - $hash->{AttrFn} = "npmjs::Attr"; - $hash->{AttrList} = + $modHash->{SetFn} = "FHEM::npmjs::Set"; + $modHash->{GetFn} = "FHEM::npmjs::Get"; + $modHash->{DefFn} = "FHEM::npmjs::Define"; + $modHash->{NotifyFn} = "FHEM::npmjs::Notify"; + $modHash->{UndefFn} = "FHEM::npmjs::Undef"; + $modHash->{AttrFn} = "FHEM::npmjs::Attr"; + $modHash->{AttrList} = "disable:1,0 " . "disabledForIntervals " . "updateListReading:1,0 " . "npmglobal:1,0 " . $readingFnAttributes; - # update INTERNAL after module reload - foreach my $d ( devspec2array("TYPE=npmjs") ) { - $defs{$d}{VERSION} = $npmjs::VERSION; - } + return FHEM::Meta::Load( __FILE__, $modHash ); } # define package -package npmjs; - +package FHEM::npmjs; use strict; use warnings; use POSIX; -use RESIDENTStk; +use FHEM::Meta; -# our @EXPORT = qw(get_time_suffix); -our $VERSION = "0.10.2"; - -# supports to import main functions from fhem.pl use GPUtils qw(GP_Import); +use JSON; +use Data::Dumper; -use Data::Dumper; #only for Debugging - -my $missingModule = ""; -eval "use JSON;1" or $missingModule .= "JSON "; - -## Import der FHEM Funktionen +# Run before module compilation BEGIN { + # Import from main:: GP_Import( qw(readingsSingleUpdate readingsBulkUpdate @@ -86,20 +75,18 @@ my %fhem_npm_modules = ( ); sub Define($$) { - my ( $hash, $def ) = @_; my @a = split( "[ \t][ \t]*", $def ); - return - "Cannot define npmjs device. Perl module ${missingModule} is missing." - if ($missingModule); + # Initialize the module and the device + return $@ unless ( FHEM::Meta::SetInternals($hash) ); + use version 0.77; our $VERSION = FHEM::Meta::Get( $hash, 'version' ); my $name = $a[0]; my $host = $a[2] ? $a[2] : 'localhost'; Undef( $hash, undef ) if ( $hash->{OLDDEF} ); # modify - $hash->{VERSION} = $VERSION; $hash->{HOST} = $host; $hash->{NOTIFYDEV} = "global,$name"; @@ -605,8 +592,11 @@ sub ProcessUpdateTimer($) { my $name = $hash->{NAME}; RemoveInternalTimer($hash); - InternalTimer( gettimeofday() + 14400, - "npmjs::ProcessUpdateTimer", $hash, 0 ); + InternalTimer( + gettimeofday() + 14400, + "FHEM::npmjs::ProcessUpdateTimer", + $hash, 0 + ); Log3 $name, 4, "npmjs ($name) - stateRequestTimer: Call Request Timer"; unless ( IsDisabled($name) ) { @@ -681,7 +671,7 @@ sub AsynchronousExecuteNpmCommand($) { $hash->{".fhem"}{subprocess} = $subprocess; InternalTimer( gettimeofday() + POLLINTERVAL, - "npmjs::PollChild", $hash, 0 ); + "FHEM::npmjs::PollChild", $hash, 0 ); Log3 $hash, 4, "npmjs ($name) - control passed back to main loop."; } @@ -697,7 +687,7 @@ sub PollChild($) { Log3 $name, 5, "npmjs ($name) - still waiting (" . $subprocess->{lasterror} . ")."; InternalTimer( gettimeofday() + POLLINTERVAL, - "npmjs::PollChild", $hash, 0 ); + "FHEM::npmjs::PollChild", $hash, 0 ); return; } else { @@ -1379,9 +1369,10 @@ sub ToDay() { 1; =pod +=encoding utf8 =item device -=item summary Module to control Node.js installation and update -=item summary_DE Modul zur Bedienung der Node.js Installation und Updates +=item summary Module to control Node.js package installation and update +=item summary_DE Modul zur Bedienung der Node.js Paket Installation und Updates =begin html @@ -1462,7 +1453,7 @@ sub ToDay() {