mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-28 17:12:32 +00:00
OPENWEATHER: URL created during define
git-svn-id: https://svn.fhem.de/fhem/trunk@6951 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
6038d6881e
commit
5b00a3b2c7
@ -38,8 +38,9 @@ package MyOPENWEATHERParser;
|
|||||||
use base qw(HTML::Parser);
|
use base qw(HTML::Parser);
|
||||||
our %fcReadings = ();
|
our %fcReadings = ();
|
||||||
my $curTag = "";
|
my $curTag = "";
|
||||||
my $day = -1;
|
my $day = -2;
|
||||||
my $time = "";
|
my $time = "";
|
||||||
|
my $isError = 0;
|
||||||
# here HTML::text/start/end are overridden
|
# here HTML::text/start/end are overridden
|
||||||
|
|
||||||
%knownTags = ( tn => "tempMin"
|
%knownTags = ( tn => "tempMin"
|
||||||
@ -51,24 +52,24 @@ my $time = "";
|
|||||||
, wd_txt => "windDirTxt"
|
, wd_txt => "windDirTxt"
|
||||||
, pc => "presChange"
|
, pc => "presChange"
|
||||||
, p => "valHours"
|
, p => "valHours"
|
||||||
|
, title => "error"
|
||||||
|
, message => "errorMsg"
|
||||||
|
, name => "city"
|
||||||
|
, post_code => "postcode"
|
||||||
);
|
);
|
||||||
|
|
||||||
sub text
|
sub text
|
||||||
{
|
{
|
||||||
my ( $self, $text ) = @_;
|
my ( $self, $text ) = @_;
|
||||||
|
|
||||||
if ($curTag eq "name")
|
|
||||||
{
|
|
||||||
$fcReadings{"city"} = $text ;
|
|
||||||
}
|
|
||||||
elsif ($curTag eq "post_code")
|
|
||||||
{
|
|
||||||
$fcReadings{"postCode"} = $text ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
my $rName = $knownTags{$curTag};
|
my $rName = $knownTags{$curTag};
|
||||||
if (defined $rName && $day >= 0)
|
if (defined $rName)
|
||||||
|
{
|
||||||
|
if ($day == -2)
|
||||||
|
{
|
||||||
|
$fcReadings{$rName} = $text ;
|
||||||
|
}
|
||||||
|
elsif ( $day >= 0 )
|
||||||
{
|
{
|
||||||
#Umlaute entfernen
|
#Umlaute entfernen
|
||||||
if ($curTag eq "w_txt") {$text =~ s/ö/oe/; $text =~ s/ä/ae/; $text =~ s/ü/ue/; $text =~ s/ß/ss/;}
|
if ($curTag eq "w_txt") {$text =~ s/ö/oe/; $text =~ s/ä/ae/; $text =~ s/ü/ue/; $text =~ s/ß/ss/;}
|
||||||
@ -86,12 +87,12 @@ sub start
|
|||||||
{
|
{
|
||||||
$day = -1;
|
$day = -1;
|
||||||
}
|
}
|
||||||
if ($tagname eq "date")
|
elsif ( $tagname eq "date" && $day >= -1 )
|
||||||
{
|
{
|
||||||
$day++;
|
$day++;
|
||||||
$time = "";
|
$time = "";
|
||||||
}
|
}
|
||||||
if ($tagname eq "time")
|
elsif ($tagname eq "time")
|
||||||
{
|
{
|
||||||
$time = substr($attr->{value}, 0, 2);
|
$time = substr($attr->{value}, 0, 2);
|
||||||
}
|
}
|
||||||
@ -180,11 +181,21 @@ OPENWEATHER_Define($$)
|
|||||||
$hash->{CITYCODE} = $args[3];
|
$hash->{CITYCODE} = $args[3];
|
||||||
$hash->{APIKEY} = $args[4];
|
$hash->{APIKEY} = $args[4];
|
||||||
$hash->{CREDIT} = "Powered by wetter.com";
|
$hash->{CREDIT} = "Powered by wetter.com";
|
||||||
RemoveInternalTimer($hash);
|
|
||||||
#Get first data after 13 seconds
|
|
||||||
InternalTimer(gettimeofday() + 13, "OPENWEATHER_Start", $hash, 0) if $interval > 0;
|
|
||||||
|
|
||||||
$hash->{fhem}{modulVersion} = '$ID $';
|
my $checkSum = md5_hex( $args[2] . $args[4] . $args[3] );
|
||||||
|
|
||||||
|
my $URL = 'http://api.wetter.com/forecast/weather';
|
||||||
|
$URL .= '/city/' . $args[3];
|
||||||
|
$URL .= '/project/' . $args[2];
|
||||||
|
$URL .= '/cs/' . $checkSum;
|
||||||
|
|
||||||
|
$hash->{URL} = $URL;
|
||||||
|
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
# Get first data after 7 seconds
|
||||||
|
InternalTimer(gettimeofday() + 7, "OPENWEATHER_Start", $hash, 0) if $interval > 0;
|
||||||
|
|
||||||
|
$hash->{fhem}{modulVersion} = '# $ID: $';
|
||||||
OPENWEATHER_Log $hash, 5, "OPENWEATHER.pm version is " . $hash->{fhem}{modulVersion};
|
OPENWEATHER_Log $hash, 5, "OPENWEATHER.pm version is " . $hash->{fhem}{modulVersion};
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -311,18 +322,10 @@ OPENWEATHER_Run ($)
|
|||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $returnStr;
|
my $returnStr;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
my $projectName = $hash->{PROJECT};
|
|
||||||
my $apiKey = $hash->{APIKEY};
|
|
||||||
my $cityCode = $hash->{CITYCODE};
|
|
||||||
|
|
||||||
my $checkSum = md5_hex( $projectName . $apiKey . $cityCode );
|
return $name."|0|Error: URL not created. Please re-define device."
|
||||||
|
unless defined $hash->{URL};
|
||||||
my $URL = 'http://api.wetter.com/forecast/weather';
|
my $URL = $hash->{URL};
|
||||||
$URL .= '/city/' . $cityCode;
|
|
||||||
$URL .= '/project/' . $projectName;
|
|
||||||
$URL .= '/cs/' . $checkSum;
|
|
||||||
|
|
||||||
$hash->{URL} = $URL;
|
|
||||||
|
|
||||||
OPENWEATHER_Log $hash, 5, "Start capturing data from $URL";
|
OPENWEATHER_Log $hash, 5, "Start capturing data from $URL";
|
||||||
|
|
||||||
@ -364,14 +367,23 @@ OPENWEATHER_Done($)
|
|||||||
my $message = decode_base64($result);
|
my $message = decode_base64($result);
|
||||||
|
|
||||||
OPENWEATHER_Log $hash, 5, "Start parsing of XML data.";
|
OPENWEATHER_Log $hash, 5, "Start parsing of XML data.";
|
||||||
|
|
||||||
my $parser = MyOPENWEATHERParser->new;
|
my $parser = MyOPENWEATHERParser->new;
|
||||||
%MyOPENWEATHERParser::fcReadings = ();
|
%MyOPENWEATHERParser::fcReadings = ();
|
||||||
$MyOPENWEATHERParser::day = -1;
|
$MyOPENWEATHERParser::day = -2;
|
||||||
$MyOPENWEATHERParser::time = "";
|
$MyOPENWEATHERParser::time = "";
|
||||||
|
$MyOPENWEATHERParser::isError = 0;
|
||||||
$parser->parse($message);
|
$parser->parse($message);
|
||||||
|
|
||||||
OPENWEATHER_Log $hash, 4, "Captured values: " . keys (%MyOPENWEATHERParser::fcReadings);
|
OPENWEATHER_Log $hash, 4, "Captured values: " . keys (%MyOPENWEATHERParser::fcReadings);
|
||||||
|
|
||||||
|
if (defined $MyOPENWEATHERParser::fcReadings{error} )
|
||||||
|
{
|
||||||
|
readingsBulkUpdate($hash, "lastConnection", $MyOPENWEATHERParser::fcReadings{error});
|
||||||
|
OPENWEATHER_Log $hash, 1, $MyOPENWEATHERParser::fcReadings{error}." - ".$MyOPENWEATHERParser::fcReadings{errorMsg};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
readingsBulkUpdate($hash, "lastConnection", keys (%MyOPENWEATHERParser::fcReadings) . " values captured");
|
readingsBulkUpdate($hash, "lastConnection", keys (%MyOPENWEATHERParser::fcReadings) . " values captured");
|
||||||
|
|
||||||
while (my ($rName, $rValue) = each(%MyOPENWEATHERParser::fcReadings) )
|
while (my ($rName, $rValue) = each(%MyOPENWEATHERParser::fcReadings) )
|
||||||
@ -383,7 +395,7 @@ OPENWEATHER_Done($)
|
|||||||
my $state = "Tmin: ".$MyOPENWEATHERParser::fcReadings{fc0_tempMin};
|
my $state = "Tmin: ".$MyOPENWEATHERParser::fcReadings{fc0_tempMin};
|
||||||
$state .= " Tmax: ".$MyOPENWEATHERParser::fcReadings{fc0_tempMax};
|
$state .= " Tmax: ".$MyOPENWEATHERParser::fcReadings{fc0_tempMax};
|
||||||
readingsBulkUpdate ($hash, "state", $state);
|
readingsBulkUpdate ($hash, "state", $state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -530,7 +542,7 @@ OPENWEATHER_UpdateAborted($)
|
|||||||
</li><br>
|
</li><br>
|
||||||
<li><code><Ortscode></code>
|
<li><code><Ortscode></code>
|
||||||
<br>
|
<br>
|
||||||
Code des Ortes für den die Wettervorhersage benötigt wird. Er kann direkt aus der Adresszeile der jeweiligen Vorhersageseite genommen werden. Zum Beispiel <i>DE0009042</i> aus:
|
Code des Ortes, für den die Wettervorhersage benötigt wird. Er kann direkt aus der Adresszeile der jeweiligen Vorhersageseite genommen werden. Zum Beispiel <i>DE0009042</i> aus:
|
||||||
<br>
|
<br>
|
||||||
<i>http://www.wetter.com/wetter_aktuell/aktuelles_wetter/deutschland/rostock/<u>DE0009042</u>.html</i>
|
<i>http://www.wetter.com/wetter_aktuell/aktuelles_wetter/deutschland/rostock/<u>DE0009042</u>.html</i>
|
||||||
</li><br>
|
</li><br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user