mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-30 18:12:28 +00:00
replaced: try/catch by eval
added: some more logging added: delete some station readings before update git-svn-id: https://svn.fhem.de/fhem/trunk@3543 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
51fe35dc19
commit
9fa03c9912
@ -34,8 +34,11 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
# Changelog:
|
# Changelog:
|
||||||
# 2013-07-28 initial release
|
# 2013-07-28 initial release
|
||||||
# 2013-07-29 fixed some typos
|
# 2013-07-29 fixed: some typos in documentation
|
||||||
# added "set <name> send"
|
# added: "set <name> send"
|
||||||
|
# 2013-07-30 replaced: try/catch by eval
|
||||||
|
# added: some more logging
|
||||||
|
# added: delete some station readings before update
|
||||||
#
|
#
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
@ -45,7 +48,7 @@ use warnings;
|
|||||||
use POSIX;
|
use POSIX;
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
use JSON qw/decode_json/;
|
use JSON qw/decode_json/;
|
||||||
use Try::Tiny;
|
#use Try::Tiny;
|
||||||
use feature qw/say switch/;
|
use feature qw/say switch/;
|
||||||
|
|
||||||
sub OWO_Set($@);
|
sub OWO_Set($@);
|
||||||
@ -70,8 +73,9 @@ openweathermap_Initialize($)
|
|||||||
$hash->{AttrFn} = "OWO_Attr";
|
$hash->{AttrFn} = "OWO_Attr";
|
||||||
|
|
||||||
$hash->{AttrList} = "do_not_notify:0,1 loglevel:0,1,2,3,4,5 ".
|
$hash->{AttrList} = "do_not_notify:0,1 loglevel:0,1,2,3,4,5 ".
|
||||||
"owoApiKey owoDebug:0,1 owoGetUrl owoInterval ".
|
"owoGetUrl owoInterval:600,900,1800,3600 ".
|
||||||
"owoStation owoUser owoRaw:0,1 owoTimestamp:0,1 ".
|
"owoApiKey owoStation owoUser ".
|
||||||
|
"owoDebug:0,1 owoRaw:0,1 owoTimestamp:0,1 ".
|
||||||
"owoSrc00 owoSrc01 owoSrc02 owoSrc03 owoSrc04 ".
|
"owoSrc00 owoSrc01 owoSrc02 owoSrc03 owoSrc04 ".
|
||||||
"owoSrc05 owoSrc06 owoSrc07 owoSrc08 owoSrc09 ".
|
"owoSrc05 owoSrc06 owoSrc07 owoSrc08 owoSrc09 ".
|
||||||
"owoSrc10 owoSrc11 owoSrc12 owoSrc13 owoSrc14 ".
|
"owoSrc10 owoSrc11 owoSrc12 owoSrc13 owoSrc14 ".
|
||||||
@ -325,19 +329,21 @@ UpdateReadings($$$){
|
|||||||
$url .= "&APPID=".AttrVal($name, "owoApiKey", "");
|
$url .= "&APPID=".AttrVal($name, "owoApiKey", "");
|
||||||
$response = GetFileFromURL("$url");
|
$response = GetFileFromURL("$url");
|
||||||
|
|
||||||
|
if(defined($response)){
|
||||||
if(AttrVal($name, "owoDebug", 1) == 1){
|
if(AttrVal($name, "owoDebug", 1) == 1){
|
||||||
Log $loglevel, "openweather $name response:\n$response";
|
Log $loglevel, "openweather $name response:\n$response";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $json = JSON->new->allow_nonref;
|
my $json = JSON->new->allow_nonref;
|
||||||
try {
|
eval {$jsonWeather = $json->decode($response)}; warn $@ if $@;
|
||||||
$jsonWeather = $json->decode($response);
|
} else {
|
||||||
} catch {
|
Log $loglevel, "openweather $name error: no response from server";
|
||||||
Log $loglevel, "openweather $name error: JSPON decode";
|
}
|
||||||
return undef;
|
|
||||||
} finally {
|
if(defined($jsonWeather)){
|
||||||
return undef;
|
my @possibleReadings = ("sunrise", "sunset", "humidity", "pressureAbs", "pressureRel", "windSpeed", "windDir",
|
||||||
};
|
"clouds", "rain3h", "snow3h", "temperature", "tempMin", "tempMax");
|
||||||
|
|
||||||
|
foreach(@possibleReadings) { CommandDeleteReading($name, $prefix.$_); }
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
if(AttrVal($name, "owoRaw", 0) == 1){
|
if(AttrVal($name, "owoRaw", 0) == 1){
|
||||||
@ -372,7 +378,9 @@ UpdateReadings($$$){
|
|||||||
readingsBulkUpdate($hash, $prefix."tempMax", sprintf("%.1f",$jsonWeather->{main}{temp_max}-273.15));
|
readingsBulkUpdate($hash, $prefix."tempMax", sprintf("%.1f",$jsonWeather->{main}{temp_max}-273.15));
|
||||||
readingsBulkUpdate($hash, "state", "active");
|
readingsBulkUpdate($hash, "state", "active");
|
||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
|
} else {
|
||||||
|
Log $loglevel, "openweather $name error: update not possible!";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user