add Attribut fhemServerIp

This commit is contained in:
Marko Oldenburg 2019-03-27 23:25:32 +01:00
parent 124a0bdee5
commit 8fe6bc5a0a
2 changed files with 17 additions and 11 deletions

View File

@ -89,6 +89,7 @@ sub AMADCommBridge_Initialize($) {
. 'enableSubCalls:0,1 ' . 'enableSubCalls:0,1 '
. 'disable:1 ' . 'disable:1 '
. 'allowfrom ' . 'allowfrom '
. 'fhemServerIP '
. $readingFnAttributes; . $readingFnAttributes;
foreach my $d ( sort keys %{ $modules{AMADCommBridge}{defptr} } ) { foreach my $d ( sort keys %{ $modules{AMADCommBridge}{defptr} } ) {
@ -189,10 +190,10 @@ sub Undef($$) {
my ( $hash, $arg ) = @_; my ( $hash, $arg ) = @_;
TcpServer_Close($hash);
delete $modules{AMADCommBridge}{defptr}{BRIDGE} delete $modules{AMADCommBridge}{defptr}{BRIDGE}
if ( defined( $modules{AMADCommBridge}{defptr}{BRIDGE} ) if ( defined( $modules{AMADCommBridge}{defptr}{BRIDGE} )
and $hash->{BRIDGE} ); and $hash->{BRIDGE} );
TcpServer_Close($hash);
return undef; return undef;
} }
@ -732,8 +733,8 @@ sub ErrorHandling($$$) {
} }
sub Open($) { sub Open($) {
my $hash = shift; my $hash = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $port = $hash->{PORT}; my $port = $hash->{PORT};
@ -753,7 +754,6 @@ sub Open($) {
Log3( $name, 3, "AMADCommBridge ($name) - Socket opened." ); Log3( $name, 3, "AMADCommBridge ($name) - Socket opened." );
return $ret; return $ret;
} }
else { else {
@ -764,12 +764,10 @@ sub Open($) {
} }
sub Close($) { sub Close($) {
my $hash = shift; my $hash = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
delete $modules{AMADCommBridge}{defptr}{BRIDGE};
TcpServer_Close($hash); TcpServer_Close($hash);
if ( not defined( $hash->{FD} ) ) { if ( not defined( $hash->{FD} ) ) {
@ -1027,8 +1025,10 @@ sub ResponseProcessing($$) {
Dispatch( $bhash, $json, undef ); Dispatch( $bhash, $json, undef );
Log3( $bname, 4, "AMADCommBridge ($bname) - call Dispatcher" ); Log3( $bname, 4, "AMADCommBridge ($bname) - call Dispatcher" );
readingsSingleUpdate( $bhash, 'fhemServerIP', CommandAttr( undef,
$decode_json->{firstrun}{'fhemserverip'}, 1 ) $bname
. ' fhemServerIP '
. $decode_json->{firstrun}{'fhemserverip'} )
if ( defined( $decode_json->{firstrun}{'fhemserverip'} ) ); if ( defined( $decode_json->{firstrun}{'fhemserverip'} ) );
$response = $response =

View File

@ -114,6 +114,8 @@ use warnings;
use POSIX; use POSIX;
use FHEM::Meta; use FHEM::Meta;
use Data::Dumper; #only for Debugging
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
@ -236,6 +238,8 @@ sub Define($$) {
"AMADDevice ($name) - defined with AMAD_ID: $amad_id on port $hash->{PORT}" "AMADDevice ($name) - defined with AMAD_ID: $amad_id on port $hash->{PORT}"
); );
$hash->{NOTIFYDEV} .= ',' . $iodev
if ( defined($iodev) );
$modules{AMADDevice}{defptr}{$amad_id} = $hash; $modules{AMADDevice}{defptr}{$amad_id} = $hash;
return undef; return undef;
@ -380,9 +384,11 @@ sub Notify($$) {
@{$events} @{$events}
or grep /^ATTR.$name.setUserFlowState.*/, or grep /^ATTR.$name.setUserFlowState.*/,
@{$events} @{$events}
or grep /^ATTR.$hash->{IODev}->{NAME}.fhemServerIP.*/,
@{$events}
) )
and $init_done
and $devname eq 'global' and $devname eq 'global'
and $init_done
); );
GetUpdate($hash) GetUpdate($hash)
@ -427,7 +433,7 @@ sub GetUpdate($) {
and ( ReadingsVal( $name, 'deviceState', 'unknown' ) eq 'unknown' and ( ReadingsVal( $name, 'deviceState', 'unknown' ) eq 'unknown'
or ReadingsVal( $name, 'deviceState', 'online' ) eq 'online' ) or ReadingsVal( $name, 'deviceState', 'online' ) eq 'online' )
and AttrVal( $name, 'disable', 0 ) ne 1 and AttrVal( $name, 'disable', 0 ) ne 1
and ReadingsVal( $bname, 'fhemServerIP', 'not set' ) ne 'not set' and AttrVal( $bname, 'fhemServerIP', 'not set' ) ne 'not set'
) )
{ {
@ -461,7 +467,7 @@ sub statusRequest($) {
my $activetask = AttrVal( $name, 'checkActiveTask', 'none' ); my $activetask = AttrVal( $name, 'checkActiveTask', 'none' );
my $userFlowState = AttrVal( $name, 'setUserFlowState', 'none' ); my $userFlowState = AttrVal( $name, 'setUserFlowState', 'none' );
my $apssid = AttrVal( $name, 'setAPSSID', 'none' ); my $apssid = AttrVal( $name, 'setAPSSID', 'none' );
my $fhemip = ReadingsVal( $hash->{IODev}->{NAME}, 'fhemServerIP', 'none' ); my $fhemip = AttrVal( $hash->{IODev}->{NAME}, 'fhemServerIP', 'none' );
my $fhemCtlMode = my $fhemCtlMode =
AttrVal( $hash->{IODev}->{NAME}, 'fhemControlMode', 'none' ); AttrVal( $hash->{IODev}->{NAME}, 'fhemControlMode', 'none' );
my $bport = $hash->{IODev}->{PORT}; my $bport = $hash->{IODev}->{PORT};