Skip to content

Commit

Permalink
Version 1.0.2 Fix multi-master support
Browse files Browse the repository at this point in the history
Version 1.0.2 Fix multi-vehicle support.

Vehicles query does not return an array, instead the Response property
is an array.
  • Loading branch information
JonnMsft committed Feb 14, 2017
1 parent ca97245 commit 8175780
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Tesla.psd1
Expand Up @@ -12,7 +12,7 @@
# RootModule = ''

# Version number of this module.
ModuleVersion = '1.0'
ModuleVersion = '1.0.2'

# ID used to uniquely identify this module
GUID = '1d79bc55-90a2-4709-b8df-ddf559cc1e76'
Expand Down
20 changes: 14 additions & 6 deletions Tesla.psm1
Expand Up @@ -168,18 +168,25 @@ ANQA5AGQAYgA2AGQAYgA='
'Authorization' = "Bearer $access_token"
'Accept-Encoding' = 'gzip,deflate'
}

Status "Get vehicle list"
$vehicles = @(Invoke-RestMethod -Uri "$apiUri/vehicles" `
-Method Get `
-UserAgent $user_agent `
-Headers $headers)
$resp = Invoke-RestMethod -Uri "$apiUri/vehicles" `
-Method Get `
-UserAgent $user_agent `
-Headers $headers
Write-Debug -Message $resp
$vehicles = $resp.response
$vehicles | Write-Debug
Status "Received $($vehicles.Count) vehicles in response"
if ($VIN)
{
for ($i = 0; $i -lt $vehicles.Count; $i++)
{
$vehicle = $vehicles[$i].response
Status "Vehicle $i has VIN $($vehicle.VIN)"
$vehicle = $vehicles[$i]
if ($vehicle.VIN -eq $VIN)
{
Status "VIN match for vehicle $i"
$VehicleIndex = $i;
break
}
Expand All @@ -189,8 +196,9 @@ ANQA5AGQAYgA2AGQAYgA='
throw "$activity`: Vehicle with VIN $VIN not found"
}
}
$vehicle = $vehicles[$VehicleIndex].response
$vehicle = $vehicles[$VehicleIndex]
$vehicleId = $vehicle.id
Status "VehicleID is $vehicleId"

if ($vehicle.state -ne 'online') {
if ($vehicle.state -ne 'asleep')
Expand Down

0 comments on commit 8175780

Please sign in to comment.