Skip to content

Commit

Permalink
feat: Get-Awtrix -AppLoop ( Fixes #106 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Jan 15, 2024
1 parent 8aaf7bb commit 080522d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Functions/Awtrix/Get-Awtrix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ function Get-Awtrix
[IPAddress[]]
$IPAddress,

[Parameter(ParameterSetName='ListEffectName',ValueFromPipelineByPropertyName)]
# If set, will list the effects supported by the Awtrix device.
[Parameter(ParameterSetName='api/effects',ValueFromPipelineByPropertyName)]
[Alias('ListEffectNames')]
[switch]
$ListEffectName,

# If set, will output the application loop on the Awtrix device.
[Parameter(ParameterSetName='api/loop',ValueFromPipelineByPropertyName)]
[Alias('AppLoop')]
[switch]
$ApplicationLoop,

# If set, will clear any cached results.
[switch]
Expand Down Expand Up @@ -69,11 +76,12 @@ function Get-Awtrix
return $script:AwtrixCache.Values
}

foreach ($ipAddr in $script:AwtrixCache.Keys) {
switch ($PSCmdlet.ParameterSetName) {
ListEffectName {
Invoke-RestMethod "http://$ipAddr/api/effects"
}

foreach ($ipAddr in $script:AwtrixCache.Keys) {
foreach ($restOut in Invoke-RestMethod "http://$ipAddr/$($PSCmdlet.ParameterSetName)") {
$restOut.pstypenames.clear()
$restOut.pstypenames.add(($PSCmdlet.ParameterSetName -replace '/','.' -replace '$api', 'Awtrix'))
$restOut
}
}

Expand Down

0 comments on commit 080522d

Please sign in to comment.