2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 07:19:24 +00:00

50_HP1000.pm: implement Unit.pm support

git-svn-id: https://svn.fhem.de/fhem/trunk@12513 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2016-11-06 17:45:26 +00:00
parent 3097fd4bac
commit 4c8e85b7a5

View File

@ -30,7 +30,7 @@ use strict;
use warnings; use warnings;
use vars qw(%data); use vars qw(%data);
use HttpUtils; use HttpUtils;
use UConv; use Unit;
use Time::Local; use Time::Local;
use List::Util qw(sum); use List::Util qw(sum);
use FHEM::98_dewpoint; use FHEM::98_dewpoint;
@ -66,7 +66,7 @@ sub HP1000_Initialize($) {
$hash->{GetFn} = "HP1000_Get"; $hash->{GetFn} = "HP1000_Get";
$hash->{DefFn} = "HP1000_Define"; $hash->{DefFn} = "HP1000_Define";
$hash->{UndefFn} = "HP1000_Undefine"; $hash->{UndefFn} = "HP1000_Undefine";
$hash->{DbLog_splitFn} = "UConv::DbLog_split"; $hash->{DbLog_splitFn} = "Unit_DbLog_split";
$hash->{parseParams} = 1; $hash->{parseParams} = 1;
$hash->{AttrList} = $hash->{AttrList} =
@ -222,9 +222,9 @@ sub HP1000_SetAliveState($;$) {
my $activity = "dead"; my $activity = "dead";
$activity = "alive" if ($alive); $activity = "alive" if ($alive);
readingsBeginUpdate($hash); readingsUnitBeginUpdate($hash);
readingsBulkUpdateIfChanged( $hash, "Activity", $activity ); readingsUnitBulkUpdateIfChanged( $hash, "Activity", $activity );
readingsEndUpdate( $hash, 1 ); readingsUnitEndUpdate( $hash, 1 );
InternalTimer( gettimeofday() + 120, "HP1000_SetAliveState", $hash, 0 ); InternalTimer( gettimeofday() + 120, "HP1000_SetAliveState", $hash, 0 );
@ -646,7 +646,7 @@ sub HP1000_CGI() {
# write general readings # write general readings
# #
readingsBeginUpdate($hash); readingsUnitBeginUpdate($hash);
while ( ( my $p, my $v ) = each %$webArgs ) { while ( ( my $p, my $v ) = each %$webArgs ) {
@ -709,7 +709,7 @@ sub HP1000_CGI() {
$p = "wind_gust_mph" if ( $p eq "_windgustmph" ); $p = "wind_gust_mph" if ( $p eq "_windgustmph" );
$p = "wind_speed_mph" if ( $p eq "_windspdmph" ); $p = "wind_speed_mph" if ( $p eq "_windspdmph" );
readingsBulkUpdate( $hash, $p, $v ); readingsUnitBulkUpdate( $hash, $p, $v );
} }
# calculate additional readings # calculate additional readings
@ -719,120 +719,73 @@ sub HP1000_CGI() {
my $israining = 0; my $israining = 0;
$israining = 1 $israining = 1
if ( defined( $webArgs->{rainrate} ) && $webArgs->{rainrate} > 0 ); if ( defined( $webArgs->{rainrate} ) && $webArgs->{rainrate} > 0 );
readingsBulkUpdateIfChanged( $hash, "israining", $israining ); readingsUnitBulkUpdateIfChanged( $hash, "israining", $israining );
# daylight # daylight
my $daylight = 0; my $daylight = 0;
$daylight = 1 $daylight = 1
if ( defined( $webArgs->{light} ) && $webArgs->{light} > 50 ); if ( defined( $webArgs->{light} ) && $webArgs->{light} > 50 );
readingsBulkUpdateIfChanged( $hash, "daylight", $daylight ); readingsUnitBulkUpdateIfChanged( $hash, "daylight", $daylight );
# condition # condition
if ( defined( $webArgs->{light} ) ) { if ( defined( $webArgs->{light} ) ) {
my $condition = "clear"; my $temp = ( $webArgs->{outtemp} ? $webArgs->{outtemp} : "10" );
my $hum = ( $webArgs->{outhumi} ? $webArgs->{outhumi} : "50" );
if ($israining) { readingsUnitBulkUpdateIfChanged(
$condition = "rain"; $hash,
} "condition",
elsif ( $webArgs->{light} > 40000 ) { UConv::values2weathercondition(
$condition = "sunny"; $temp, $hum, $webArgs->{light}, $daylight, $israining
} )
elsif ($daylight) { );
$condition = "cloudy";
}
readingsBulkUpdateIfChanged( $hash, "condition", $condition );
} }
# humidityCondition # humidityCondition
if ( defined( $webArgs->{outhumi} ) ) { if ( defined( $webArgs->{outhumi} ) ) {
my $condition = "dry"; readingsUnitBulkUpdateIfChanged( $hash, "humidityCondition",
UConv::humidity2condition( $webArgs->{outhumi} ) );
if ( $webArgs->{outhumi} >= 80 && $israining ) {
$condition = "rain";
}
elsif ( $webArgs->{outhumi} >= 80 ) {
$condition = "wet";
}
elsif ( $webArgs->{outhumi} >= 70 ) {
$condition = "high";
}
elsif ( $webArgs->{outhumi} >= 50 ) {
$condition = "optimal";
}
elsif ( $webArgs->{outhumi} >= 40 ) {
$condition = "low";
}
readingsBulkUpdateIfChanged( $hash, "humidityCondition", $condition );
} }
# indoorHumidityCondition # indoorHumidityCondition
if ( defined( $webArgs->{inhumi} ) ) { if ( defined( $webArgs->{inhumi} ) ) {
my $condition = "dry"; readingsUnitBulkUpdateIfChanged( $hash, "indoorHumidityCondition",
UConv::humidity2condition( $webArgs->{inhumi} ) );
if ( $webArgs->{inhumi} >= 80 ) {
$condition = "wet";
}
elsif ( $webArgs->{inhumi} >= 70 ) {
$condition = "high";
}
elsif ( $webArgs->{inhumi} >= 50 ) {
$condition = "optimal";
}
elsif ( $webArgs->{inhumi} >= 40 ) {
$condition = "low";
}
readingsBulkUpdateIfChanged( $hash, "indoorHumidityCondition",
$condition );
} }
# UV (convert from uW/cm2) # UV (convert from uW/cm2)
if ( defined( $webArgs->{UV} ) ) { if ( defined( $webArgs->{UV} ) ) {
$webArgs->{UVI} = UConv::uwpscm2uvi( $webArgs->{UV} ); $webArgs->{UVI} = UConv::uwpscm2uvi( $webArgs->{UV} );
readingsBulkUpdate( $hash, "UV", $webArgs->{UVI} ); readingsUnitBulkUpdate( $hash, "UV", $webArgs->{UVI}, "uvi" );
} }
# UVcondition # UVcondition
if ( defined( $webArgs->{UVI} ) ) { if ( defined( $webArgs->{UVI} ) ) {
my $condition = "low"; readingsUnitBulkUpdateIfChanged( $hash, "UVcondition",
UConv::uvi2condition( $webArgs->{UVI} ) );
if ( $webArgs->{UVI} > 11 ) {
$condition = "extreme";
}
elsif ( $webArgs->{UVI} > 8 ) {
$condition = "veryhigh";
}
elsif ( $webArgs->{UVI} > 6 ) {
$condition = "high";
}
elsif ( $webArgs->{UVI} > 3 ) {
$condition = "moderate";
}
readingsBulkUpdateIfChanged( $hash, "UVcondition", $condition );
} }
# solarradiation in W/m2 (convert from lux) # solarradiation in W/m2 (convert from lux)
if ( defined( $webArgs->{light} ) ) { if ( defined( $webArgs->{light} ) ) {
$webArgs->{solarradiation} = $webArgs->{solarradiation} =
UConv::lux2wpsm( $webArgs->{light} ); UConv::lux2wpsm( $webArgs->{light} );
readingsBulkUpdate( $hash, "solarradiation", readingsUnitBulkUpdate( $hash, "solarradiation",
$webArgs->{solarradiation} ); $webArgs->{solarradiation}, "wpsm" );
} }
# pressure_mm in mmHg (convert from hpa) # pressure_mm in mmHg (convert from hpa)
if ( defined( $webArgs->{relbaro} ) ) { if ( defined( $webArgs->{relbaro} ) ) {
$webArgs->{barommm} = UConv::hpa2mmhg( $webArgs->{relbaro} ); $webArgs->{barommm} = UConv::hpa2mmhg( $webArgs->{relbaro} );
readingsBulkUpdate( $hash, "pressure_mm", $webArgs->{barommm} ); readingsUnitBulkUpdate( $hash, "pressure_mm", $webArgs->{barommm},
"mmhg" );
} }
# pressureAbs_mm in mmHg (convert from hpa) # pressureAbs_mm in mmHg (convert from hpa)
if ( defined( $webArgs->{absbaro} ) ) { if ( defined( $webArgs->{absbaro} ) ) {
$webArgs->{absbarommm} = $webArgs->{absbarommm} =
UConv::hpa2mmhg( $webArgs->{absbaro} ); UConv::hpa2mmhg( $webArgs->{absbaro} );
readingsBulkUpdate( $hash, "pressureAbs_mm", $webArgs->{absbarommm} ); readingsUnitBulkUpdate( $hash, "pressureAbs_mm",
$webArgs->{absbarommm}, "mmhg" );
} }
# indoorDewpoint in Celsius # indoorDewpoint in Celsius
@ -844,7 +797,8 @@ sub HP1000_CGI() {
); );
$webArgs->{indewpoint} = $webArgs->{indewpoint} =
round( dewpoint_dewpoint( $webArgs->{intemp}, $h ), 1 ); round( dewpoint_dewpoint( $webArgs->{intemp}, $h ), 1 );
readingsBulkUpdate( $hash, "indoorDewpoint", $webArgs->{indewpoint} ); readingsUnitBulkUpdate( $hash, "indoorDewpoint",
$webArgs->{indewpoint}, "c" );
} }
# indoorDewpoint in Fahrenheit # indoorDewpoint in Fahrenheit
@ -860,8 +814,8 @@ sub HP1000_CGI() {
); );
$webArgs->{indoordewpointf} = $webArgs->{indoordewpointf} =
round( dewpoint_dewpoint( $webArgs->{indoortempf}, $h ), 1 ); round( dewpoint_dewpoint( $webArgs->{indoortempf}, $h ), 1 );
readingsBulkUpdate( $hash, "indoorDewpoint_f", readingsUnitBulkUpdate( $hash, "indoorDewpoint_f",
$webArgs->{indoordewpointf} ); $webArgs->{indoordewpointf}, "f" );
} }
# humidityAbs / humidityAbs_f # humidityAbs / humidityAbs_f
@ -873,11 +827,12 @@ sub HP1000_CGI() {
); );
$webArgs->{outhumiabs} = $webArgs->{outhumiabs} =
round( dewpoint_absFeuchte( $webArgs->{outtemp}, $h ), 1 ); round( dewpoint_absFeuchte( $webArgs->{outtemp}, $h ), 1 );
readingsBulkUpdate( $hash, "humidityAbs", $webArgs->{outhumiabs} ); readingsUnitBulkUpdate( $hash, "humidityAbs", $webArgs->{outhumiabs} );
$webArgs->{outhumiabsf} = $webArgs->{outhumiabsf} =
round( dewpoint_absFeuchte( $webArgs->{outtempf}, $h ), 1 ); round( dewpoint_absFeuchte( $webArgs->{outtempf}, $h ), 1 );
readingsBulkUpdate( $hash, "humidityAbs_f", $webArgs->{outhumiabsf} ); readingsUnitBulkUpdate( $hash, "humidityAbs_f",
$webArgs->{outhumiabsf} );
} }
# indoorHumidityAbs # indoorHumidityAbs
@ -889,7 +844,8 @@ sub HP1000_CGI() {
); );
$webArgs->{inhumiabs} = $webArgs->{inhumiabs} =
round( dewpoint_absFeuchte( $webArgs->{intemp}, $h ), 1 ); round( dewpoint_absFeuchte( $webArgs->{intemp}, $h ), 1 );
readingsBulkUpdate( $hash, "indoorHumidityAbs", $webArgs->{inhumiabs} ); readingsUnitBulkUpdate( $hash, "indoorHumidityAbs",
$webArgs->{inhumiabs} );
} }
# indoorHumidityAbs_f # indoorHumidityAbs_f
@ -905,15 +861,15 @@ sub HP1000_CGI() {
); );
$webArgs->{indoorhumidityabsf} = $webArgs->{indoorhumidityabsf} =
round( dewpoint_absFeuchte( $webArgs->{indoortempf}, $h ), 1 ); round( dewpoint_absFeuchte( $webArgs->{indoortempf}, $h ), 1 );
readingsBulkUpdate( $hash, "indoorHumidityAbs_f", readingsUnitBulkUpdate( $hash, "indoorHumidityAbs_f",
$webArgs->{indoorhumidityabsf} ); $webArgs->{indoorhumidityabsf} );
} }
# wind_compasspoint # wind_compasspoint
if ( defined( $webArgs->{winddir} ) ) { if ( defined( $webArgs->{winddir} ) ) {
$webArgs->{windcompasspoint} = $webArgs->{windcompasspoint} =
UConv::degrees2compasspoint( $webArgs->{winddir} ); UConv::deg2compasspoint( $webArgs->{winddir} );
readingsBulkUpdate( $hash, "wind_compasspoint", readingsUnitBulkUpdate( $hash, "wind_compasspoint",
$webArgs->{windcompasspoint} ); $webArgs->{windcompasspoint} );
} }
@ -921,42 +877,47 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{windspeed} ) ) { if ( defined( $webArgs->{windspeed} ) ) {
$webArgs->{windspeedbft} = $webArgs->{windspeedbft} =
UConv::kph2bft( $webArgs->{windspeed} ); UConv::kph2bft( $webArgs->{windspeed} );
readingsBulkUpdate( $hash, "wind_speed_bft", $webArgs->{windspeedbft} ); readingsUnitBulkUpdate( $hash, "wind_speed_bft",
$webArgs->{windspeedbft} );
} }
# wind_speed_kn in kn (convert from km/h) # wind_speed_kn in kn (convert from km/h)
if ( defined( $webArgs->{windspeed} ) ) { if ( defined( $webArgs->{windspeed} ) ) {
my $v = UConv::kph2kn( $webArgs->{windspeed} ); my $v = UConv::kph2kn( $webArgs->{windspeed} );
$webArgs->{windspeedkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" ); $webArgs->{windspeedkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsBulkUpdate( $hash, "wind_speed_kn", $webArgs->{windspeedkn} ); readingsUnitBulkUpdate( $hash, "wind_speed_kn",
$webArgs->{windspeedkn} );
} }
# wind_speed_fts in ft/s (convert from mph) # wind_speed_fts in ft/s (convert from mph)
if ( defined( $webArgs->{windspeedmph} ) ) { if ( defined( $webArgs->{windspeedmph} ) ) {
my $v = UConv::mph2fts( $webArgs->{windspeedmph} ); my $v = UConv::mph2fts( $webArgs->{windspeedmph} );
$webArgs->{windspeedfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" ); $webArgs->{windspeedfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsBulkUpdate( $hash, "wind_speed_fts", $webArgs->{windspeedfts} ); readingsUnitBulkUpdate( $hash, "wind_speed_fts",
$webArgs->{windspeedfts} );
} }
# wind_gust_bft in Beaufort (convert from km/h) # wind_gust_bft in Beaufort (convert from km/h)
if ( defined( $webArgs->{windgust} ) ) { if ( defined( $webArgs->{windgust} ) ) {
$webArgs->{windgustbft} = $webArgs->{windgustbft} =
UConv::kph2bft( $webArgs->{windgust} ); UConv::kph2bft( $webArgs->{windgust} );
readingsBulkUpdate( $hash, "wind_gust_bft", $webArgs->{windgustbft} ); readingsUnitBulkUpdate( $hash, "wind_gust_bft",
$webArgs->{windgustbft} );
} }
# wind_gust_kn in m/s (convert from km/h) # wind_gust_kn in m/s (convert from km/h)
if ( defined( $webArgs->{windgust} ) ) { if ( defined( $webArgs->{windgust} ) ) {
my $v = UConv::kph2kn( $webArgs->{windgust} ); my $v = UConv::kph2kn( $webArgs->{windgust} );
$webArgs->{windgustkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" ); $webArgs->{windgustkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsBulkUpdate( $hash, "wind_gust_kn", $webArgs->{windgustkn} ); readingsUnitBulkUpdate( $hash, "wind_gust_kn", $webArgs->{windgustkn} );
} }
# wind_gust_fts ft/s (convert from mph) # wind_gust_fts ft/s (convert from mph)
if ( defined( $webArgs->{windgustmph} ) ) { if ( defined( $webArgs->{windgustmph} ) ) {
my $v = UConv::mph2fts( $webArgs->{windgustmph} ); my $v = UConv::mph2fts( $webArgs->{windgustmph} );
$webArgs->{windgustfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" ); $webArgs->{windgustfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsBulkUpdate( $hash, "wind_gust_fts", $webArgs->{windgustfts} ); readingsUnitBulkUpdate( $hash, "wind_gust_fts",
$webArgs->{windgustfts} );
} }
# averages/wind_direction_avg2m # averages/wind_direction_avg2m
@ -965,7 +926,7 @@ sub HP1000_CGI() {
HP1000_GetAvg( $hash, "winddir", 2 * 60, $webArgs->{winddir} ) ); HP1000_GetAvg( $hash, "winddir", 2 * 60, $webArgs->{winddir} ) );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsBulkUpdate( $hash, "wind_direction_avg2m", $v ); readingsUnitBulkUpdate( $hash, "wind_direction_avg2m", $v );
$webArgs->{winddir_avg2m} = $v; $webArgs->{winddir_avg2m} = $v;
} }
} }
@ -973,8 +934,8 @@ sub HP1000_CGI() {
# averages/wind_compasspoint_avg2m # averages/wind_compasspoint_avg2m
if ( defined( $webArgs->{winddir_avg2m} ) ) { if ( defined( $webArgs->{winddir_avg2m} ) ) {
$webArgs->{windcompasspoint_avg2m} = $webArgs->{windcompasspoint_avg2m} =
UConv::degrees2compasspoint( $webArgs->{winddir_avg2m} ); UConv::deg2compasspoint( $webArgs->{winddir_avg2m} );
readingsBulkUpdate( $hash, "wind_compasspoint_avg2m", readingsUnitBulkUpdate( $hash, "wind_compasspoint_avg2m",
$webArgs->{windcompasspoint_avg2m} ); $webArgs->{windcompasspoint_avg2m} );
} }
@ -984,7 +945,7 @@ sub HP1000_CGI() {
HP1000_GetAvg( $hash, "windspeed", 2 * 60, $webArgs->{windspeed} ); HP1000_GetAvg( $hash, "windspeed", 2 * 60, $webArgs->{windspeed} );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsBulkUpdate( $hash, "wind_speed_avg2m", $v ); readingsUnitBulkUpdate( $hash, "wind_speed_avg2m", $v );
$webArgs->{windspeed_avg2m} = $v; $webArgs->{windspeed_avg2m} = $v;
} }
} }
@ -995,7 +956,7 @@ sub HP1000_CGI() {
HP1000_GetAvg( $hash, "windspdmph", 2 * 60, $webArgs->{windspdmph} ); HP1000_GetAvg( $hash, "windspdmph", 2 * 60, $webArgs->{windspdmph} );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsBulkUpdate( $hash, "wind_speed_mph_avg2m", $v ); readingsUnitBulkUpdate( $hash, "wind_speed_mph_avg2m", $v );
$webArgs->{windspdmph_avg2m} = $v; $webArgs->{windspdmph_avg2m} = $v;
} }
} }
@ -1004,7 +965,7 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{windspeed_avg2m} ) ) { if ( defined( $webArgs->{windspeed_avg2m} ) ) {
$webArgs->{windspeedbft_avg2m} = $webArgs->{windspeedbft_avg2m} =
UConv::kph2bft( $webArgs->{windspeed_avg2m} ); UConv::kph2bft( $webArgs->{windspeed_avg2m} );
readingsBulkUpdate( $hash, "wind_speed_bft_avg2m", readingsUnitBulkUpdate( $hash, "wind_speed_bft_avg2m",
$webArgs->{windspeedbft_avg2m} ); $webArgs->{windspeedbft_avg2m} );
} }
@ -1012,7 +973,7 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{windspeed_avg2m} ) ) { if ( defined( $webArgs->{windspeed_avg2m} ) ) {
$webArgs->{windspeedkn_avg2m} = $webArgs->{windspeedkn_avg2m} =
UConv::kph2kn( $webArgs->{windspeed_avg2m} ); UConv::kph2kn( $webArgs->{windspeed_avg2m} );
readingsBulkUpdate( $hash, "wind_speed_kn_avg2m", readingsUnitBulkUpdate( $hash, "wind_speed_kn_avg2m",
$webArgs->{windspeedkn_avg2m} ); $webArgs->{windspeedkn_avg2m} );
} }
@ -1021,7 +982,7 @@ sub HP1000_CGI() {
my $v = UConv::kph2mps( $webArgs->{windspeed_avg2m} ); my $v = UConv::kph2mps( $webArgs->{windspeed_avg2m} );
$webArgs->{windspeedmps_avg2m} = $webArgs->{windspeedmps_avg2m} =
( $v > 0.5 ? round( $v, 1 ) : "0.0" ); ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsBulkUpdate( $hash, "wind_speed_mps_avg2m", readingsUnitBulkUpdate( $hash, "wind_speed_mps_avg2m",
$webArgs->{windspeedmps_avg2m} ); $webArgs->{windspeedmps_avg2m} );
} }
@ -1031,7 +992,7 @@ sub HP1000_CGI() {
HP1000_GetSum( $hash, "windgust", 10 * 60, $webArgs->{windgust} ); HP1000_GetSum( $hash, "windgust", 10 * 60, $webArgs->{windgust} );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsBulkUpdate( $hash, "wind_gust_sum10m", $v ); readingsUnitBulkUpdate( $hash, "wind_gust_sum10m", $v );
$webArgs->{windgust_10m} = $v; $webArgs->{windgust_10m} = $v;
} }
} }
@ -1043,7 +1004,7 @@ sub HP1000_CGI() {
$webArgs->{windgustmph} ); $webArgs->{windgustmph} );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsBulkUpdate( $hash, "wind_gust_mph_sum10m", $v ); readingsUnitBulkUpdate( $hash, "wind_gust_mph_sum10m", $v );
$webArgs->{windgustmph_10m} = $v; $webArgs->{windgustmph_10m} = $v;
} }
} }
@ -1061,30 +1022,16 @@ sub HP1000_CGI() {
# brightness in % ?? # brightness in % ??
# state # state
my @stateReadings = split( /\s+/, AttrVal( $name, "stateReadings", "" ) ); my $stateReadings = AttrVal( $name, "stateReadings", "" );
my $stateReadingsFormat = AttrVal( $name, "stateReadingsFormat", "0" );
my $stateReadingsLang = AttrVal( $name, "stateReadingsLang", "en" ); my $stateReadingsLang = AttrVal( $name, "stateReadingsLang", "en" );
foreach (@stateReadings) { my $stateReadingsFormat = AttrVal( $name, "stateReadingsFormat", "0" );
$_ =~ /^(\w+):?(\w+)?$/;
my $r = $1;
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 )
);
if ( defined($v2) ) { $result =
$result .= " " if ( $result ne "Initialized" ); getMultiValStatus( $name, $stateReadings,
$result = "" if ( $result eq "Initialized" ); $stateReadingsLang, $stateReadingsFormat );
$result .= "$n: $v2";
}
}
readingsBulkUpdate( $hash, "state", $result ); readingsUnitBulkUpdate( $hash, "state", $result );
readingsEndUpdate( $hash, 1 ); readingsUnitEndUpdate( $hash, 1 );
HP1000_PushWU( $hash, $webArgs ) HP1000_PushWU( $hash, $webArgs )
if AttrVal( $name, "wu_push", 0 ) eq "1"; if AttrVal( $name, "wu_push", 0 ) eq "1";
@ -1205,9 +1152,9 @@ sub HP1000_PushWU($$) {
my $return = "error: missing attributes wu_user and wu_password"; my $return = "error: missing attributes wu_user and wu_password";
readingsBeginUpdate($hash); readingsUnitBeginUpdate($hash);
readingsBulkUpdateIfChanged( $hash, "wu_state", $return ); readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return );
readingsEndUpdate( $hash, 1 ); readingsUnitEndUpdate( $hash, 1 );
return; return;
} }
@ -1281,9 +1228,9 @@ sub HP1000_ReturnSrv($$$) {
my $return = "error: connection timeout"; my $return = "error: connection timeout";
Log3 $name, 4, "HP1000 $name: EXTSRV HTTP " . $return; Log3 $name, 4, "HP1000 $name: EXTSRV HTTP " . $return;
readingsBeginUpdate($hash); readingsUnitBeginUpdate($hash);
readingsBulkUpdateIfChanged( $hash, "extsrv_state", $return ); readingsUnitBulkUpdateIfChanged( $hash, "extsrv_state", $return );
readingsEndUpdate( $hash, 1 ); readingsUnitEndUpdate( $hash, 1 );
} }
# data received # data received
@ -1298,9 +1245,9 @@ sub HP1000_ReturnSrv($$$) {
Log3 $name, $logprio, Log3 $name, $logprio,
"HP1000 $name: EXTSRV HTTP return: " . $param->{code} . " - $data"; "HP1000 $name: EXTSRV HTTP return: " . $param->{code} . " - $data";
readingsBeginUpdate($hash); readingsUnitBeginUpdate($hash);
readingsBulkUpdateIfChanged( $hash, "extsrv_state", $return ); readingsUnitBulkUpdateIfChanged( $hash, "extsrv_state", $return );
readingsEndUpdate( $hash, 1 ); readingsUnitEndUpdate( $hash, 1 );
} }
return; return;
@ -1317,9 +1264,9 @@ sub HP1000_ReturnWU($$$) {
my $return = "error: connection timeout"; my $return = "error: connection timeout";
Log3 $name, 4, "HP1000 $name: WU HTTP " . $return; Log3 $name, 4, "HP1000 $name: WU HTTP " . $return;
readingsBeginUpdate($hash); readingsUnitBeginUpdate($hash);
readingsBulkUpdateIfChanged( $hash, "wu_state", $return ); readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return );
readingsEndUpdate( $hash, 1 ); readingsUnitEndUpdate( $hash, 1 );
} }
# data received # data received
@ -1336,9 +1283,9 @@ sub HP1000_ReturnWU($$$) {
Log3 $name, $logprio, Log3 $name, $logprio,
"HP1000 $name: WU HTTP return: " . $param->{code} . " - $data"; "HP1000 $name: WU HTTP return: " . $param->{code} . " - $data";
readingsBeginUpdate($hash); readingsUnitBeginUpdate($hash);
readingsBulkUpdateIfChanged( $hash, "wu_state", $return ); readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return );
readingsEndUpdate( $hash, 1 ); readingsUnitEndUpdate( $hash, 1 );
} }
return; return;