mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +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:
|
||||
# 2013-07-28 initial release
|
||||
# 2013-07-29 fixed some typos
|
||||
# added "set <name> send"
|
||||
# 2013-07-29 fixed: some typos in documentation
|
||||
# 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;
|
||||
@ -45,7 +48,7 @@ use warnings;
|
||||
use POSIX;
|
||||
use HttpUtils;
|
||||
use JSON qw/decode_json/;
|
||||
use Try::Tiny;
|
||||
#use Try::Tiny;
|
||||
use feature qw/say switch/;
|
||||
|
||||
sub OWO_Set($@);
|
||||
@ -70,8 +73,9 @@ openweathermap_Initialize($)
|
||||
$hash->{AttrFn} = "OWO_Attr";
|
||||
|
||||
$hash->{AttrList} = "do_not_notify:0,1 loglevel:0,1,2,3,4,5 ".
|
||||
"owoApiKey owoDebug:0,1 owoGetUrl owoInterval ".
|
||||
"owoStation owoUser owoRaw:0,1 owoTimestamp:0,1 ".
|
||||
"owoGetUrl owoInterval:600,900,1800,3600 ".
|
||||
"owoApiKey owoStation owoUser ".
|
||||
"owoDebug:0,1 owoRaw:0,1 owoTimestamp:0,1 ".
|
||||
"owoSrc00 owoSrc01 owoSrc02 owoSrc03 owoSrc04 ".
|
||||
"owoSrc05 owoSrc06 owoSrc07 owoSrc08 owoSrc09 ".
|
||||
"owoSrc10 owoSrc11 owoSrc12 owoSrc13 owoSrc14 ".
|
||||
@ -325,19 +329,21 @@ UpdateReadings($$$){
|
||||
$url .= "&APPID=".AttrVal($name, "owoApiKey", "");
|
||||
$response = GetFileFromURL("$url");
|
||||
|
||||
if(defined($response)){
|
||||
if(AttrVal($name, "owoDebug", 1) == 1){
|
||||
Log $loglevel, "openweather $name response:\n$response";
|
||||
}
|
||||
|
||||
my $json = JSON->new->allow_nonref;
|
||||
try {
|
||||
$jsonWeather = $json->decode($response);
|
||||
} catch {
|
||||
Log $loglevel, "openweather $name error: JSPON decode";
|
||||
return undef;
|
||||
} finally {
|
||||
return undef;
|
||||
};
|
||||
eval {$jsonWeather = $json->decode($response)}; warn $@ if $@;
|
||||
} else {
|
||||
Log $loglevel, "openweather $name error: no response from server";
|
||||
}
|
||||
|
||||
if(defined($jsonWeather)){
|
||||
my @possibleReadings = ("sunrise", "sunset", "humidity", "pressureAbs", "pressureRel", "windSpeed", "windDir",
|
||||
"clouds", "rain3h", "snow3h", "temperature", "tempMin", "tempMax");
|
||||
|
||||
foreach(@possibleReadings) { CommandDeleteReading($name, $prefix.$_); }
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
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, "state", "active");
|
||||
readingsEndUpdate($hash, 1);
|
||||
|
||||
} else {
|
||||
Log $loglevel, "openweather $name error: update not possible!";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user