Skip to content

Commit 6f3dd18

Browse files
Merge pull request #22 from StartAutomating/LightScriptingHueFixes
Light scripting hue fixes
2 parents a8a439d + b30eaa1 commit 6f3dd18

22 files changed

+378
-49
lines changed

.github/workflows/RunEZOut.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/TestAndPublish.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ jobs:
448448
449449
if (-not $imported) { return }
450450
451-
$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue } catch {}
451+
$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue} catch {}
452452
453-
if ($foundModule -and $foundModule.Version -ge $imported.Version) {
453+
if ($foundModule -and (([Version]$foundModule.Version) -ge ([Version]$imported.Version))) {
454454
"::warning::Gallery Version of $moduleName is more recent ($($foundModule.Version) >= $($imported.Version))" | Out-Host
455455
} else {
456456
@@ -485,4 +485,18 @@ jobs:
485485
}
486486
}
487487
} @Parameters
488+
BuildModule:
489+
runs-on: ubuntu-latest
490+
if: ${{ success() }}
491+
steps:
492+
- name: Check out repository
493+
uses: actions/checkout@v2
494+
- name: BuildPipeScript
495+
uses: StartAutomating/PipeScript@main
496+
- name: UseEZOut
497+
uses: StartAutomating/EZOut@master
498+
- name: UsePiecemeal
499+
uses: StartAutomating/Piecemeal@main
500+
- name: UseHelpOut
501+
uses: StartAutomating/HelpOut@master
488502

.github/workflows/UpdateDocs.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

Add-HueLight.ps1

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
function Add-HueLight {
2+
3+
[CmdletBinding(SupportsShouldProcess)]
4+
5+
6+
7+
param(
8+
# One or more Device Identifiers (serial numbers ).
9+
# Use this parameter when adding lights that have already been assigned to another bridge.
10+
[Alias('SerialNumber')]
11+
[string[]]
12+
$DeviceID
13+
)
14+
begin {
15+
$hueBridge = Get-HueBridge
16+
$invokeParams = @{}
17+
$invokeParams.IPAddress = $hueBridge.IPAddress
18+
$invokeParams.HueUserName = $hueBridge.HueUserName
19+
20+
function ConvertRestInput {
21+
param([Collections.IDictionary]$RestInput = @{}, [switch]$ToQueryString)
22+
foreach ($ri in @($RestInput.GetEnumerator())) {
23+
24+
$restParameterValue = $ri.Value
25+
$restParameterValue =
26+
if ($restParameterValue -is [DateTime]) {
27+
$restParameterValue.Tostring('o')
28+
}
29+
elseif ($restParameterValue -is [switch]) {
30+
$restParameterValue -as [bool]
31+
}
32+
else {
33+
if ($ToQueryString -and
34+
$restParameterValue -is [Array] -and
35+
$JoinQueryValue) {
36+
$restParameterValue -join $JoinQueryValue
37+
} else {
38+
$restParameterValue
39+
}
40+
}
41+
42+
$RestInput[$ri.Key] = $restParameterValue
43+
}
44+
$RestInput
45+
46+
}
47+
48+
}
49+
process {
50+
$InvokeCommand = 'Send-HueBridge'
51+
$invokerCommandinfo =
52+
$ExecutionContext.SessionState.InvokeCommand.GetCommand('Send-HueBridge', 'All')
53+
$method = 'POST'
54+
$contentType = 'application/json'
55+
$bodyParameterNames = @('DeviceID')
56+
$queryParameterNames = @('')
57+
$joinQueryValue = ''
58+
$uriParameterNames = @('')
59+
$endpoints = @("lights")
60+
$ForEachOutput = {
61+
62+
}
63+
if ($ForEachOutput -match '^\s{0,}$') {
64+
$ForEachOutput = $null
65+
}
66+
if (-not $invokerCommandinfo) {
67+
Write-Error "Unable to find invoker '$InvokeCommand'"
68+
return
69+
}
70+
if (-not $psParameterSet) { $psParameterSet = $psCmdlet.ParameterSetName}
71+
if ($psParameterSet -eq '__AllParameterSets') { $psParameterSet = $endpoints[0]}
72+
$uri = $endpoints[0]
73+
74+
$invokeSplat = @{}
75+
$invokeSplat.Uri = $uri
76+
if ($method) {
77+
$invokeSplat.Method = $method
78+
}
79+
if ($ContentType -and $invokerCommandInfo.Parameters.ContentType) {
80+
$invokeSplat.ContentType = $ContentType
81+
}
82+
if ($InvokeParams -and $InvokeParams -is [Collections.IDictionary]) {
83+
$invokeSplat += $InvokeParams
84+
}
85+
$completeBody = [Ordered]@{}
86+
foreach ($bodyParameterName in $bodyParameterNames) {
87+
if ($bodyParameterName) {
88+
if ($PSBoundParameters.ContainsKey($bodyParameterName)) {
89+
$completeBody[$bodyParameterName] = $PSBoundParameters[$bodyParameterName]
90+
} else {
91+
$bodyDefault = $ExecutionContext.SessionState.PSVariable.Get($bodyParameterName).Value
92+
if ($null -ne $bodyDefault) {
93+
$completeBody[$bodyParameterName] = $bodyDefault
94+
}
95+
}
96+
}
97+
}
98+
$completeBody = ConvertRestInput $completeBody
99+
$bodyContent =
100+
if ($ContentType -match 'x-www-form-urlencoded') {
101+
@(foreach ($bodyPart in $completeBody.GetEnumerator()) {
102+
"$($bodyPart.Key.ToString().ToLower())=$([Web.HttpUtility]::UrlEncode($bodyPart.Value))"
103+
}) -join '&'
104+
} elseif ($ContentType -match 'json' -or -not $ContentType) {
105+
ConvertTo-Json $completeBody
106+
}
107+
if ($bodyContent -and $method -ne 'get') {
108+
$invokeSplat.Body = $bodyContent
109+
}
110+
Write-Verbose "$($invokeSplat.Uri)"
111+
if ($ForEachOutput) {
112+
if ($ForEachOutput.Ast.ProcessBlock) {
113+
& $invokerCommandinfo @invokeSplat | & $ForEachOutput
114+
} else {
115+
& $invokerCommandinfo @invokeSplat | ForEach-Object -Process $ForEachOutput
116+
}
117+
} else {
118+
& $invokerCommandinfo @invokeSplat
119+
}
120+
}
121+
}
122+

