2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 05:16:45 +00:00

module: 48_JawboneUp: Only update readings on change, use BulkUpdate

git-svn-id: https://svn.fhem.de/fhem/trunk@8351 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
domschlo 2015-04-02 17:33:24 +00:00
parent a78be9d060
commit 899c14d8d5

View File

@ -222,6 +222,14 @@ sub jawboneUp_DoBackground($)
} }
############ Accept result from background process: ############## ############ Accept result from background process: ##############
sub updReading($$$) {
my ($hash,$name,$val) = @_;
if ($hash->{READINGS}{$name}{VAL} != $val) {
readingsBulkUpdate($hash,$name,$val,1);
}
}
sub jawboneUp_DoneBackground($) sub jawboneUp_DoneBackground($)
{ {
my ($string) = @_; my ($string) = @_;
@ -263,20 +271,23 @@ sub jawboneUp_DoneBackground($)
$hash->{"API_Status"} = "API Failure. Unexpected format of return values: )".$string; $hash->{"API_Status"} = "API Failure. Unexpected format of return values: )".$string;
return undef; return undef;
} }
readingsSingleUpdate($hash,"bg_steps",$a[2],1);
readingsSingleUpdate($hash,"calories",$a[3],1); readingsBeginUpdate($hash);
readingsSingleUpdate($hash,"distance",$a[4],1); updReading($hash,"bg_steps",$a[2]);
readingsSingleUpdate($hash,"bmr_calories",$a[5],1); updReading($hash,"calories",$a[3]);
readingsSingleUpdate($hash,"bmr_calories_day",$a[6],1); updReading($hash,"distance",$a[4]);
readingsSingleUpdate($hash,"active_time",$a[7],1); updReading($hash,"bmr_calories",$a[5]);
readingsSingleUpdate($hash,"longest_idle",$a[8],1); updReading($hash,"bmr_calories_day",$a[6]);
updReading($hash,"active_time",$a[7]);
updReading($hash,"longest_idle",$a[8]);
readingsSingleUpdate($hash,"sleep_awake",$a[9],1); updReading($hash,"sleep_awake",$a[9]);
readingsSingleUpdate($hash,"sleep_asleep",$a[10],1); updReading($hash,"sleep_asleep",$a[10]);
readingsSingleUpdate($hash,"sleep_mode",$a[11],1);
readingsSingleUpdate($hash,"stopwatch_mode",$a[12],1);
updReading($hash,"sleep_mode",$a[11]);
updReading($hash,"stopwatch_mode",$a[12]);
readingsEndUpdate($hash, 1);
$hash->{LAST_POLL} = FmtDateTime( gettimeofday() ); $hash->{LAST_POLL} = FmtDateTime( gettimeofday() );
$hash->{STATE} = "Connected"; $hash->{STATE} = "Connected";