feat: integrate N7Cockpit remote mode control
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$ConfigPath = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$projectRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
if (-not $ConfigPath) { $ConfigPath = Join-Path $projectRoot 'config\migration.psd1' }
|
||||
if (-not [System.IO.Path]::IsPathRooted($ConfigPath)) {
|
||||
$ConfigPath = Join-Path $projectRoot $ConfigPath
|
||||
}
|
||||
$config = Import-PowerShellDataFile -LiteralPath $ConfigPath
|
||||
$tokenPath = [string]$config.TokenFile
|
||||
if (-not [System.IO.Path]::IsPathRooted($tokenPath)) {
|
||||
$tokenPath = Join-Path $projectRoot $tokenPath
|
||||
}
|
||||
$token = (Get-Content -LiteralPath $tokenPath -Raw).Trim()
|
||||
$baseUrl = ([string]$config.ServerAUrl).TrimEnd('/')
|
||||
$vehicleId = ([string]$config.VehicleId).Trim()
|
||||
$headers = @{ Authorization = "Bearer $token" }
|
||||
$catalog = Invoke-RestMethod -Uri "$baseUrl/api/v1/vehicles/$vehicleId/modes" `
|
||||
-Headers $headers -TimeoutSec 10
|
||||
$events = Invoke-RestMethod -Uri "$baseUrl/api/v1/vehicles/$vehicleId/events?after=0" `
|
||||
-Headers $headers -TimeoutSec 10
|
||||
[pscustomobject]@{
|
||||
Passed = $true
|
||||
ServerA = $baseUrl
|
||||
VehicleId = $catalog.vehicle_id
|
||||
PresetModes = @($catalog.modes | Where-Object { $_.origin -eq 'preset' }).Count
|
||||
EventSequence = $events.next_sequence
|
||||
}
|
||||
Reference in New Issue
Block a user