Add-HueLight.ps1.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function Add-HueLight
2+
{
3+
[Rest("lights",
4+
Invoker="Send-HueBridge",
5+
Method='POST',
6+
ContentType='application/json',
7+
BodyParameter={
8+
{
9+
param(
10+
# One or more Device Identifiers (serial numbers ).
11+
# Use this parameter when adding lights that have already been assigned to another bridge.
12+
[Alias('SerialNumber')]
13+
[string[]]
14+
$DeviceID
15+
)
16+
}
17+
})]
18+
[CmdletBinding(SupportsShouldProcess)]
19+
param()
20+
21+
begin {
22+
$hueBridge = Get-HueBridge
23+
$invokeParams = @{}
24+
$invokeParams.IPAddress = $hueBridge.IPAddress
25+
$invokeParams.HueUserName = $hueBridge.HueUserName
26+
}
27+
}

Add-HueRoom.ps1

-3.8 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.2.4
2+
* Adding Add-HueLight (#18)
3+
* Adding Get-HueLight -New (#21)
4+
* Fixing Rename-HueLight (#19)
5+
* Building LightScript with PipeScript (#20)
6+
---
7+
18
## 0.2.3
29
* Set-NanoLeaf: Fixing #17
310
* Send-HueBridge: Adding logging

Get-HueLight.ps1

-1.37 KB
Binary file not shown.

LightScript.ps1.psm1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[include("*-*.ps1")]$PSScriptRoot
2+
3+
if ($home) {
4+
$Script:KnownResources =
5+
@(
6+
Get-HueLight
7+
Get-HueRoom
8+
Get-NanoLeaf
9+
)
10+
11+
foreach ($resource in $Script:KnownResources) {
12+
if ($resource.pstypenames -contains 'Hue.Light') {
13+
Set-Alias -Name ($resource.Name -replace '\s') -Value Set-HueLight
14+
}
15+
if ($resource.pstypenames -contains 'Hue.Group' -or
16+
$resource.pstypenames -contains 'Hue.LightGroup') {
17+
Set-Alias -Name ($resource.Name -replace '\s') -Value Set-HueLight
18+
}
19+
}
20+
}

LightScript.psd1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.2.3'
2+
ModuleVersion = '0.2.4'
33
RootModule = 'LightScript.psm1'
44
Description = 'Smarter Lighting with PowerShell'
55
FormatsToProcess = 'LightScript.format.ps1xml'
@@ -14,6 +14,13 @@
1414
LicenseURI = 'https://github.com/StartAutomating/LightScript/blob/main/LICENSE'
1515
IconURI = 'https://github.com/StartAutomating/LightScript/blob/main/Assets/LightScript.png'
1616
ReleaseNotes = @'
17+
## 0.2.4
18+
* Adding Add-HueLight (#18)
19+
* Adding Get-HueLight -New (#21)
20+
* Fixing Rename-HueLight (#19)
21+
* Building LightScript with PipeScript (#20)
22+
---
23+
1724
## 0.2.3
1825
* Set-NanoLeaf: Fixing #17
1926
* Send-HueBridge: Adding logging

0 commit comments

Comments
 (0)