Skip to content

Commit

Permalink
feat: Set-Awtrix argument Completer ( Fixes #111 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Jan 28, 2024
1 parent e3aaa61 commit 84b3c60
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Functions/Awtrix/Set-Awtrix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Set-Awtrix
[Parameter(ValueFromPipelineByPropertyName)]
[ValidatePattern('#(?>[a-f0-9]{6}|[a-f0-9]{3})')]
[string]
$RGBColor,
$RGBColor,

# If set, will change the Awtrix into a given color temperature.
[Parameter(ValueFromPipelineByPropertyName)]
Expand Down Expand Up @@ -118,6 +118,21 @@ function Set-Awtrix

# The name of the effect.
[Parameter(ValueFromPipelineByPropertyName)]
[ArgumentCompleter({
param ( $commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters )
$effectNames = @(Get-Awtrix -ListEffectName |
Select-Object -Unique)
if ($wordToComplete) {
$toComplete = $wordToComplete -replace "^'" -replace "'$"
return @($effectNames -like "$toComplete*" -replace '^', "'" -replace '$',"'")
} else {
return @($effectNames -replace '^', "'" -replace '$',"'")
}
})]
[Alias('animName')]
[string]
$EffectName,
Expand All @@ -128,6 +143,7 @@ function Set-Awtrix
[PSObject]
$EffectOption,

# Any options related to the notification.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('NotificationOptions','NotificationParameter','NotificationParameters')]
[PSObject]
Expand Down Expand Up @@ -248,10 +264,10 @@ function Set-Awtrix
$invokeSplat.Uri = "http://$ip/api/switch"
$invokeSplat.Body = @{name=$ApplicationName} | ConvertTo-Json
}
$invokeSplat
$invokeSplat
}

if ($NotificationText -or $NotificationOption) {
if ($NotificationText -or $NotificationOption -or $EffectName) {
if ($ApplicationName) {
$invokeSplat.Uri = "http://$ip/api/custom?name=$($ApplicationName)"
} else {
Expand All @@ -274,6 +290,8 @@ function Set-Awtrix

if ($EffectOption) {
$invokeSplat.Body.effectSettings = $EffectOption
} elseif ($EffectName) {
# $invokeSplat.Body.effectSettings = @{speed=10;palette='Rainbow'}
}

if ($HoldNotification) {
Expand All @@ -286,11 +304,13 @@ function Set-Awtrix
if ($NotificationOption -is [Collections.IDictionary]) {
$NotificationOption = [PSCustomObject]$NotificationOption
}

foreach ($notificationProperty in $NotificationOption.psobject.properties) {
$invokeSplat.Body.$($notificationProperty.Name) = $notificationProperty.Value
}
}


$invokeSplat
}
)

Expand Down

0 comments on commit 84b3c60

Please sign in to comment.