Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light scripting hue fixes #22

Merged
merged 37 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c83039a
Building LightScript with PipeScript and Consolidating Workflows (#20)
Jul 24, 2022
e944eb1
Send-HueBridge: Adding Aliases and Renaming Parameters (re #20)
Jul 24, 2022
ba6d20d
Simplifying Module Source (re #20)
Jul 24, 2022
31e810b
Get-HueLight: Support for -New (#21)
Jul 24, 2022
1ad07ac
Rename-HueLight: Fixing encoding and #19.
Jul 24, 2022
8426f16
Add-HueRoom: Fixing encoding
Jul 24, 2022
659d3f0
Set-NanoLeaf: Adding .example
Jul 24, 2022
2932e35
Adding Add-HueLight Source (#18 #20)
Jul 24, 2022
30e1fd7
Adding Add-HueLight Source (#18 #20)
Jul 24, 2022
8332af4
Adding Add-HueLight Source (#18 #20)
Jul 24, 2022
b977190
Updating Add-HueLight.md
Jul 24, 2022
f89dccf
Updating Add-HueRoom.md
Jul 24, 2022
5fc8979
Updating Add-HueSensor.md
Jul 24, 2022
f32ec2b
Updating Get-HueLight.md
Jul 24, 2022
e5e492c
Updating Get-NanoLeaf.md
Jul 24, 2022
937f9a6
Updating Send-HueBridge.md
Jul 24, 2022
c33c620
Updating Set-HueLight.md
Jul 24, 2022
82cd448
Updating Set-NanoLeaf.md
Jul 24, 2022
85c4a5a
Updating Set-Pixoo.md
Jul 24, 2022
21c96b4
Updating Set-Twinkly.md
Jul 24, 2022
736060c
Updating README.md
Jul 24, 2022
ac377fb
Updating README.md
Jul 24, 2022
0e15b5d
Updating CHANGELOG.md
Jul 24, 2022
d59a685
Updating LightScript.png
Jul 24, 2022
8bee98b
Updating Module Version [0.2.4] and CHANGELOG
Jul 24, 2022
2510a42
Updating README.md
Jul 24, 2022
0448c6a
Updating README.md
Jul 24, 2022
dbc1129
Updating CHANGELOG.md
Jul 24, 2022
594bc95
Updating Module Version [0.2.4] and CHANGELOG
Jul 24, 2022
43aab94
Updating README.md
Jul 24, 2022
192a52c
Updating README.md
Jul 24, 2022
c800c47
Updating CHANGELOG.md
Jul 24, 2022
3a44437
Merge branch 'main' into LightScriptingHueFixes
StartAutomating Jul 24, 2022
7322e03
Updating README.md
Jul 24, 2022
05b186d
Updating README.md
Jul 24, 2022
8ed6a6e
Updating about topic (adding Add-HueLight example)
Jul 24, 2022
b30eaa1
Updating README.md
Jul 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/workflows/RunEZOut.yml

This file was deleted.

18 changes: 16 additions & 2 deletions .github/workflows/TestAndPublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ jobs:

if (-not $imported) { return }

$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue } catch {}
$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue} catch {}

if ($foundModule -and $foundModule.Version -ge $imported.Version) {
if ($foundModule -and (([Version]$foundModule.Version) -ge ([Version]$imported.Version))) {
"::warning::Gallery Version of $moduleName is more recent ($($foundModule.Version) >= $($imported.Version))" | Out-Host
} else {

Expand Down Expand Up @@ -485,4 +485,18 @@ jobs:
}
}
} @Parameters
BuildModule:
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: BuildPipeScript
uses: StartAutomating/PipeScript@main
- name: UseEZOut
uses: StartAutomating/EZOut@master
- name: UsePiecemeal
uses: StartAutomating/Piecemeal@main
- name: UseHelpOut
uses: StartAutomating/HelpOut@master

14 changes: 0 additions & 14 deletions .github/workflows/UpdateDocs.yml

This file was deleted.

122 changes: 122 additions & 0 deletions Add-HueLight.ps1
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
}
}
}

27 changes: 27 additions & 0 deletions Add-HueLight.ps1.ps1
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 modified Add-HueRoom.ps1
Binary file not shown.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.2.4
* Adding Add-HueLight (#18)
* Adding Get-HueLight -New (#21)
* Fixing Rename-HueLight (#19)
* Building LightScript with PipeScript (#20)
---

## 0.2.3
* Set-NanoLeaf: Fixing #17
* Send-HueBridge: Adding logging
Expand Down
Binary file modified Get-HueLight.ps1
Binary file not shown.
20 changes: 20 additions & 0 deletions LightScript.ps1.psm1
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
}
}
}
9 changes: 8 additions & 1 deletion LightScript.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.2.3'
ModuleVersion = '0.2.4'
RootModule = 'LightScript.psm1'
Description = 'Smarter Lighting with PowerShell'
FormatsToProcess = 'LightScript.format.ps1xml'
Expand All @@ -14,6 +14,13 @@
LicenseURI = 'https://github.com/StartAutomating/LightScript/blob/main/LICENSE'
IconURI = 'https://github.com/StartAutomating/LightScript/blob/main/Assets/LightScript.png'
ReleaseNotes = @'
## 0.2.4
* Adding Add-HueLight (#18)
* Adding Get-HueLight -New (#21)
* Fixing Rename-HueLight (#19)
* Building LightScript with PipeScript (#20)
---

## 0.2.3
* Set-NanoLeaf: Fixing #17
* Send-HueBridge: Adding logging
Expand Down
Binary file modified LightScript.psm1
Binary file not shown.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ Add-HueSchedule -In '00:10:00' -Command (Set-HueLight -Alert lselect -OutputInpu
~~~


You can also add new lights to a bridge:

~~~PowerShell
Add-HueLight
Get-HueLight -New
~~~

### Hue Devices and Smart Aliases

Set-HueLight supports smart aliasing.
Expand Down
Binary file modified Rename-HueLight.ps1
Binary file not shown.
16 changes: 9 additions & 7 deletions Send-HueBridge.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Send-HueBridge
Get-HueBridge
#>
[OutputType([PSObject])]
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Low')]
[CmdletBinding(SupportsShouldProcess,ConfirmImpact='Low')]
param(
# The IP address of the hue bridge.
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
Expand All @@ -26,14 +26,16 @@ function Send-HueBridge

# The command being sent to the bridge. This is a partial URI.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Uri','Url')]
[string]
$Command,

# The data being sent to the Hue Bridge.
# If this data is not a string, it will be converted to JSON.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Data')]
[PSObject]
$Data,
$Body,

# The HTTP method. By default, Get.
[Parameter(ValueFromPipelineByPropertyName)]
Expand Down Expand Up @@ -67,17 +69,17 @@ function Send-HueBridge
method = $Method
}

if ($Data) {
if ($data -is [string]){
$splat.body = $data
if ($Body) {
if ($Body -is [string]){
$splat.body = $Body
} else {
$splat.body = ConvertTo-Json -Compress -Depth 100 -InputObject $Data
$splat.body = ConvertTo-Json -Compress -Depth 100 -InputObject $Body
}
}
#endregion Construct the Message Body

if ($OutputInput -or $WhatIfPreference) { # If -OutputInput or -WhatIf was passed
if ($Data) { $splat.body = $Data }
if ($Body) { $splat.body = $Body }
$splat.address = ([uri]$splat.uri).LocalPath # Make an address property with a relative URI
$splat.Remove('uri') # and remove URI
$splat
Expand Down
2 changes: 2 additions & 0 deletions Set-NanoLeaf.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
delayTime = 1
transTime = 1
}
.Example
Set-NanoLeaf -Palette "#123456", "#654321", "#abcdef", "#fedcba" -PluginType Rhythm -PluginName 'Dancing Duo'
.Link
Get-NanoLeaf
.Link
Expand Down
54 changes: 54 additions & 0 deletions docs/Add-HueLight.md
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
syntaxItem
```
```PowerShell
----------
```
```PowerShell
{@{name=Add-HueLight; CommonParameters=True; parameter=System.Object[]}}
```
---


Loading