2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

73_GardenaSmartBridge: change package code

git-svn-id: https://svn.fhem.de/fhem/trunk@19641 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
LeonGaultier 2019-06-18 14:47:13 +00:00
parent 80c6225365
commit 473786f746
3 changed files with 115 additions and 86 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- feature: 73_GardenaSmartBridge: change package code
- feature: 73_AMADCommBridge: change package code - feature: 73_AMADCommBridge: change package code
- feature: 42_AptToDate: change every package code - feature: 42_AptToDate: change every package code
- feature: 73_AutoShuttersControl: change every package code - feature: 73_AutoShuttersControl: change every package code

View File

@ -53,65 +53,22 @@
## ##
## ##
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 ';
eval "use IO::Socket::SSL;1" or $missingModul .= 'IO::Socket::SSL '; eval "use IO::Socket::SSL;1" or $missingModul .= 'IO::Socket::SSL ';
@ -186,7 +143,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 +164,7 @@ BEGIN {
getKeyValue getKeyValue
getUniqueId getUniqueId
RemoveInternalTimer RemoveInternalTimer
readingFnAttributes
InternalTimer InternalTimer
defs defs
init_done init_done
@ -214,6 +176,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 +251,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,