change package code

This commit is contained in:
Marko Oldenburg 2019-06-18 16:43:40 +02:00
parent 40e91352d8
commit 7c0520a26e
2 changed files with 113 additions and 86 deletions

View File

@ -53,63 +53,19 @@
## ##
## ##
package main;
use strict;
use warnings;
use FHEM::Meta;
my $version = '1.6.6';
sub GardenaSmartBridge_Initialize($) {
my ($hash) = @_;
# Provider
$hash->{WriteFn} = 'FHEM::GardenaSmartBridge::Write';
$hash->{Clients} = ':GardenaSmartDevice:';
$hash->{MatchList} = { '1:GardenaSmartDevice' => '^{"id":".*' };
# Consumer
$hash->{SetFn} = 'FHEM::GardenaSmartBridge::Set';
$hash->{DefFn} = 'FHEM::GardenaSmartBridge::Define';
$hash->{UndefFn} = 'FHEM::GardenaSmartBridge::Undef';
$hash->{DeleteFn} = 'FHEM::GardenaSmartBridge::Delete';
$hash->{RenameFn} = 'FHEM::GardenaSmartBridge::Rename';
$hash->{NotifyFn} = 'FHEM::GardenaSmartBridge::Notify';
$hash->{AttrFn} = 'FHEM::GardenaSmartBridge::Attr';
$hash->{AttrList} =
'debugJSON:0,1 '
. 'disable:1 '
. 'interval '
. 'disabledForIntervals '
. 'gardenaAccountEmail '
. 'gardenaBaseURL '
. $readingFnAttributes;
foreach my $d ( sort keys %{ $modules{GardenaSmartBridge}{defptr} } ) {
my $hash = $modules{GardenaSmartBridge}{defptr}{$d};
$hash->{VERSION} = $version;
}
return FHEM::Meta::InitMod( __FILE__, $hash );
}
package FHEM::GardenaSmartBridge; package FHEM::GardenaSmartBridge;
use GPUtils qw(GP_Import) use GPUtils qw(GP_Import)
; # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt ; # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
my $missingModul = '';
use strict; use strict;
use warnings; use warnings;
use POSIX; use POSIX;
use FHEM::Meta; use FHEM::Meta;
use HttpUtils; use HttpUtils;
our $VERSION = '1.6.7';
my $missingModul = '';
eval "use Encode qw(encode encode_utf8 decode_utf8);1" eval "use Encode qw(encode encode_utf8 decode_utf8);1"
or $missingModul .= "Encode "; or $missingModul .= "Encode ";
# eval "use JSON;1" or $missingModul .= 'JSON '; # eval "use JSON;1" or $missingModul .= 'JSON ';
@ -186,7 +142,11 @@ if ($@) {
} }
} }
## Import der FHEM Funktionen
#-- Run before package compilation
BEGIN { BEGIN {
# Import from main context
GP_Import( GP_Import(
qw(readingsSingleUpdate qw(readingsSingleUpdate
readingsBulkUpdate readingsBulkUpdate
@ -203,6 +163,7 @@ BEGIN {
getKeyValue getKeyValue
getUniqueId getUniqueId
RemoveInternalTimer RemoveInternalTimer
readingFnAttributes
InternalTimer InternalTimer
defs defs
init_done init_done
@ -214,6 +175,60 @@ BEGIN {
); );
} }
# _Export - Export references to main context using a different naming schema
sub _Export {
no strict qw/refs/; ## no critic
my $pkg = caller(0);
my $main = $pkg;
$main =~ s/^(?:.+::)?([^:]+)$/main::$1\_/g;
foreach (@_) {
*{ $main . $_ } = *{ $pkg . '::' . $_ };
}
}
#-- Export to main context with different name
_Export(
qw(
Initialize
)
);
sub Initialize($) {
my ($hash) = @_;
# Provider
$hash->{WriteFn} = 'FHEM::GardenaSmartBridge::Write';
$hash->{Clients} = ':GardenaSmartDevice:';
$hash->{MatchList} = { '1:GardenaSmartDevice' => '^{"id":".*' };
# Consumer
$hash->{SetFn} = 'FHEM::GardenaSmartBridge::Set';
$hash->{DefFn} = 'FHEM::GardenaSmartBridge::Define';
$hash->{UndefFn} = 'FHEM::GardenaSmartBridge::Undef';
$hash->{DeleteFn} = 'FHEM::GardenaSmartBridge::Delete';
$hash->{RenameFn} = 'FHEM::GardenaSmartBridge::Rename';
$hash->{NotifyFn} = 'FHEM::GardenaSmartBridge::Notify';
$hash->{AttrFn} = 'FHEM::GardenaSmartBridge::Attr';
$hash->{AttrList} =
'debugJSON:0,1 '
. 'disable:1 '
. 'interval '
. 'disabledForIntervals '
. 'gardenaAccountEmail '
. 'gardenaBaseURL '
. $readingFnAttributes;
foreach my $d ( sort keys %{ $modules{GardenaSmartBridge}{defptr} } ) {
my $hash = $modules{GardenaSmartBridge}{defptr}{$d};
$hash->{VERSION} = $VERSION;
}
return FHEM::Meta::InitMod( __FILE__, $hash );
}
sub Define($$) { sub Define($$) {
my ( $hash, $def ) = @_; my ( $hash, $def ) = @_;
@ -235,7 +250,7 @@ sub Define($$) {
AttrVal( $name, 'gardenaBaseURL', AttrVal( $name, 'gardenaBaseURL',
'https://sg-api.dss.husqvarnagroup.net' ) 'https://sg-api.dss.husqvarnagroup.net' )
. '/sg-1'; . '/sg-1';
$hash->{VERSION} = $version; $hash->{VERSION} = $VERSION;
$hash->{INTERVAL} = 60; $hash->{INTERVAL} = 60;
$hash->{NOTIFYDEV} = "global,$name"; $hash->{NOTIFYDEV} = "global,$name";

View File

@ -53,41 +53,6 @@
## ##
## ##
package main;
use strict;
use warnings;
use FHEM::Meta;
my $version = '1.6.4';
sub GardenaSmartDevice_Initialize($) {
my ($hash) = @_;
$hash->{Match} = '^{"id":".*';
$hash->{SetFn} = "FHEM::GardenaSmartDevice::Set";
$hash->{DefFn} = "FHEM::GardenaSmartDevice::Define";
$hash->{UndefFn} = "FHEM::GardenaSmartDevice::Undef";
$hash->{ParseFn} = "FHEM::GardenaSmartDevice::Parse";
$hash->{AttrFn} = "FHEM::GardenaSmartDevice::Attr";
$hash->{AttrList} =
"readingValueLanguage:de,en "
. "model:watering_computer,sensor,mower,ic24,power,electronic_pressure_pump "
. "IODev "
. $readingFnAttributes;
foreach my $d ( sort keys %{ $modules{GardenaSmartDevice}{defptr} } ) {
my $hash = $modules{GardenaSmartDevice}{defptr}{$d};
$hash->{VERSION} = $version;
}
return FHEM::Meta::InitMod( __FILE__, $hash );
}
## unserer packagename ## unserer packagename
package FHEM::GardenaSmartDevice; package FHEM::GardenaSmartDevice;
@ -100,10 +65,8 @@ use strict;
use warnings; use warnings;
use POSIX; use POSIX;
use FHEM::Meta; use FHEM::Meta;
use Time::Local; use Time::Local;
our $VERSION = '1.6.5';
# eval "use JSON;1" or $missingModul .= "JSON ";
# try to use JSON::MaybeXS wrapper # try to use JSON::MaybeXS wrapper
# for chance of better performance + open code # for chance of better performance + open code
@ -177,7 +140,10 @@ if ($@) {
} }
## Import der FHEM Funktionen ## Import der FHEM Funktionen
#-- Run before package compilation
BEGIN { BEGIN {
# Import from main context
GP_Import( GP_Import(
qw(readingsSingleUpdate qw(readingsSingleUpdate
readingsBulkUpdate readingsBulkUpdate
@ -188,6 +154,7 @@ BEGIN {
CommandAttr CommandAttr
AttrVal AttrVal
ReadingsVal ReadingsVal
readingFnAttributes
AssignIoPort AssignIoPort
modules modules
IOWrite IOWrite
@ -196,6 +163,51 @@ BEGIN {
); );
} }
# _Export - Export references to main context using a different naming schema
sub _Export {
no strict qw/refs/; ## no critic
my $pkg = caller(0);
my $main = $pkg;
$main =~ s/^(?:.+::)?([^:]+)$/main::$1\_/g;
foreach (@_) {
*{ $main . $_ } = *{ $pkg . '::' . $_ };
}
}
#-- Export to main context with different name
_Export(
qw(
Initialize
)
);
sub Initialize($) {
my ($hash) = @_;
$hash->{Match} = '^{"id":".*';
$hash->{SetFn} = "FHEM::GardenaSmartDevice::Set";
$hash->{DefFn} = "FHEM::GardenaSmartDevice::Define";
$hash->{UndefFn} = "FHEM::GardenaSmartDevice::Undef";
$hash->{ParseFn} = "FHEM::GardenaSmartDevice::Parse";
$hash->{AttrFn} = "FHEM::GardenaSmartDevice::Attr";
$hash->{AttrList} =
"readingValueLanguage:de,en "
. "model:watering_computer,sensor,mower,ic24,power,electronic_pressure_pump "
. "IODev "
. $readingFnAttributes;
foreach my $d ( sort keys %{ $modules{GardenaSmartDevice}{defptr} } ) {
my $hash = $modules{GardenaSmartDevice}{defptr}{$d};
$hash->{VERSION} = $VERSION;
}
return FHEM::Meta::InitMod( __FILE__, $hash );
}
sub Define($$) { sub Define($$) {
my ( $hash, $def ) = @_; my ( $hash, $def ) = @_;
@ -214,7 +226,7 @@ sub Define($$) {
my $category = $a[3]; my $category = $a[3];
$hash->{DEVICEID} = $deviceId; $hash->{DEVICEID} = $deviceId;
$hash->{VERSION} = $version; $hash->{VERSION} = $VERSION;
$hash->{helper}{STARTINGPOINTID} = ''; $hash->{helper}{STARTINGPOINTID} = '';
CommandAttr( undef, CommandAttr( undef,