Read packages on the provided WebSocket connection.
Read-TibberWebSocket [-Connection] <Object> [-Callback] <ScriptBlock> [[-CallbackComplete] <ScriptBlock>]
[[-CallbackError] <ScriptBlock>] [[-CallbackArgumentList] <Object[]>] [[-DurationInSeconds] <Int32>]
[[-ReadUntil] <DateTime>] [[-PackageCount] <Int32>] [[-TimeoutInSeconds] <Int32>] [<CommonParameters>]
Calling this function will read packages on the provided WebSocket connection.
Read-TibberWebSocket -Connection $connection -Callback { param($Json)
Write-Host "New Json document received: $($Json.payload.data | Out-String)"
}
function Write-PackageToHost {
param (
[Object] $Json
)
Write-Host "New Json document received: $($Json.payload.data | Out-String)"
}
Read-TibberWebSocket -Connection $connection -Callback ${function:Write-PackageToHost}
$result = Read-TibberWebSocket -Connection $connection -Callback ${function:Write-PackageToHost} -DurationInSeconds 30
Write-Host "Read $($result.NumberOfPackages) package(s) in $($result.ElapsedTimeInSeconds) seconds"
Read-TibberWebSocket -Connection $connection -Callback ${function:Write-PackageToHost} -PackageCount 3
Write-Host "Read $($result.NumberOfPackages) package(s) in $($result.ElapsedTimeInSeconds) seconds"
function Write-PackageToHost {
param (
[Object] $Json,
[string] $With,
[string] $Additional,
[int] $Arguments
)
Write-Host "New Json document received: $($Json.payload.data | Out-String)"
Write-Host "$With $Additional $Arguments"
}
Read-TibberWebSocket -Connection $connection -Callback ${function:Write-PackageToHost} -CallbackArgumentList @("Hello", "world!", 2022)
Specifies the connection to use for the communication.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies the default script block/function called for each response.
Type: ScriptBlock
Parameter Sets: (All)
Aliases: OnNext, CallbackNext
Required: True
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies the script block/function called after recieving a 'complete' message.
Type: ScriptBlock
Parameter Sets: (All)
Aliases: OnComplete
Required: False
Position: 3
Default value: $Callback
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies the script block/function called after recieving a 'error' message.
Type: ScriptBlock
Parameter Sets: (All)
Aliases: OnError
Required: False
Position: 4
Default value: {
throw "WebSocket error message received: $($response | ConvertTo-Json -Depth 10)"
}
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies the optional arguments passed on to the callback script block, positioned after the response.
Type: Object[]
Parameter Sets: (All)
Aliases: CallbackArguments, Arguments, Args
Required: False
Position: 5
Default value: @()
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies for how long in seconds we should read packages, or -1 to read indefinitely.
Type: Int32
Parameter Sets: (All)
Aliases: Duration
Required: False
Position: 6
Default value: -1
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies a date/time to read data until (a deadline).
Type: DateTime
Parameter Sets: (All)
Aliases: Until, Deadline
Required: False
Position: 7
Default value: ([DateTime]::Now).AddSeconds(-1)
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies the number of packages to read, or -1 to read indefinitely.
Type: Int32
Parameter Sets: (All)
Aliases: Count
Required: False
Position: 8
Default value: -1
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies the time to wait for WebSocket operations, or -1 to wait indefinitely.
Type: Int32
Parameter Sets: (All)
Aliases: Timeout
Required: False
Position: 9
Default value: 30
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.