Skip to content

Commit

Permalink
feat: Set-Awtrix -Reboot ( Fixes #115 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Jan 29, 2024
1 parent c924bf1 commit 40ca884
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions Functions/Awtrix/Set-Awtrix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ function Set-Awtrix
.EXAMPLE
Set-Awtrix -Brightness 1
.EXAMPLE
Set-Awtrix -RGBColor "#4488ff"
Set-Awtrix -RGBColor "#4488ff" # Sets the Awtrix to a blue moodlight
.EXAMPLE
Set-Awtrix -NotificationText "Hello World"
.EXAMPLE
Set-Awtrix -Hue 180 -Saturation .5 -Brightness .25
.LINK
Get-Awtrix
#>
Expand Down Expand Up @@ -49,6 +53,12 @@ function Set-Awtrix
[switch]
$Off,

# If set, will reboot an Awtrix device.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Reset')]
[switch]
$Reboot,

# If provided, will change the Awtrix into a single RGB color.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidatePattern('#(?>[a-f0-9]{6}|[a-f0-9]{3})')]
Expand Down Expand Up @@ -216,7 +226,7 @@ function Set-Awtrix
$invokeSplat.Body = (@{
BRI = [byte]$realBrightness
} | ConvertTo-Json -Compress)
$invokeSplat
[Ordered]@{} + $invokeSplat

} elseif ($paramCopy.ContainsKey("Brightness") -and
$paramCopy.ContainsKey("Hue") -and
Expand All @@ -231,14 +241,14 @@ function Set-Awtrix
if ($On -and -not $Off) {
$invokeSplat.Uri = "http://$ip/api/power"
$invokeSplat.Body = (@{power = $true} | ConvertTo-Json -Compress)
$invokeSplat
[Ordered]@{} + $invokeSplat
}

if ($off) {
$invokeSplat.Uri = "http://$ip/api/power"
$invokeSplat.Body = (@{power = $false} | ConvertTo-Json -Compress)
Invoke-RestMethod @invokeSplat
$invokeSplat
[Ordered]@{} + $invokeSplat
}
#endregion On/Off Switch

Expand All @@ -254,7 +264,7 @@ function Set-Awtrix
if ($Brightness) {
$invokeSplat.Body.brightness = [byte][Math]::Ceiling($Brightness * 255)
}
$invokeSplat
[Ordered]@{} + $invokeSplat
}
#endregion Color Temperature

Expand All @@ -265,7 +275,7 @@ function Set-Awtrix
if ($paramCopy.ContainsKey("Brightness")) {
$invokeSplat.Body.brightness = [byte][Math]::Ceiling($Brightness * 255)
}
$invokeSplat
[Ordered]@{} + $invokeSplat
}
#endregion RGBColor

Expand All @@ -281,7 +291,7 @@ function Set-Awtrix
$invokeSplat.Uri = "http://$ip/api/switch"
$invokeSplat.Body = @{name=$ApplicationName} | ConvertTo-Json
}
$invokeSplat
[Ordered]@{} + $invokeSplat
}

if ($NotificationText -or $NotificationOption -or $EffectName) {
Expand Down Expand Up @@ -343,6 +353,13 @@ function Set-Awtrix

$invokeSplat
}

if ($Reboot) {
$invokeSplat.Uri = "http://$ip/api/reboot"
$invokeSplat.Body = ""
$invokeSplat.Method = "POST"
[Ordered]@{} + $invokeSplat
}
)

$restOutputs =
Expand Down

0 comments on commit 40ca884

Please sign in to comment.