Skip to content

Commit

Permalink
Adding Set-LaMetricTime, starting with -Timer (Fixes #79)
Browse files Browse the repository at this point in the history
  • Loading branch information
StartAutomating authored and StartAutomating committed Nov 11, 2022
1 parent 3a29cb4 commit 0711474
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Functions/LaMetric/Set-LaMetricTime.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function Set-LaMetricTime {
<#
.SYNOPSIS
Sets a LaMetricTime device.
.DESCRIPTION
Configures or sends notifications to an LaMetricTime device.
.EXAMPLE
.LINK
Get-LaMetricTime
.LINK
Connect-LaMetrictime
#>
param(
# One or more IP Addresses of LaMetricTime devices.
# If no IP Addresses are provided, the change will apply to all devices.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('LaMetricTimeIPAddress')]
[IPAddress[]]
$IPAddress,
# Sets a Timer on the LaMetric device, using the built-in Countdown app.
[Parameter(ValueFromPipelineByPropertyName)]
[timespan]
$Timer
)
process {
if (-not $IPAddress) {
if ($home) {
$null = Get-LaMetricTime
$IPAddress = $script:LaMetricTimeCache.Keys
}
if (-not $IPAddress) {
Write-Warning "No -IPAddress provided and no cached devices found"
return
}
}
foreach ($ip in $IPAddress) {
$laMetricB64Key = $script:LaMetricTimeCache["$ip"].ApiKey
#region Timer
$ipAndPort = "${ip}:8080"
$endpoint = "api/v2/device/apps"
$appAndWiget = "com.lametric.countdown/widgets/f03ea1ae1ae5f85b390b460f55ba8061/actions"
Invoke-RestMethod ('http://',$ipAndPort,'/',$endpoint,'/',$appAndWiget,'' -join '') -Headers @{
Authorization = "Basic $laMetricB64Key"
} -Body ([Ordered]@{
id = "countdown.configure"
params = [Ordered]@{
duration = [int]$timer.TotalSeconds
start_now = $true
}
activate = $true
} | ConvertTo-Json) -Method 'post'
#endregion Timer
}
}
}

0 comments on commit 0711474

Please sign in to comment.