-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from StartAutomating/LightScriptingHueFixes
Light scripting hue fixes
- Loading branch information
Showing
22 changed files
with
378 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
function Add-HueLight { | ||
|
||
[CmdletBinding(SupportsShouldProcess)] | ||
|
||
|
||
|
||
param( | ||
# One or more Device Identifiers (serial numbers ). | ||
# Use this parameter when adding lights that have already been assigned to another bridge. | ||
[Alias('SerialNumber')] | ||
[string[]] | ||
$DeviceID | ||
) | ||
begin { | ||
$hueBridge = Get-HueBridge | ||
$invokeParams = @{} | ||
$invokeParams.IPAddress = $hueBridge.IPAddress | ||
$invokeParams.HueUserName = $hueBridge.HueUserName | ||
|
||
function ConvertRestInput { | ||
param([Collections.IDictionary]$RestInput = @{}, [switch]$ToQueryString) | ||
foreach ($ri in @($RestInput.GetEnumerator())) { | ||
|
||
$restParameterValue = $ri.Value | ||
$restParameterValue = | ||
if ($restParameterValue -is [DateTime]) { | ||
$restParameterValue.Tostring('o') | ||
} | ||
elseif ($restParameterValue -is [switch]) { | ||
$restParameterValue -as [bool] | ||
} | ||
else { | ||
if ($ToQueryString -and | ||
$restParameterValue -is [Array] -and | ||
$JoinQueryValue) { | ||
$restParameterValue -join $JoinQueryValue | ||
} else { | ||
$restParameterValue | ||
} | ||
} | ||
|
||
$RestInput[$ri.Key] = $restParameterValue | ||
} | ||
$RestInput | ||
|
||
} | ||
|
||
} | ||
process { | ||
$InvokeCommand = 'Send-HueBridge' | ||
$invokerCommandinfo = | ||
$ExecutionContext.SessionState.InvokeCommand.GetCommand('Send-HueBridge', 'All') | ||
$method = 'POST' | ||
$contentType = 'application/json' | ||
$bodyParameterNames = @('DeviceID') | ||
$queryParameterNames = @('') | ||
$joinQueryValue = '' | ||
$uriParameterNames = @('') | ||
$endpoints = @("lights") | ||
$ForEachOutput = { | ||
|
||
} | ||
if ($ForEachOutput -match '^\s{0,}$') { | ||
$ForEachOutput = $null | ||
} | ||
if (-not $invokerCommandinfo) { | ||
Write-Error "Unable to find invoker '$InvokeCommand'" | ||
return | ||
} | ||
if (-not $psParameterSet) { $psParameterSet = $psCmdlet.ParameterSetName} | ||
if ($psParameterSet -eq '__AllParameterSets') { $psParameterSet = $endpoints[0]} | ||
$uri = $endpoints[0] | ||
|
||
$invokeSplat = @{} | ||
$invokeSplat.Uri = $uri | ||
if ($method) { | ||
$invokeSplat.Method = $method | ||
} | ||
if ($ContentType -and $invokerCommandInfo.Parameters.ContentType) { | ||
$invokeSplat.ContentType = $ContentType | ||
} | ||
if ($InvokeParams -and $InvokeParams -is [Collections.IDictionary]) { | ||
$invokeSplat += $InvokeParams | ||
} | ||
$completeBody = [Ordered]@{} | ||
foreach ($bodyParameterName in $bodyParameterNames) { | ||
if ($bodyParameterName) { | ||
if ($PSBoundParameters.ContainsKey($bodyParameterName)) { | ||
$completeBody[$bodyParameterName] = $PSBoundParameters[$bodyParameterName] | ||
} else { | ||
$bodyDefault = $ExecutionContext.SessionState.PSVariable.Get($bodyParameterName).Value | ||
if ($null -ne $bodyDefault) { | ||
$completeBody[$bodyParameterName] = $bodyDefault | ||
} | ||
} | ||
} | ||
} | ||
$completeBody = ConvertRestInput $completeBody | ||
$bodyContent = | ||
if ($ContentType -match 'x-www-form-urlencoded') { | ||
@(foreach ($bodyPart in $completeBody.GetEnumerator()) { | ||
"$($bodyPart.Key.ToString().ToLower())=$([Web.HttpUtility]::UrlEncode($bodyPart.Value))" | ||
}) -join '&' | ||
} elseif ($ContentType -match 'json' -or -not $ContentType) { | ||
ConvertTo-Json $completeBody | ||
} | ||
if ($bodyContent -and $method -ne 'get') { | ||
$invokeSplat.Body = $bodyContent | ||
} | ||
Write-Verbose "$($invokeSplat.Uri)" | ||
if ($ForEachOutput) { | ||
if ($ForEachOutput.Ast.ProcessBlock) { | ||
& $invokerCommandinfo @invokeSplat | & $ForEachOutput | ||
} else { | ||
& $invokerCommandinfo @invokeSplat | ForEach-Object -Process $ForEachOutput | ||
} | ||
} else { | ||
& $invokerCommandinfo @invokeSplat | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function Add-HueLight | ||
{ | ||
[Rest("lights", | ||
Invoker="Send-HueBridge", | ||
Method='POST', | ||
ContentType='application/json', | ||
BodyParameter={ | ||
{ | ||
param( | ||
# One or more Device Identifiers (serial numbers ). | ||
# Use this parameter when adding lights that have already been assigned to another bridge. | ||
[Alias('SerialNumber')] | ||
[string[]] | ||
$DeviceID | ||
) | ||
} | ||
})] | ||
[CmdletBinding(SupportsShouldProcess)] | ||
param() | ||
|
||
begin { | ||
$hueBridge = Get-HueBridge | ||
$invokeParams = @{} | ||
$invokeParams.IPAddress = $hueBridge.IPAddress | ||
$invokeParams.HueUserName = $hueBridge.HueUserName | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[include("*-*.ps1")]$PSScriptRoot | ||
|
||
if ($home) { | ||
$Script:KnownResources = | ||
@( | ||
Get-HueLight | ||
Get-HueRoom | ||
Get-NanoLeaf | ||
) | ||
|
||
foreach ($resource in $Script:KnownResources) { | ||
if ($resource.pstypenames -contains 'Hue.Light') { | ||
Set-Alias -Name ($resource.Name -replace '\s') -Value Set-HueLight | ||
} | ||
if ($resource.pstypenames -contains 'Hue.Group' -or | ||
$resource.pstypenames -contains 'Hue.LightGroup') { | ||
Set-Alias -Name ($resource.Name -replace '\s') -Value Set-HueLight | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
Add-HueLight | ||
------------ | ||
### Synopsis | ||
|
||
Add-HueLight [[-DeviceID] <string[]>] [-WhatIf] [-Confirm] [<CommonParameters>] | ||
|
||
|
||
--- | ||
### Description | ||
--- | ||
### Parameters | ||
#### **Confirm** | ||
-Confirm is an automatic variable that is created when a command has ```[CmdletBinding(SupportsShouldProcess)]```. | ||
-Confirm is used to -Confirm each operation. | ||
|
||
If you pass ```-Confirm:$false``` you will not be prompted. | ||
|
||
|
||
If the command sets a ```[ConfirmImpact("Medium")]``` which is lower than ```$confirmImpactPreference```, you will not be prompted unless -Confirm is passed. | ||
|
||
#### **DeviceID** | ||
|
||
|Type |Requried|Postion|PipelineInput| | ||
|----------------|--------|-------|-------------| | ||
|```[string[]]```|false |0 |false | | ||
--- | ||
#### **WhatIf** | ||
-WhatIf is an automatic variable that is created when a command has ```[CmdletBinding(SupportsShouldProcess)]```. | ||
-WhatIf is used to see what would happen, or return operations without executing them | ||
--- | ||
### Inputs | ||
None | ||
|
||
|
||
--- | ||
### Outputs | ||
System.Object | ||
|
||
|
||
--- | ||
### Syntax | ||
```PowerShell | ||
[32;1msyntaxItem[0m | ||
``` | ||
```PowerShell | ||
[32;1m----------[0m | ||
``` | ||
```PowerShell | ||
{@{name=Add-HueLight; CommonParameters=True; parameter=System.Object[]}} | ||
``` | ||
--- | ||
|
||
|
Oops, something went wrong.