mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 07:19:24 +00:00
59_Wunderground: add stateReadingsFormat
git-svn-id: https://svn.fhem.de/fhem/trunk@12499 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
0cf0f343d3
commit
fd1f4fa73a
@ -54,7 +54,7 @@ sub Wunderground_Initialize($) {
|
|||||||
$hash->{parseParams} = 1;
|
$hash->{parseParams} = 1;
|
||||||
|
|
||||||
$hash->{AttrList} =
|
$hash->{AttrList} =
|
||||||
"disable:0,1 timeout:1,2,3,4,5 pollInterval:300,450,600,750,900 wu_lang:en,de,at,ch,nl,fr,pl stateReadings "
|
"disable:0,1 timeout:1,2,3,4,5 pollInterval:300,450,600,750,900 wu_lang:en,de,at,ch,nl,fr,pl stateReadings stateReadingsFormat:0,1,2 "
|
||||||
. $readingFnAttributes;
|
. $readingFnAttributes;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -157,6 +157,7 @@ sub Wunderground_Define($$$) {
|
|||||||
|
|
||||||
if ( $init_done && !defined( $hash->{OLDDEF} ) ) {
|
if ( $init_done && !defined( $hash->{OLDDEF} ) ) {
|
||||||
fhem 'attr ' . $name . ' stateReadings temp_c humidity';
|
fhem 'attr ' . $name . ' stateReadings temp_c humidity';
|
||||||
|
fhem 'attr ' . $name . ' stateReadingsFormat 1';
|
||||||
}
|
}
|
||||||
|
|
||||||
# start the status update timer
|
# start the status update timer
|
||||||
@ -284,16 +285,24 @@ sub Wunderground_ReceiveCommand($$$) {
|
|||||||
|
|
||||||
# state
|
# state
|
||||||
my @stateReadings = split( /\s+/, AttrVal( $name, "stateReadings", "" ) );
|
my @stateReadings = split( /\s+/, AttrVal( $name, "stateReadings", "" ) );
|
||||||
|
my $stateReadingsFormat = AttrVal( $name, "stateReadingsFormat", "0" );
|
||||||
|
my $stateReadingsLang = AttrVal( $name, "wu_lang", "en" );
|
||||||
foreach (@stateReadings) {
|
foreach (@stateReadings) {
|
||||||
$_ =~ /^(\w+):?(\w+)?$/;
|
$_ =~ /^(\w+):?(\w+)?$/;
|
||||||
my $r = $1;
|
my $r = $1;
|
||||||
my $n = ( $2 ? $2 : UConv::rname2rsname($r) );
|
my $v = ReadingsVal( $name, $r, undef );
|
||||||
|
my $u = UConv::rname2unitDetails( $r, $stateReadingsLang, $v );
|
||||||
|
my $n = ( $2 ? $2 : ( $u->{"short"} ? $u->{"short"} : $1 ) );
|
||||||
|
my $v2 = (
|
||||||
|
$stateReadingsFormat eq "2"
|
||||||
|
? $u->{"value_unit_long"}
|
||||||
|
: ( $stateReadingsFormat eq "1" ? $u->{"value_unit"} : $v )
|
||||||
|
);
|
||||||
|
|
||||||
my $v = ReadingsVal( $name, $r, undef );
|
if ( defined($v2) ) {
|
||||||
if ( defined($v) ) {
|
|
||||||
$state .= " " if ( $state ne "Initialized" );
|
$state .= " " if ( $state ne "Initialized" );
|
||||||
$state = "" if ( $state eq "Initialized" );
|
$state = "" if ( $state eq "Initialized" );
|
||||||
$state .= "$n: $v";
|
$state .= "$n: $v2";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user