mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-27 10:37:13 +00:00
59_Weather: added summary
git-svn-id: https://svn.fhem.de/fhem/trunk@12464 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
56220f5a3a
commit
3520a5189f
@ -30,7 +30,6 @@ use warnings;
|
|||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
use vars qw($FW_ss);
|
use vars qw($FW_ss);
|
||||||
use YahooWeatherAPI;
|
|
||||||
|
|
||||||
my %pressure_trend_txt_en = ( 0 => "steady", 1 => "rising", 2 => "falling" );
|
my %pressure_trend_txt_en = ( 0 => "steady", 1 => "rising", 2 => "falling" );
|
||||||
my %pressure_trend_txt_de = ( 0 => "gleichbleibend", 1 => "steigend", 2 => "fallend" );
|
my %pressure_trend_txt_de = ( 0 => "gleichbleibend", 1 => "steigend", 2 => "fallend" );
|
||||||
@ -391,32 +390,67 @@ sub Weather_Define($$) {
|
|||||||
|
|
||||||
# define <name> Weather <location> [interval]
|
# define <name> Weather <location> [interval]
|
||||||
# define MyWeather Weather "Maintal,HE" 3600
|
# define MyWeather Weather "Maintal,HE" 3600
|
||||||
|
|
||||||
|
# define <name> Weather location=<location> [API=<API>] [interval=<interval>] [lang=<lang>]
|
||||||
|
|
||||||
|
my $name;
|
||||||
|
my $API="YahooWeatherAPI,transport:https,cachemaxage:600";
|
||||||
|
my $location;
|
||||||
|
my $interval = 3600;
|
||||||
|
my $lang = "en";
|
||||||
|
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
if($def =~ /=/) {
|
||||||
|
|
||||||
|
my $usage= "syntax: define <name> Weather location=<location> [API=<API>] [lang=<lang>]";
|
||||||
|
|
||||||
|
my ($arrayref, $hashref)= parseParams($def);
|
||||||
|
my @a= @{$arrayref};
|
||||||
|
my %h= %{$hashref};
|
||||||
|
|
||||||
|
return $usage unless(scalar @a == 2);
|
||||||
|
$name= $a[0];
|
||||||
|
|
||||||
|
return $usage unless exists $h{location};
|
||||||
|
$location= $h{location};
|
||||||
|
$lang= $h{lang} if exists $h{lang};
|
||||||
|
$interval= $h{interval} if exists $h{interval};
|
||||||
|
$API= $h{API} if exists $h{API};
|
||||||
|
|
||||||
return "syntax: define <name> Weather <location> [interval [en|de|nl]]"
|
} else {
|
||||||
if(int(@a) < 3 && int(@a) > 5);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
|
|
||||||
|
return "syntax: define <name> Weather <location> [interval [en|de|nl]]"
|
||||||
|
if(int(@a) < 3 && int(@a) > 5);
|
||||||
|
|
||||||
|
$name = $a[0];
|
||||||
|
$location = $a[2];
|
||||||
|
if(int(@a)>=4) { $interval= $a[3]; }
|
||||||
|
if(int(@a)==5) { $lang= $a[4]; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
my ($api,$apioptions)= split(',', $API, 2);
|
||||||
|
$apioptions= "" unless(defined($apioptions));
|
||||||
|
eval {
|
||||||
|
require "$api.pm";
|
||||||
|
};
|
||||||
|
return "$name: cannot load API $api: $@" if($@);
|
||||||
|
|
||||||
$hash->{NOTIFYDEV} = "global";
|
$hash->{NOTIFYDEV} = "global";
|
||||||
$hash->{STATE} = "Initialized";
|
$hash->{STATE} = "Initialized";
|
||||||
$hash->{fhem}{interfaces}= "temperature;humidity;wind";
|
$hash->{fhem}{interfaces}= "temperature;humidity;wind";
|
||||||
|
|
||||||
my $name = $a[0];
|
|
||||||
my $location = $a[2];
|
|
||||||
my $interval = 3600;
|
|
||||||
my $lang = "en";
|
|
||||||
if(int(@a)>=4) { $interval= $a[3]; }
|
|
||||||
if(int(@a)==5) { $lang= $a[4]; }
|
|
||||||
|
|
||||||
$hash->{LOCATION} = $location;
|
$hash->{LOCATION} = $location;
|
||||||
$hash->{INTERVAL} = $interval;
|
$hash->{INTERVAL} = $interval;
|
||||||
$hash->{LANG} = $lang;
|
$hash->{LANG} = $lang;
|
||||||
|
$hash->{API} = $api;
|
||||||
|
$hash->{APIOPTIONS} = $apioptions;
|
||||||
$hash->{UNITS} = "c"; # hardcoded to use degrees centigrade (Celsius)
|
$hash->{UNITS} = "c"; # hardcoded to use degrees centigrade (Celsius)
|
||||||
$hash->{READINGS}{current_date_time}{TIME}= TimeNow();
|
$hash->{READINGS}{current_date_time}{TIME}= TimeNow();
|
||||||
$hash->{READINGS}{current_date_time}{VAL}= "none";
|
$hash->{READINGS}{current_date_time}{VAL}= "none";
|
||||||
|
|
||||||
$hash->{fhem}{allowCache}= 1;
|
$hash->{fhem}{allowCache}= 1;
|
||||||
|
|
||||||
Weather_GetUpdate($hash) if($init_done);
|
Weather_GetUpdate($hash) if($init_done);
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -561,6 +595,9 @@ WeatherAsHtmlD($;$)
|
|||||||
1;
|
1;
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
=item device
|
||||||
|
=item summary provides current weather condition and forecast (source: Yahoo Weather API)
|
||||||
|
=item summary_DE stellt Wetterbericht und -vorhersage bereit (Quelle: Yahoo Weather API)
|
||||||
=begin html
|
=begin html
|
||||||
|
|
||||||
<a name="Weather"></a>
|
<a name="Weather"></a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user