2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 05:16:45 +00:00

50_HP1000: improved handling when webhookFWinstances attribute was not explicitly set

git-svn-id: https://svn.fhem.de/fhem/trunk@17527 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2018-10-14 09:38:12 +00:00
parent 33d14b26d8
commit 22a23a222f

View File

@ -285,14 +285,12 @@ sub HP1000_Define($$$) {
. " (there can only be one instance as per restriction of the weather station itself)"
if ( defined( $modules{HP1000}{defptr} ) && !defined( $hash->{OLDDEF} ) );
# check FHEMWEB instance
# check FHEMWEB instance when user first defines the device
if ( $init_done && !defined( $hash->{OLDDEF} ) ) {
my $FWports;
foreach ( devspec2array('TYPE=FHEMWEB:FILTER=TEMPORARY!=1') ) {
$hash->{FW} = $_
if ( AttrVal( $_, "webname", "fhem" ) eq "weatherstation" );
push( @{$FWports}, $defs{$_}->{PORT} )
if ( defined( $defs{$_}->{PORT} ) );
}
if ( !defined( $hash->{FW} ) ) {
@ -315,8 +313,6 @@ sub HP1000_Define($$$) {
}
}
$hash->{FW_PORT} = $defs{ $hash->{FW} }{PORT};
fhem 'attr ' . $name . ' stateReadings temperature humidity';
fhem 'attr ' . $name . ' stateReadingsFormat 1';
}
@ -423,16 +419,31 @@ sub HP1000_CGI() {
# get device name
$name = $data{FWEXT}{"/updateweatherstation"}{deviceName}
if ( defined( $data{FWEXT}{"/updateweatherstation"} ) );
$hash = $defs{$name};
# return error if no such device
return ( "text/plain; charset=utf-8",
"No HP1000 device for webhook /updateweatherstation" )
unless ( IsDevice( $name, 'HP1000' ) );
# incorrect FHEMWEB instance used
my @webhookFWinstances = split( ",",
AttrVal( $name, "webhookFWinstances", "WEBweatherstation" ) );
# Only allow data via explicitly named FHEMWEB instances,
# e.g. the user is taking care about correct incoming data
# routing to that instance via reverse proxy
$hash->{FW} = AttrVal( $name, "webhookFWinstances", "" );
# Otherwise, only allow data via FHEMWEB instance with
# webname 'weatherstation' as hardcoded in weatherstation firmware
if ( $hash->{FW} eq "" ) {
foreach ( devspec2array('TYPE=FHEMWEB:FILTER=TEMPORARY!=1') ) {
if ( AttrVal( $_, "webname", "fhem" ) eq "weatherstation" ) {
$hash->{FW} = $_;
last;
}
}
}
# incorrect FHEMWEB instance used
my @webhookFWinstances = split( ",", $hash->{FW} );
return ( "text/plain; charset=utf-8",
"incorrect FHEMWEB instance to receive data" )
unless ( grep ( /^$FW_wname$/, @webhookFWinstances ) );
@ -487,7 +498,6 @@ sub HP1000_CGI() {
return ( "text/plain; charset=utf-8", "Missing data" );
}
$hash = $defs{$name};
my $uptime = time() - $fhem_started;
delete $hash->{FORECASTDEV} if ( $hash->{FORECASTDEV} );
@ -508,20 +518,10 @@ sub HP1000_CGI() {
: 0
);
$hash->{SYSTEMTIME_UTC} = $webArgs->{dateutc};
$hash->{FW} = "";
$hash->{FW_PORT} = "";
$hash->{UPLOAD_TYPE} = "default";
$hash->{UPLOAD_TYPE} = "customize"
if ( defined( $webArgs->{solarradiation} ) );
foreach ( devspec2array('TYPE=FHEMWEB:FILTER=TEMPORARY!=1') ) {
if ( AttrVal( $_, "webname", "fhem" ) eq "weatherstation" ) {
$hash->{FW} = $_;
$hash->{FW_PORT} = $defs{$_}{PORT};
last;
}
}
Log3 $name, 5,
"HP1000: received data (uptime=$uptime):\n" . Dumper($webArgs);