|
|
@@ -1,16 +1,16 @@
|
|
|
##############################################################################
|
|
|
-# $Id: 32_withings.pm 17341 2018-09-13 22:23:46Z moises $
|
|
|
+# $Id: 32_withings.pm 17431 2018-09-29 20:49:21Z moises $
|
|
|
#
|
|
|
# 32_withings.pm
|
|
|
#
|
|
|
-# 2017 Markus M.
|
|
|
+# 2018 Markus M.
|
|
|
# Based on original code by justme1968
|
|
|
#
|
|
|
# https://forum.fhem.de/index.php/topic,64944.0.html
|
|
|
#
|
|
|
#
|
|
|
##############################################################################
|
|
|
-# Release 06 / 2018-09-13
|
|
|
+# Release 08 / 2018-09-28
|
|
|
|
|
|
package main;
|
|
|
|
|
|
@@ -341,14 +341,18 @@ sub withings_Define($$) {
|
|
|
|
|
|
CommandAttr(undef,"$name IODev $a[4]");
|
|
|
|
|
|
- } elsif( @a == 4 && $a[2] =~ m/^\d+$/ && $a[3] =~ m/^[\w-]+$/i ) {
|
|
|
+ } elsif( @a == 4 && $a[2] =~ m/^\d+$/ && $a[3] =~ m/^[\w:-]+$/i ) {
|
|
|
$subtype = "USER";
|
|
|
|
|
|
my $user = $a[2];
|
|
|
my $key = $a[3];
|
|
|
|
|
|
+ my $accesskey = withings_encrypt($key);
|
|
|
+ Log3 $name, 3, "$name: encrypt $key to $accesskey" if($key ne $accesskey);
|
|
|
+ $hash->{DEF} = "$user $accesskey";
|
|
|
+
|
|
|
$hash->{User} = $user;
|
|
|
- $hash->{Key} = $key;
|
|
|
+ #$hash->{Key} = $accesskey; #not needed
|
|
|
|
|
|
my $d = $modules{$hash->{TYPE}}{defptr}{"U$user"};
|
|
|
return "device $user already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name );
|
|
|
@@ -380,13 +384,13 @@ sub withings_Define($$) {
|
|
|
}
|
|
|
|
|
|
$hash->{NAME} = $name;
|
|
|
- $hash->{SUBTYPE} = $subtype;
|
|
|
+ $hash->{SUBTYPE} = $subtype if(defined($subtype));
|
|
|
|
|
|
|
|
|
#CommandAttr(undef,"$name DbLogExclude .*");
|
|
|
|
|
|
|
|
|
- my $resolve = inet_aton("scalews.health.nokia.com");
|
|
|
+ my $resolve = inet_aton("scalews.withings.com");
|
|
|
if(!defined($resolve))
|
|
|
{
|
|
|
$hash->{STATE} = "DNS error";
|
|
|
@@ -418,7 +422,7 @@ sub withings_InitWait($) {
|
|
|
|
|
|
RemoveInternalTimer($hash);
|
|
|
|
|
|
- my $resolve = inet_aton("scalews.health.nokia.com");
|
|
|
+ my $resolve = inet_aton("scalews.withings.com");
|
|
|
if(!defined($resolve))
|
|
|
{
|
|
|
$hash->{STATE} = "DNS error";
|
|
|
@@ -448,7 +452,7 @@ sub withings_Notify($$) {
|
|
|
return if(!grep(m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}}));
|
|
|
Log3 "withings", 5, "withings: notify";
|
|
|
|
|
|
- my $resolve = inet_aton("scalews.health.nokia.com");
|
|
|
+ my $resolve = inet_aton("scalews.withings.com");
|
|
|
if(!defined($resolve))
|
|
|
{
|
|
|
$hash->{STATE} = "DNS error";
|
|
|
@@ -523,11 +527,11 @@ sub withings_getSessionKey($) {
|
|
|
|
|
|
return if( $hash->{SessionKey} && $hash->{SessionTimestamp} && gettimeofday() - $hash->{SessionTimestamp} < (60*60*24*7-3600) );
|
|
|
|
|
|
- my $resolve = inet_aton("account.health.nokia.com");
|
|
|
+ my $resolve = inet_aton("account.withings.com");
|
|
|
if(!defined($resolve))
|
|
|
{
|
|
|
$hash->{SessionTimestamp} = 0;
|
|
|
- Log3 "withings", 1, "$name: DNS error on getSessionData";
|
|
|
+ Log3 $name, 1, "$name: DNS error on getSessionData";
|
|
|
return undef;
|
|
|
}
|
|
|
|
|
|
@@ -537,24 +541,24 @@ sub withings_getSessionKey($) {
|
|
|
# if( !defined($hash->{helper}{appliver}) || !defined($hash->{helper}{csrf_token}) || !defined($hash->{SessionTimestamp}) || gettimeofday() - $hash->{SessionTimestamp} > (30*60) )#!defined($hash->{helper}{appliver}) || !defined($hash->{helper}{csrf_token}))
|
|
|
# {
|
|
|
# my($err0,$data0) = HttpUtils_BlockingGet({
|
|
|
- # url => $hash->{'.https'}."://scalews.health.nokia.com/",
|
|
|
+ # url => $hash->{'.https'}."://account.withings.com/",
|
|
|
# timeout => 10,
|
|
|
# noshutdown => 1,
|
|
|
# });
|
|
|
# if($err0 || !defined($data0))
|
|
|
# {
|
|
|
- # Log3 "withings", 1, "$name: appliver call failed! ".$err0;
|
|
|
+ # Log3 $name, 1, "$name: appliver call failed! ".$err0;
|
|
|
# return undef;
|
|
|
# }
|
|
|
# $data1 = $data0;
|
|
|
# $data0 =~ /appliver=([^.*]+)\&/;
|
|
|
# $hash->{helper}{appliver} = $1;
|
|
|
# if(!defined($hash->{helper}{appliver})) {
|
|
|
- # Log3 "withings", 1, "$name: APPLIVER ERROR ";
|
|
|
+ # Log3 $name, 1, "$name: APPLIVER ERROR ";
|
|
|
# $hash->{STATE} = "APPLIVER error";
|
|
|
# return undef;
|
|
|
# }
|
|
|
- # Log3 "withings", 4, "$name: appliver ".$hash->{helper}{appliver};
|
|
|
+ # Log3 $name, 4, "$name: appliver ".$hash->{helper}{appliver};
|
|
|
# #}
|
|
|
#
|
|
|
#
|
|
|
@@ -564,11 +568,11 @@ sub withings_getSessionKey($) {
|
|
|
# $hash->{helper}{csrf_token} = $1;
|
|
|
#
|
|
|
# if(!defined($hash->{helper}{csrf_token})) {
|
|
|
- # Log3 "withings", 1, "$name: CSRF ERROR ";
|
|
|
+ # Log3 $name, 1, "$name: CSRF ERROR ";
|
|
|
# $hash->{STATE} = "CSRF error";
|
|
|
# return undef;
|
|
|
# }
|
|
|
- # Log3 "withings", 4, "$name: csrf_token ".$hash->{helper}{csrf_token};
|
|
|
+ # Log3 $name, 4, "$name: csrf_token ".$hash->{helper}{csrf_token};
|
|
|
#}
|
|
|
|
|
|
#my $ua = LWP::UserAgent->new;
|
|
|
@@ -577,26 +581,26 @@ sub withings_getSessionKey($) {
|
|
|
#$request->content($get_data);
|
|
|
#my $response = $ua->request($request);
|
|
|
|
|
|
- # $resolve = inet_aton("account.health.nokia.com");
|
|
|
+ # $resolve = inet_aton("account.withings.com");
|
|
|
# if(!defined($resolve))
|
|
|
# {
|
|
|
- # Log3 "withings", 1, "$name: DNS error on getSessionKey.";
|
|
|
+ # Log3 $name, 1, "$name: DNS error on getSessionKey.";
|
|
|
# return undef;
|
|
|
# }
|
|
|
|
|
|
my $datahash = {
|
|
|
- url => $hash->{'.https'}."://account.health.nokia.com/connectionwou/account_login?r=https://dashboard.health.nokia.com/",
|
|
|
+ url => $hash->{'.https'}."://account.withings.com/connectionwou/account_login?r=https://healthmate.withings.com/",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
ignoreredirects => 1,
|
|
|
- data => { email=> withings_decrypt($hash->{helper}{username}), password => withings_decrypt($hash->{helper}{password}), is_admin => '' },
|
|
|
+ data => { email=> withings_decrypt($hash->{helper}{username}), password => withings_decrypt($hash->{helper}{password}), is_admin => 'f' },
|
|
|
};
|
|
|
|
|
|
my($err,$data) = HttpUtils_BlockingGet($datahash);
|
|
|
|
|
|
if ($err || !defined($data) || $data =~ /Authentification failed/ || $data =~ /not a valid/)
|
|
|
{
|
|
|
- Log3 "withings", 1, "$name: LOGIN ERROR ";
|
|
|
+ Log3 $name, 1, "$name: LOGIN ERROR ";
|
|
|
$hash->{STATE} = "Login error";
|
|
|
return undef;
|
|
|
}
|
|
|
@@ -608,12 +612,12 @@ sub withings_getSessionKey($) {
|
|
|
$hash->{SessionTimestamp} = (gettimeofday())[0] if( $hash->{SessionKey} );
|
|
|
$hash->{STATE} = "Connected" if( $hash->{SessionKey} );
|
|
|
$hash->{STATE} = "Session error" if( !$hash->{SessionKey} );
|
|
|
- Log3 "withings", 4, "$name: sessionkey ".$hash->{SessionKey};
|
|
|
+ Log3 $name, 4, "$name: sessionkey ".$hash->{SessionKey};
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$hash->{STATE} = "Cookie error";
|
|
|
- Log3 "withings", 1, "$name: COOKIE ERROR ";
|
|
|
+ Log3 $name, 1, "$name: COOKIE ERROR ";
|
|
|
$hash->{helper}{appliver} = '9855c478';
|
|
|
$hash->{helper}{csrf_token} = '9855c478';
|
|
|
return undef;
|
|
|
@@ -623,10 +627,10 @@ sub withings_getSessionKey($) {
|
|
|
if( !$hash->{AccountID} || length($hash->{AccountID} < 2 ) ) {
|
|
|
|
|
|
($err,$data) = HttpUtils_BlockingGet({
|
|
|
- url => $hash->{'.https'}."://scalews.withings.com/index/service/account",
|
|
|
+ url => $hash->{'.https'}."://scalews.withings.com/cgi-bin/account",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
- data => {sessionid => $hash->{SessionKey}, appname => 'my2', appliver=> $hash->{helper}{appliver}, apppfm => 'web', action => 'get'},
|
|
|
+ data => {sessionid => $hash->{SessionKey}, appname => 'my2', appliver=> $hash->{helper}{appliver}, apppfm => 'web', action => 'get', enrich => 't'},
|
|
|
});
|
|
|
return undef if(!defined($data));
|
|
|
|
|
|
@@ -648,15 +652,15 @@ sub withings_getSessionKey($) {
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Log3 "withings", 4, "$name: account email: ".$account->{email};
|
|
|
+ Log3 $name, 4, "$name: account email: ".$account->{email};
|
|
|
}
|
|
|
}
|
|
|
- Log3 "withings", 4, "$name: accountid ".$hash->{AccountID};
|
|
|
+ Log3 $name, 4, "$name: accountid ".$hash->{AccountID};
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$hash->{STATE} = "Account error";
|
|
|
- Log3 "withings", 1, "$name: ACCOUNT ERROR ";
|
|
|
+ Log3 $name, 1, "$name: ACCOUNT ERROR ";
|
|
|
return undef;
|
|
|
}
|
|
|
}
|
|
|
@@ -667,16 +671,15 @@ sub withings_getSessionKey($) {
|
|
|
sub withings_connect($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: connect";
|
|
|
+ Log3 $name, 5, "$name: connect";
|
|
|
|
|
|
$hash->{'.https'} = "https";
|
|
|
$hash->{'.https'} = "http" if( AttrVal($name, "nossl", 0) );
|
|
|
|
|
|
- #my $cmdret= CommandAttr(undef,"$name room WithingsTest");
|
|
|
- #$cmdret= CommandAttr(undef,"$name verbose 5");
|
|
|
-
|
|
|
withings_getSessionKey( $hash );
|
|
|
|
|
|
+ return undef; #no more autocreate on start
|
|
|
+
|
|
|
foreach my $d (keys %defs) {
|
|
|
next if(!defined($defs{$d}));
|
|
|
next if($defs{$d}{TYPE} ne "autocreate");
|
|
|
@@ -691,11 +694,12 @@ sub withings_connect($) {
|
|
|
Log3 $name, 2, "$name: user '$user->{id}' already defined";
|
|
|
next;
|
|
|
}
|
|
|
- next if($user->{firstname} eq "Repository-User");
|
|
|
+ next if($user->{usertype} ne "1" || $user->{status} ne "0");
|
|
|
|
|
|
my $id = $user->{id};
|
|
|
my $devname = "withings_U". $id;
|
|
|
- my $define= "$devname withings $id $user->{publickey}";
|
|
|
+ my $publickey = withings_encrypt($user->{publickey});
|
|
|
+ my $define= "$devname withings $id $publickey";
|
|
|
|
|
|
Log3 $name, 2, "$name: create new device '$devname' for user '$id'";
|
|
|
|
|
|
@@ -761,7 +765,7 @@ sub withings_connect($) {
|
|
|
sub withings_autocreate($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: autocreate";
|
|
|
+ Log3 $name, 5, "$name: autocreate";
|
|
|
|
|
|
$hash->{'.https'} = "https";
|
|
|
$hash->{'.https'} = "http" if( AttrVal($name, "nossl", 0) );
|
|
|
@@ -777,11 +781,12 @@ sub withings_autocreate($) {
|
|
|
Log3 $name, 2, "$name: user '$user->{id}' already defined";
|
|
|
next;
|
|
|
}
|
|
|
- next if($user->{firstname} eq "Repository-User");
|
|
|
+ next if($user->{usertype} ne "1" || $user->{status} ne "0");
|
|
|
|
|
|
my $id = $user->{id};
|
|
|
my $devname = "withings_U". $id;
|
|
|
- my $define= "$devname withings $id $user->{publickey}";
|
|
|
+ my $publickey = withings_encrypt($user->{publickey});
|
|
|
+ my $define= "$devname withings $id $publickey";
|
|
|
|
|
|
Log3 $name, 2, "$name: create new device '$devname' for user '$id'";
|
|
|
|
|
|
@@ -844,7 +849,7 @@ sub withings_autocreate($) {
|
|
|
sub withings_initDevice($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: initdevice ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: initdevice ".$hash->{Device};
|
|
|
|
|
|
AssignIoPort($hash);
|
|
|
if(defined($hash->{IODev}->{NAME})) {
|
|
|
@@ -904,7 +909,7 @@ sub withings_initDevice($) {
|
|
|
sub withings_initUser($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: inituser ".$hash->{User};
|
|
|
+ Log3 $name, 5, "$name: inituser ".$hash->{User};
|
|
|
|
|
|
AssignIoPort($hash);
|
|
|
if(defined($hash->{IODev}->{NAME})) {
|
|
|
@@ -936,12 +941,12 @@ sub withings_initUser($) {
|
|
|
sub withings_getUsers($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getusers";
|
|
|
+ Log3 $name, 5, "$name: getusers";
|
|
|
|
|
|
withings_getSessionKey($hash);
|
|
|
|
|
|
my ($err,$data) = HttpUtils_BlockingGet({
|
|
|
- url => $hash->{'.https'}."://scalews.health.nokia.com/index/service/account",
|
|
|
+ url => $hash->{'.https'}."://scalews.withings.com/cgi-bin/account",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{SessionKey}, accountid => $hash->{AccountID} , recurse_use => '1', recurse_devtype => '1', listmask => '5', allusers => 't' , appname => 'my2', appliver=> $hash->{helper}{appliver}, apppfm => 'web', action => 'getuserslist'},
|
|
|
@@ -977,7 +982,7 @@ sub withings_getUsers($) {
|
|
|
sub withings_getDevices($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getdevices";
|
|
|
+ Log3 $name, 5, "$name: getdevices";
|
|
|
|
|
|
withings_getSessionKey($hash);
|
|
|
|
|
|
@@ -989,7 +994,7 @@ sub withings_getDevices($) {
|
|
|
});
|
|
|
|
|
|
#my $ua = LWP::UserAgent->new;
|
|
|
- #my $request = HTTP::Request->new(POST => $hash->{'.https'}.'://healthmate.withings.com/index/service/association');
|
|
|
+ #my $request = HTTP::Request->new(POST => $hash->{'.https'}.'://scalews.withings.com/cgi-bin/association');
|
|
|
#my $get_data = 'sessionid='.$hash->{SessionKey}.'&accountid='.$hash->{AccountID}.'&type=-1&enrich=t&appname=my2&appliver='.$hash->{helper}{appliver}.'&apppfm=web&action=getbyaccountid';
|
|
|
#$request->content($get_data);
|
|
|
#my $response = $ua->request($request);
|
|
|
@@ -1002,7 +1007,7 @@ sub withings_getDevices($) {
|
|
|
return undef;
|
|
|
}
|
|
|
Log3 $name, 1, "withings: getDevices json error ".$json->{error} if(defined($json->{error}));
|
|
|
- Log3 "withings", 5, "$name: getdevices ".Dumper($json);
|
|
|
+ Log3 $name, 5, "$name: getdevices ".Dumper($json);
|
|
|
|
|
|
my @devices = ();
|
|
|
foreach my $association (@{$json->{body}{associations}}) {
|
|
|
@@ -1018,19 +1023,19 @@ sub withings_getDevices($) {
|
|
|
sub withings_getDeviceDetail($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getdevicedetail ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: getdevicedetail ".$hash->{Device};
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
|
|
|
my ($err,$data) = HttpUtils_BlockingGet({
|
|
|
- url => $hash->{'.https'}."://scalews.health.nokia.com/index/service/device",
|
|
|
+ url => $hash->{'.https'}."://scalews.withings.com/cgi-bin/device",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid => $hash->{Device} , appname => 'my2', appliver=> $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getproperties'},
|
|
|
});
|
|
|
|
|
|
- #Log3 "withings", 5, "$name: getdevicedetaildata ".Dumper($data);
|
|
|
+ #Log3 $name, 5, "$name: getdevicedetaildata ".Dumper($data);
|
|
|
return undef if(!defined($data));
|
|
|
|
|
|
my $json = eval { JSON->new->utf8(0)->decode($data) };
|
|
|
@@ -1066,13 +1071,13 @@ sub withings_getDeviceDetail($) {
|
|
|
sub withings_getDeviceLink($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getdevicelink ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: getdevicelink ".$hash->{Device};
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
|
|
|
my ($err,$data) = HttpUtils_BlockingGet({
|
|
|
- url => $hash->{'.https'}."://scalews.health.nokia.com/cgi-bin/association",
|
|
|
+ url => $hash->{'.https'}."://scalews.withings.com/cgi-bin/association",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, appname => 'hmw', appliver=> $hash->{IODev}->{helper}{appliver}, enrich => 't', action => 'getbyaccountid'},
|
|
|
@@ -1110,14 +1115,14 @@ sub withings_getDeviceProperties($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
|
|
|
- Log3 "withings", 5, "$name: getdeviceproperties ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: getdeviceproperties ".$hash->{Device};
|
|
|
return undef if( !defined($hash->{Device}) );
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/device",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/device",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getproperties'},
|
|
|
@@ -1140,7 +1145,7 @@ sub withings_getDeviceProperties($) {
|
|
|
sub withings_getDeviceReadingsScale($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getscalereadings ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: getscalereadings ".$hash->{Device};
|
|
|
return undef if( !defined($hash->{Device}) );
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
@@ -1153,7 +1158,7 @@ sub withings_getDeviceReadingsScale($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/measure",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, meastype => '12,35', startdate => int($lastupdate), enddate => int($enddate), devicetype => '16', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getmeashf'},
|
|
|
@@ -1175,7 +1180,7 @@ sub withings_getDeviceReadingsScale($) {
|
|
|
sub withings_getDeviceReadingsBedside($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getaurareadings ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: getaurareadings ".$hash->{Device};
|
|
|
return undef if( !defined($hash->{Device}) );
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
@@ -1188,7 +1193,7 @@ sub withings_getDeviceReadingsBedside($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/measure",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, meastype => '12,13,14,15,56', startdate => int($lastupdate), enddate => int($enddate), devicetype => '16', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getmeashf'},
|
|
|
@@ -1210,7 +1215,7 @@ sub withings_getDeviceReadingsBedside($) {
|
|
|
sub withings_getDeviceReadingsHome($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: gethomereadings ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: gethomereadings ".$hash->{Device};
|
|
|
return undef if( !defined($hash->{Device}) );
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
@@ -1223,7 +1228,7 @@ sub withings_getDeviceReadingsHome($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/measure",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, meastype => '12,13,14,15,58', startdate => int($lastupdate), enddate => int($enddate), devicetype => '16', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getmeashf'},
|
|
|
@@ -1245,7 +1250,7 @@ sub withings_getDeviceReadingsHome($) {
|
|
|
sub withings_getDeviceEventsBaby($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getbabyevents ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: getbabyevents ".$hash->{Device};
|
|
|
return undef if( !defined($hash->{Device}) );
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
@@ -1257,7 +1262,7 @@ sub withings_getDeviceEventsBaby($) {
|
|
|
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/event",
|
|
|
+ url => "https://scalews.withings.com/index/service/event",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {activated => '0', action => 'get', sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, type => '10,11,12,13,14,15,20', begindate => int($lastupdate)},
|
|
|
@@ -1280,7 +1285,7 @@ sub withings_getDeviceEventsBaby($) {
|
|
|
sub withings_getDeviceAlertsHome($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: gethomealerts ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: gethomealerts ".$hash->{Device};
|
|
|
return undef if( !defined($hash->{Device}) );
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
@@ -1291,7 +1296,7 @@ sub withings_getDeviceAlertsHome($) {
|
|
|
$lastupdate = $hash->{lastsessiondate} if(defined($hash->{lastsessiondate}) and $hash->{lastsessiondate} < $lastupdate);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.withings.net/cgi-bin/v2/timeline",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/timeline",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {type => '1', callctx => 'foreground', action => 'getbydeviceid', appname => 'HomeMonitor', apppfm => 'ios', appliver => '20000', sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, lastupdate => int($lastupdate) },
|
|
|
@@ -1313,7 +1318,7 @@ sub withings_getDeviceAlertsHome($) {
|
|
|
sub withings_getDeviceAlertsBaby($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getbabyevents ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: getbabyevents ".$hash->{Device};
|
|
|
return undef if( !defined($hash->{Device}) );
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
@@ -1324,7 +1329,7 @@ sub withings_getDeviceAlertsBaby($) {
|
|
|
$lastupdate = $hash->{lastsessiondate} if(defined($hash->{lastsessiondate}) and $hash->{lastsessiondate} < $lastupdate);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/event",
|
|
|
+ url => "https://scalews.withings.com/index/service/event",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {activated => '1', action => 'get', sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, type => '10,11,12,13,14,15,20', begindate => int($lastupdate)},
|
|
|
@@ -1345,7 +1350,7 @@ sub withings_getDeviceAlertsBaby($) {
|
|
|
sub withings_getVideoLink($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getbabyvideo ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: getbabyvideo ".$hash->{Device};
|
|
|
return undef if( !defined($hash->{Device}) );
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
@@ -1384,12 +1389,12 @@ sub withings_getS3Credentials($) {
|
|
|
return undef if( $hash->{sts_expiretime} && $hash->{sts_expiretime} > time - 3600 ); # min 1h
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
- Log3 "withings", 5, "$name: gets3credentials ".$hash->{Device};
|
|
|
+ Log3 $name, 5, "$name: gets3credentials ".$hash->{Device};
|
|
|
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
|
|
|
my ($err,$data) = HttpUtils_BlockingGet({
|
|
|
- url => $hash->{'.https'}."://scalews.withings.net/cgi-bin/v2/device",
|
|
|
+ url => $hash->{'.https'}."://scalews.withings.com/cgi-bin/v2/device",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
data => {callctx => 'foreground', action => 'getsts', deviceid => $hash->{Device}, appname => 'HomeMonitor', apppfm => 'ios' , appliver => '20000', sessionid => $hash->{IODev}->{SessionKey}},
|
|
|
@@ -1442,7 +1447,7 @@ sub withings_signS3Link($$$;$) {
|
|
|
sub withings_getUserDetail($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getuserdetails ".$hash->{User};
|
|
|
+ Log3 $name, 5, "$name: getuserdetails ".$hash->{User};
|
|
|
return undef if( !defined($hash->{User}) );
|
|
|
|
|
|
return undef if( $hash->{SUBTYPE} ne "USER" );
|
|
|
@@ -1451,7 +1456,7 @@ sub withings_getUserDetail($) {
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
|
|
|
my ($err,$data) = HttpUtils_BlockingGet({
|
|
|
- url => $hash->{'.https'}."://scalews.health.nokia.com/index/service/user",
|
|
|
+ url => $hash->{'.https'}."://scalews.withings.com/index/service/user",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid => $hash->{User} , appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getbyuserid'},
|
|
|
@@ -1481,7 +1486,7 @@ sub withings_poll($;$) {
|
|
|
return undef if(IsDisabled($name));
|
|
|
|
|
|
|
|
|
- #my $resolve = inet_aton("scalews.health.nokia.com");
|
|
|
+ #my $resolve = inet_aton("scalews.withings.com");
|
|
|
#if(!defined($resolve))
|
|
|
#{
|
|
|
# $hash->{STATE} = "DNS error";
|
|
|
@@ -1495,14 +1500,14 @@ sub withings_poll($;$) {
|
|
|
|
|
|
if( $hash->{SUBTYPE} eq "DEVICE" ) {
|
|
|
my $intervalData = AttrVal($name,"intervalData",900);
|
|
|
- my $intervalDebug = AttrVal($name,"intervalDebug",900);
|
|
|
+ my $intervalDebug = AttrVal($name,"intervalDebug",AttrVal($name,"intervalData",900));
|
|
|
+ my $intervalProperties = AttrVal($name,"intervalProperties",AttrVal($name,"intervalData",900));
|
|
|
my $lastData = ReadingsVal( $name, ".pollData", 0 );
|
|
|
my $lastDebug = ReadingsVal( $name, ".pollDebug", 0 );
|
|
|
- my $intervalProperties = AttrVal($name,"intervalProperties",43200);
|
|
|
my $lastProperties = ReadingsVal( $name, ".pollProperties", 0 );
|
|
|
|
|
|
if(defined($hash->{modelID}) && $hash->{modelID} eq '4') {
|
|
|
- withings_getDeviceProperties($hash) if($force > 1 || $lastData <= ($now - $intervalData));
|
|
|
+ withings_getDeviceProperties($hash) if($force > 1 || $lastProperties <= ($now - $intervalProperties));
|
|
|
withings_getDeviceReadingsScale($hash) if($force || $lastData <= ($now - $intervalData));
|
|
|
}
|
|
|
elsif(defined($hash->{modelID}) && $hash->{modelID} eq '21') {
|
|
|
@@ -1563,7 +1568,7 @@ sub withings_poll($;$) {
|
|
|
sub withings_getUserReadingsDaily($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getuserdailystats ".$hash->{User};
|
|
|
+ Log3 $name, 5, "$name: getuserdailystats ".$hash->{User};
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
@@ -1577,7 +1582,7 @@ sub withings_getUserReadingsDaily($) {
|
|
|
my $enddateymd = strftime("%Y-%m-%d", localtime($enddate));
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/cgi-bin/v2/aggregate",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/aggregate",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, range => '1', meastype => '36,37,38,40,41,49,50,51,52,53,87', startdateymd => $startdateymd, enddateymd => $enddateymd, appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getbyuserid'},
|
|
|
@@ -1595,7 +1600,7 @@ sub withings_getUserReadingsDaily($) {
|
|
|
$enddateymd = strftime("%Y-%m-%d", localtime($enddate));
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/cgi-bin/v2/activity",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/activity",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, subcategory => '37', startdateymd => $startdateymd, enddateymd => $enddateymd, appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getbyuserid'},
|
|
|
@@ -1606,7 +1611,7 @@ sub withings_getUserReadingsDaily($) {
|
|
|
});
|
|
|
|
|
|
# HttpUtils_NonblockingGet({
|
|
|
-# url => "https://scalews.health.nokia.com/cgi-bin/v2/activity",
|
|
|
+# url => "https://scalews.withings.com/cgi-bin/v2/activity",
|
|
|
# timeout => 60,
|
|
|
# noshutdown => 1,
|
|
|
# data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, startdateymd => $startdateymd, enddateymd => $enddateymd, appname => 'hmw', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getbyuserid'},
|
|
|
@@ -1630,7 +1635,7 @@ sub withings_getUserReadingsDaily($) {
|
|
|
sub withings_getUserReadingsCommon($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getuserreadings ".$hash->{User};
|
|
|
+ Log3 $name, 5, "$name: getuserreadings ".$hash->{User};
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
@@ -1641,7 +1646,7 @@ sub withings_getUserReadingsCommon($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/measure",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/measure",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, category => '1', userid=> $hash->{User}, offset => '0', limit => '400', startdate => int($lastupdate), enddate => int($enddate), appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getmeas'},
|
|
|
@@ -1666,7 +1671,7 @@ sub withings_getUserReadingsCommon($) {
|
|
|
sub withings_getUserReadingsSleep($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getsleepreadings ".$hash->{User};
|
|
|
+ Log3 $name, 5, "$name: getsleepreadings ".$hash->{User};
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
@@ -1679,7 +1684,7 @@ sub withings_getUserReadingsSleep($) {
|
|
|
# data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, meastype => '43,44,11,57,59,60,61,62,63,64,65,66,67,68,69,70', startdate => int($lastupdate), enddate => int($enddate), devicetype => '32', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getvasistas'},
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/measure",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, meastype => '11,39,41,43,44,57,59,87', startdate => int($lastupdate), enddate => int($enddate), devicetype => '32', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getvasistas'},
|
|
|
@@ -1701,7 +1706,7 @@ sub withings_getUserReadingsSleep($) {
|
|
|
sub withings_getUserReadingsSleepDebug($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
- Log3 "withings", 5, "$name: getsleepreadingsdebug ".$hash->{User};
|
|
|
+ Log3 $name, 5, "$name: getsleepreadingsdebug ".$hash->{User};
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
@@ -1713,7 +1718,7 @@ sub withings_getUserReadingsSleepDebug($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/measure",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, meastype => '60,61,62,63,64,65,66,67,68,69,70', startdate => int($lastupdate), enddate => int($enddate), devicetype => '32', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getvasistas'},
|
|
|
@@ -1737,7 +1742,7 @@ sub withings_getUserReadingsActivity($) {
|
|
|
my ($hash) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
|
|
|
- Log3 "withings", 5, "$name: getactivityreadings ".$hash->{User};
|
|
|
+ Log3 $name, 5, "$name: getactivityreadings ".$hash->{User};
|
|
|
|
|
|
return undef if( !defined($hash->{IODev}) );
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
@@ -1748,10 +1753,10 @@ sub withings_getUserReadingsActivity($) {
|
|
|
my $enddate = ($lastupdate+(8*60*60));
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
- Log3 "withings", 5, "$name: getactivityreadings ".$lastupdate." to ".$enddate;
|
|
|
+ Log3 $name, 5, "$name: getactivityreadings ".$lastupdate." to ".$enddate;
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
+ url => "https://scalews.withings.com/cgi-bin/v2/measure",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, meastype => '36,37,38,39,40,41,42,43,44,59,70,87,90', startdate => int($lastupdate), enddate => int($enddate), devicetype => '16', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getvasistas'},
|
|
|
@@ -1776,7 +1781,7 @@ sub withings_parseProperties($$) {
|
|
|
my ($hash,$json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
|
|
|
- Log3 "withings", 5, "$name: parsedevice";
|
|
|
+ Log3 $name, 5, "$name: parsedevice";
|
|
|
|
|
|
#parse
|
|
|
my $detail = $json->{body};
|
|
|
@@ -1799,7 +1804,7 @@ sub withings_parseMeasureGroups($$) {
|
|
|
my ($hash, $json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 5, "$name: parsemeasuregroups";
|
|
|
+ Log3 $name, 5, "$name: parsemeasuregroups";
|
|
|
my ($now) = int(time);
|
|
|
my $lastupdate = ReadingsVal( $name, ".lastData", ($now-21*24*60*60) );
|
|
|
my $newlastupdate = $lastupdate;
|
|
|
@@ -1831,6 +1836,7 @@ sub withings_parseMeasureGroups($$) {
|
|
|
readingsBulkUpdate( $hash, $reading, $value, 1 );
|
|
|
$hash->{CHANGETIME}[0] = FmtDateTime($measuregrp->{date});
|
|
|
readingsEndUpdate($hash,1);
|
|
|
+ $i++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1857,7 +1863,7 @@ sub withings_parseMeasureGroups($$) {
|
|
|
|
|
|
|
|
|
delete $hash->{CHANGETIME};
|
|
|
- Log3 $name, 3, "$name: got ".$i.' entries from MeasureGroups (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, (($i>0)?3:4), "$name: got ".$i.' entries from MeasureGroups (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -1867,7 +1873,7 @@ sub withings_parseMeasurements($$) {
|
|
|
my ($hash, $json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 4, "$name: parsemeasurements";
|
|
|
+ Log3 $name, 4, "$name: parsemeasurements";
|
|
|
my ($now) = time;
|
|
|
my $lastupdate = ReadingsVal( $name, ".lastData", ($now-21*24*60*60) );
|
|
|
my $newlastupdate = $lastupdate;
|
|
|
@@ -1910,7 +1916,7 @@ sub withings_parseMeasurements($$) {
|
|
|
readingsBulkUpdate( $hash, $reading->[1], $reading->[2], 1 );
|
|
|
$hash->{CHANGETIME}[0] = FmtDateTime($reading->[0]);;
|
|
|
readingsEndUpdate($hash,1);
|
|
|
-
|
|
|
+ $i++;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1939,7 +1945,7 @@ sub withings_parseMeasurements($$) {
|
|
|
|
|
|
|
|
|
delete $hash->{CHANGETIME};
|
|
|
- Log3 $name, 3, "$name: got ".$i.' entries from Measurements (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, (($i>0)?3:4), "$name: got ".$i.' entries from Measurements (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -1955,7 +1961,7 @@ sub withings_parseAggregate($$) {
|
|
|
my ($hash, $json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 5, "$name: parseaggregate";
|
|
|
+ Log3 $name, 5, "$name: parseaggregate";
|
|
|
|
|
|
#return undef;
|
|
|
my ($now) = time;
|
|
|
@@ -2032,7 +2038,7 @@ sub withings_parseAggregate($$) {
|
|
|
readingsBulkUpdate( $hash, $reading->[1], $reading->[2], 1 );
|
|
|
$hash->{CHANGETIME}[0] = FmtDateTime($reading->[0]);
|
|
|
readingsEndUpdate($hash,1);
|
|
|
-
|
|
|
+ $i++;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -2055,7 +2061,7 @@ sub withings_parseAggregate($$) {
|
|
|
|
|
|
|
|
|
delete $hash->{CHANGETIME};
|
|
|
- Log3 $name, 4, "$name: got ".$i.' entries from Aggregate (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, (($i>0)?3:4), "$name: got ".$i.' entries from Aggregate (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -2070,7 +2076,7 @@ sub withings_parseActivity($$) {
|
|
|
my ($hash, $json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 5, "$name: parseactivity";
|
|
|
+ Log3 $name, 5, "$name: parseactivity";
|
|
|
|
|
|
my ($now) = time;
|
|
|
my $lastupdate = ReadingsVal( $name, ".lastActivity", ($now-21*24*60*60) );
|
|
|
@@ -2129,7 +2135,7 @@ sub withings_parseActivity($$) {
|
|
|
readingsBulkUpdate( $hash, $reading->[1], $reading->[2], 1 );
|
|
|
$hash->{CHANGETIME}[0] = FmtDateTime($reading->[0]);
|
|
|
readingsEndUpdate($hash,1);
|
|
|
-
|
|
|
+ $i++;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -2151,7 +2157,7 @@ sub withings_parseActivity($$) {
|
|
|
|
|
|
|
|
|
delete $hash->{CHANGETIME};
|
|
|
- Log3 $name, 4, "$name: got ".$i.' entries from Activity (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, (($i>0)?3:4), "$name: got ".$i.' entries from Activity (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -2166,7 +2172,7 @@ sub withings_parseWorkouts($$) {
|
|
|
my ($hash, $json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 1, "$name: parseworkouts\n".Dumper($json);
|
|
|
+ Log3 $name, 1, "$name: parseworkouts\n".Dumper($json);
|
|
|
|
|
|
return undef;
|
|
|
|
|
|
@@ -2179,7 +2185,7 @@ sub withings_parseVasistas($$;$) {
|
|
|
my ($hash, $json, $datatype) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 5, "$name: parsevasistas";
|
|
|
+ Log3 $name, 5, "$name: parsevasistas";
|
|
|
|
|
|
my ($now) = time;
|
|
|
my $lastupdate = ReadingsVal( $name, ".lastData", ($now-21*24*60*60) );
|
|
|
@@ -2195,7 +2201,7 @@ sub withings_parseVasistas($$;$) {
|
|
|
my $readingsdate;
|
|
|
my $newlastupdate = $lastupdate;
|
|
|
|
|
|
-
|
|
|
+ my $iscurrent = 0;
|
|
|
|
|
|
foreach my $series ( @{$json->{body}{series}}) {
|
|
|
$j=0;
|
|
|
@@ -2249,8 +2255,21 @@ sub withings_parseVasistas($$;$) {
|
|
|
|
|
|
if($updatetype ne "unknown") {
|
|
|
$newlastupdate = $readingsdate if($readingsdate > $newlastupdate);
|
|
|
+ $i++;
|
|
|
}
|
|
|
-
|
|
|
+#start in-bed detection
|
|
|
+ if($iscurrent == 0 && $datatype =~ /Sleep/){
|
|
|
+ if($i>40 && $readingsdate > time()-3600){
|
|
|
+ $iscurrent = 1;
|
|
|
+ #Log3 $name, 1, "$name: in-bed: ".FmtDateTime($readingsdate) if($i>0);
|
|
|
+ readingsBeginUpdate($hash);
|
|
|
+ $hash->{".updateTimestamp"} = FmtDateTime($readingsdate);
|
|
|
+ readingsBulkUpdate( $hash, "in_bed", 1, 1 );
|
|
|
+ $hash->{CHANGETIME}[0] = FmtDateTime($readingsdate);
|
|
|
+ readingsEndUpdate($hash,1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+#end in-bed detection
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -2261,6 +2280,15 @@ sub withings_parseVasistas($$;$) {
|
|
|
$newlastupdate = $device->{lastsessiondate} if($device->{lastsessiondate} and $device->{lastsessiondate} < $newlastupdate);
|
|
|
$newlastupdate = $device->{lastweighindate} if($device->{lastweighindate} and $device->{lastweighindate} < $newlastupdate);
|
|
|
|
|
|
+ #start in-bed detection
|
|
|
+ if($datatype =~ /Sleep/ && $iscurrent == 0){
|
|
|
+ if($device->{lastweighindate} > (time()-1800)){
|
|
|
+ readingsSingleUpdate( $hash, "in_bed", 1, 1 );
|
|
|
+ } else {
|
|
|
+ readingsSingleUpdate( $hash, "in_bed", 0, 1 );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #end in-bed detection
|
|
|
}
|
|
|
$newlastupdate = $now if($newlastupdate > $now);
|
|
|
if($newlastupdate < ($lastupdate-1))
|
|
|
@@ -2282,7 +2310,7 @@ sub withings_parseVasistas($$;$) {
|
|
|
readingsSingleUpdate( $hash, ".lastData", $newlastupdate, 0 );
|
|
|
}
|
|
|
|
|
|
- Log3 $name, 4, "$name: got ".$i.' entries from Vasistas (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, (($i>0)?3:4), "$name: got ".$i.' entries from Vasistas (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -2295,7 +2323,7 @@ sub withings_parseTimeline($$) {
|
|
|
my ($hash, $json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 5, "$name: parsemetimeline ";
|
|
|
+ Log3 $name, 5, "$name: parsemetimeline ";
|
|
|
|
|
|
my ($now) = time;
|
|
|
my $lastupdate = ReadingsVal( $name, ".lastAlert", ($now-21*24*60*60) );
|
|
|
@@ -2319,12 +2347,12 @@ sub withings_parseTimeline($$) {
|
|
|
}
|
|
|
elsif($event->{class} eq 'deleted')
|
|
|
{
|
|
|
- Log3 "withings", 5, "withings: event " . FmtDateTime($event->{epoch})." Event was deleted";
|
|
|
+ Log3 $name, 5, "withings: event " . FmtDateTime($event->{epoch})." Event was deleted";
|
|
|
next;
|
|
|
}
|
|
|
elsif($event->{class} ne 'noise_detected' && $event->{class} ne 'movement_detected' && $event->{class} ne 'alert_environment' && $event->{class} ne 'offline' && $event->{class} ne 'online' && $event->{class} ne 'snapshot')
|
|
|
{
|
|
|
- Log3 "withings", 2, "withings: alert class unknown " . $event->{class};
|
|
|
+ Log3 $name, 2, "withings: alert class unknown " . $event->{class};
|
|
|
next;
|
|
|
}
|
|
|
|
|
|
@@ -2344,7 +2372,7 @@ sub withings_parseTimeline($$) {
|
|
|
readingsBulkUpdate( $hash, $reading, $value, 1 );
|
|
|
$hash->{CHANGETIME}[0] = FmtDateTime($event->{epoch});
|
|
|
readingsEndUpdate($hash,1);
|
|
|
-
|
|
|
+ $i++;
|
|
|
}
|
|
|
if(AttrVal($name,"videoLinkEvents",0) eq "1")
|
|
|
{
|
|
|
@@ -2375,7 +2403,7 @@ sub withings_parseTimeline($$) {
|
|
|
|
|
|
|
|
|
delete $hash->{CHANGETIME};
|
|
|
- Log3 $name, 4, "$name: got ".$i.' entries from Timeline (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, (($i>0)?3:4), "$name: got ".$i.' entries from Timeline (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -2386,7 +2414,7 @@ sub withings_parseEvents($$) {
|
|
|
my ($hash, $json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 5, "$name: parseevents";
|
|
|
+ Log3 $name, 5, "$name: parseevents";
|
|
|
my ($now) = time;
|
|
|
my $lastupdate = ReadingsVal( $name, ".lastData", ($now-21*24*60*60) );
|
|
|
my $lastalertupdate = ReadingsVal( $name, ".lastAlert", ($now-21*24*60*60) );
|
|
|
@@ -2408,7 +2436,7 @@ sub withings_parseEvents($$) {
|
|
|
$hash->{".updateTimestamp"} = FmtDateTime($event->{date});
|
|
|
my $changeindex = 0;
|
|
|
|
|
|
- #Log3 "withings", 5, "withings: event " . FmtDateTime($event->{date})." ".$event->{type}." ".$event->{activated}."/".$event->{measure}{value};
|
|
|
+ #Log3 $name, 5, "withings: event " . FmtDateTime($event->{date})." ".$event->{type}." ".$event->{activated}."/".$event->{measure}{value};
|
|
|
|
|
|
my $reading = $event_types{$event->{type}}->{reading};
|
|
|
my $value = "notice";
|
|
|
@@ -2449,7 +2477,7 @@ sub withings_parseEvents($$) {
|
|
|
|
|
|
|
|
|
readingsEndUpdate($hash,1);
|
|
|
-
|
|
|
+ $i++;
|
|
|
}
|
|
|
|
|
|
if($newlastupdate == $lastupdate and $i == 0)
|
|
|
@@ -2480,7 +2508,7 @@ sub withings_parseEvents($$) {
|
|
|
|
|
|
|
|
|
delete $hash->{CHANGETIME};
|
|
|
- Log3 $name, 4, "$name: got ".$i.' entries from Events (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, (($i>0)?3:4), "$name: got ".$i.' entries from Events (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -2548,10 +2576,10 @@ sub withings_Get($$@) {
|
|
|
my $users = withings_getUsers($hash);
|
|
|
my $ret;
|
|
|
foreach my $user (@{$users}) {
|
|
|
- $ret .= "$user->{id}\t\[$user->{shortname}\]\t$user->{publickey}\t$user->{firstname} $user->{lastname}\n";
|
|
|
+ $ret .= "$user->{id}\t\[$user->{shortname}\]\t$user->{publickey} \t$user->{usertype}/$user->{status}\t$user->{firstname} $user->{lastname}\n";
|
|
|
}
|
|
|
|
|
|
- $ret = "id\tshort\tpublickey\t\tname\n" . $ret if( $ret );;
|
|
|
+ $ret = "id\tshort\tpublickey\tusertype/status\tname\n" . $ret if( $ret );;
|
|
|
$ret = "no users found" if( !$ret );
|
|
|
return $ret;
|
|
|
}
|
|
|
@@ -3170,7 +3198,7 @@ sub withings_Dispatch($$$) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on dispatch type ".$param->{type}." ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
- Log3 $name, 1, "withings: Dispatch ".$param->{type}." json error ".$json->{error} if(defined($json->{error}));
|
|
|
+ Log3 $name, 1, "$name: Dispatch ".$param->{type}." json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
Log3 $name, 5, "$name: json returned: ".Dumper($json);
|
|
|
|