2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-25 16:05:19 +00:00

98_livetracking: fixed Life360 login

git-svn-id: https://svn.fhem.de/fhem/trunk@26833 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
moises 2022-12-10 23:32:26 +00:00
parent e045180d32
commit f25cbb357e
3 changed files with 84 additions and 55 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- bugfix: 98_livetracking: fixed Life360 login
- bugfix: 10_KNX: fix bug introduced w. last change, Forum #122582
- bugfix: 93_DbRep: fix diffValue for newer MariaDB Forum: #130697
- change: 98_todoist: API v9, please check

View File

@ -524,6 +524,10 @@ sub allergy_utf8clean($) {
<br>
Daily levels for all allergens that are not being ignored due to <i>ignoreList</i>
</li><br>
<li><code>date</code>
<br>
Forecast end date from alternative data source
</li><br>
</ul>
<br>
<b>Attributes</b>
@ -602,6 +606,10 @@ sub allergy_utf8clean($) {
<br>
Tägliche Werte für alle Allergene, die nicht aufgrund der Ignoreliste <i>(attr ignoreList)</i> ignoriert werden.
</li><br>
<li><code>date</code>
<br>
Vorhersage-End-Datum bei alternativer Datenquelle
</li><br>
</ul>
<br>
<b>Attribute</b>

View File

@ -195,7 +195,7 @@ sub livetracking_Set($$@) {
elsif($command eq "BootstrapLife360")
{
$hash->{helper}{life360_script} = "";
$hash->{helper}{life360_secret} = "";
#$hash->{helper}{life360_secret} = "";
$hash->{helper}{life360_token} = "";
livetracking_BootstrapLife360($hash);
}
@ -414,7 +414,7 @@ sub livetracking_GetLife360($) {
my $circle = $attr{$name}{life360_circle};
my $userid = $attr{$name}{life360_userid};
my $url = "https://www.life360.com/v3/circles/".$circle."/members/".$userid."/history?time=".int($lastupdate);
my $url = "https://api-cloudfront.life360.com/v3/circles/".$circle."/members/history";
HttpUtils_NonblockingGet({
url => $url,
@ -493,6 +493,7 @@ sub livetracking_ParseLife360($$) {
foreach my $dataset (reverse(@{$json->{locations}}))
{
next if($dataset->{userId} ne $attr{$name}{life360_userid});
next if(!defined($dataset->{latitude}));
if(defined($dataset->{battery}) && defined($dataset->{endTimestamp}))
@ -1081,43 +1082,61 @@ sub livetracking_BootstrapLife360($)
return undef;
}
if(!defined($hash->{helper}{life360_script}) or $hash->{helper}{life360_script} eq "")
{
my $url = "https://www.life360.com/circles/#/";
HttpUtils_NonblockingGet({
url => $url,
noshutdown => 1,
hash => $hash,
type => 'scriptdata',
callback => \&livetracking_bootstrap,
});
return undef;
}
if(!defined($hash->{helper}{life360_secret}) or $hash->{helper}{life360_secret} eq "")
{
my $url = "https://www.life360.com/circles/scripts/".$hash->{helper}{life360_script}.".scripts.js";
HttpUtils_NonblockingGet({
url => $url,
noshutdown => 1,
hash => $hash,
type => 'secretdata',
callback => \&livetracking_bootstrap,
});
return undef;
}
# if(!defined($hash->{helper}{life360_script}) or $hash->{helper}{life360_script} eq "")
# {
# my $url = "https://api-cloudfront.life360.com/circles/#/";
#
# HttpUtils_NonblockingGet({
# url => $url,
# noshutdown => 1,
# hash => $hash,
# type => 'scriptdata',
# callback => \&livetracking_bootstrap,
# });
# return undef;
# }
#
# if(!defined($hash->{helper}{life360_secret}) or $hash->{helper}{life360_secret} eq "")
# {
# my $url = "https://www.life360.com/circles/scripts/".$hash->{helper}{life360_script}.".scripts.js";
#
# HttpUtils_NonblockingGet({
# url => $url,
# noshutdown => 1,
# hash => $hash,
# type => 'secretdata',
# callback => \&livetracking_bootstrap,
# });
# return undef;
# }
#
# if(!defined($hash->{helper}{life360_token}) or !defined($attr{$name}{life360_userid}) or $hash->{helper}{life360_token} eq "" or $attr{$name}{life360_userid} eq "")
# {
# my $url = "https://www.life360.com/v3/oauth2/token.json";
#
# HttpUtils_NonblockingGet({
# url => $url,
# method => "POST",
# header => "Content-Type: application/x-www-form-urlencoded\r\nAuthorization: Basic ".$hash->{helper}{life360_secret},
# data => "countryCode=1&password=".uri_escape($hash->{helper}{life360_pass})."&username=".uri_escape($hash->{helper}{life360_user})."&persist=true&grant_type=password",
# noshutdown => 1,
# hash => $hash,
# type => 'tokendata',
# callback => \&livetracking_bootstrap,
# });
#
# return undef;
# }
if(!defined($hash->{helper}{life360_token}) or !defined($attr{$name}{life360_userid}) or $hash->{helper}{life360_token} eq "" or $attr{$name}{life360_userid} eq "")
{
my $url = "https://www.life360.com/v3/oauth2/token.json";
my $url = "https://api-cloudfront.life360.com/v3/oauth2/token.json";
HttpUtils_NonblockingGet({
url => $url,
method => "POST",
header => "Content-Type: application/x-www-form-urlencoded\r\nAuthorization: Basic ".$hash->{helper}{life360_secret},
data => "countryCode=1&password=".uri_escape($hash->{helper}{life360_pass})."&username=".uri_escape($hash->{helper}{life360_user})."&persist=true&grant_type=password",
header => "Content-Type: application/json\r\nAuthorization: Basic YnJ1czR0ZXZhcHV0UmVadWNydUJSVXdVYnJFTUVDN1VYZTJlUEhhYjpSdUt1cHJBQ3JhbWVzV1UydVRyZVF1bXVtYTdhemFtQQ==",
data => '{"username":"'.$hash->{helper}{life360_user}.'","password":"'.$hash->{helper}{life360_pass}.'","grant_type":"password","countryCode":1}',
noshutdown => 1,
hash => $hash,
type => 'tokendata',
@ -1129,7 +1148,7 @@ sub livetracking_BootstrapLife360($)
if(!defined($attr{$name}{life360_circle}) or $attr{$name}{life360_circle} eq "")
{
my $url = "https://www.life360.com/v3/circles";
my $url = "https://api-cloudfront.life360.com/v3/circles";
HttpUtils_NonblockingGet({
url => $url,
@ -1161,27 +1180,28 @@ sub livetracking_bootstrap($$$)
Log3 $name, 5, "$name: $data";
if( $param->{type} eq 'scriptdata' )
{
if ($data =~ /\bscripts\/\b(.*?)\b.scripts.js\b/)
{
$hash->{helper}{life360_script} = $1;
Log3 $name, 4, "$name: life360 script ".$hash->{helper}{life360_script};
InternalTimer( gettimeofday() + 1, "livetracking_BootstrapLife360", $hash, 0);
}
return undef;
}
elsif( $param->{type} eq 'secretdata' )
{
if ($data =~ /CLIENT_SECRET = "(.*?)";/)
{
$hash->{helper}{life360_secret} = $1;
Log3 $name, 4, "$name: life360 secret ".$hash->{helper}{life360_secret};
InternalTimer( gettimeofday() + 1, "livetracking_BootstrapLife360", $hash, 0);
}
return undef;
}
elsif( $param->{type} eq 'tokendata' )
# if( $param->{type} eq 'scriptdata' )
# {
# if ($data =~ /\bscripts\/\b(.*?)\b.scripts.js\b/)
# {
# $hash->{helper}{life360_script} = $1;
# Log3 $name, 4, "$name: life360 script ".$hash->{helper}{life360_script};
# InternalTimer( gettimeofday() + 1, "livetracking_BootstrapLife360", $hash, 0);
# }
# return undef;
# }
# elsif( $param->{type} eq 'secretdata' )
# {
# if ($data =~ /CLIENT_SECRET = "(.*?)";/)
# {
# $hash->{helper}{life360_secret} = $1;
# Log3 $name, 4, "$name: life360 secret ".$hash->{helper}{life360_secret};
# InternalTimer( gettimeofday() + 1, "livetracking_BootstrapLife360", $hash, 0);
# }
# return undef;
# }
#els
if( $param->{type} eq 'tokendata' )
{
my $json = eval { JSON->new->utf8(0)->decode($data) };
if($@)
@ -1211,7 +1231,7 @@ sub livetracking_bootstrap($$$)
foreach my $dataset (@{$json->{circles}})
{
Log3 $name, 5, "$name: Life360 Circle: ".$dataset->{name}.", ID: ".$dataset->{id};
my $url = "https://www.life360.com/v3/circles/".$dataset->{id};
my $url = "https://api-cloudfront.life360.com/v3/circles/".$dataset->{id};
HttpUtils_NonblockingGet({
url => $url,