-
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 #5 from StartAutomating/BugFixesAndNewFixtures
Bug fixes and new fixtures
- Loading branch information
Showing
16 changed files
with
859 additions
and
50 deletions.
There are no files selected for viewing
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,9 @@ | ||
## 0.2: | ||
Adding: Disconnect-HueBridge, Disconnect-NanoLeaf, Disconnect-Twinkly (#2) | ||
Adding Pixoo commands: Connect/Disconnect/Get/Set-Pixoo (#4) | ||
|
||
--- | ||
## 0.1: | ||
Initial Release of LightScript: Smarter Lighting with PowerShell | ||
|
||
Script your Hue Bridge, NanoLeaf, or Twinkly lights. |
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,78 @@ | ||
function Connect-Pixoo | ||
{ | ||
<# | ||
.Synopsis | ||
Connects to a Pixoo | ||
.Description | ||
Connects to a Pixoo over Wifi | ||
.Example | ||
Connect-Pixoo 1.2.3.4 -PassThru | ||
.Link | ||
Get-Pixoo | ||
#> | ||
[OutputType([Nullable], [PSObject])] | ||
param( | ||
# The IP Address for the Twinkly device. This can be discovered thru the phone user interface. | ||
[Parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName)] | ||
[Alias('PixooIPAddress')] | ||
[IPAddress] | ||
$IPAddress, | ||
|
||
# If set, will output the connection information. | ||
[switch] | ||
$PassThru | ||
) | ||
|
||
begin { | ||
if ($home) { | ||
$lightScriptRoot = Join-Path $home -ChildPath LightScript | ||
} | ||
} | ||
|
||
process { | ||
#region Attempt to Contact the Device | ||
$pixooConf = Invoke-RestMethod -Uri "http://$IPAddress/post" -Method POST -Body ( | ||
@{ | ||
Command="Channel/GetAllConf" | ||
} | ConvertTo-Json | ||
) | ||
#endregion Attempt to Contact the Device | ||
|
||
|
||
if ($pixooConf) { | ||
$macAddress = | ||
if ($PSVersionTable.Platform -like 'Win*' -or -not $PSVersionTable.Platform) { | ||
Get-NetNeighbor | Where-Object IPAddress -eq $IPAddress | Select-Object -ExpandProperty LinkLayerAddress | ||
} elseif ($ExecutionContext.SessionState.InvokeCommand.GetCommand('nmap','Application')) { | ||
nmap -Pn "$ipAddress" | | ||
Where-Object { $_ -like 'MAC Address:*'} | | ||
ForEach-Object { @($_ -split ' ')[2] } | ||
} | ||
|
||
if (-not $macAddress) { | ||
Write-Error "Unable to resolve MAC address for $ipAddress, will not save connection" | ||
return | ||
} | ||
#region Save Device Information | ||
if ($home) { | ||
if (-not (Test-Path $lightScriptRoot)) { | ||
$createLightScriptDir = New-Item -ItemType Directory -Path $lightScriptRoot | ||
if (-not $createLightScriptDir) { return } | ||
} | ||
|
||
|
||
$pixooDataFile = Join-Path $lightScriptRoot ".$($macAddress).pixoo.clixml" | ||
$pixooConf.pstypenames.clear() | ||
$pixooConf.pstypenames.add('Pixoo') | ||
$pixooConf | | ||
Add-Member NoteProperty IPAddress $IPAddress -Force -PassThru | | ||
Add-Member NoteProperty MACAddress $macAddress -Force -PassThru | | ||
Export-Clixml -Path $pixooDataFile | ||
} | ||
#endregion Save Device Information | ||
if ($PassThru) { | ||
$pixooConf | ||
} | ||
} | ||
} | ||
} |
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,49 @@ | ||
function Disconnect-HueBridge | ||
{ | ||
<# | ||
.Synopsis | ||
Disconnects a Hue Bridge. | ||
.Description | ||
Disconnects a new Hue Bridge and removes connection information. | ||
.Link | ||
Connect-HueBridge | ||
.Example | ||
Disconnect-HueBridge -HueBridgeIP 1.2.3.4 | ||
#> | ||
[CmdletBinding(DefaultParameterSetName='ExistingConnection')] | ||
[OutputType([Nullable], [PSObject])] | ||
param( | ||
# The IP Address of the Hue Bridge | ||
[Parameter(Mandatory,ParameterSetName='NewConnection',ValueFromPipelineByPropertyName)] | ||
[Alias('IPAddress')] | ||
[IPAddress] | ||
$HueBridgeIP | ||
) | ||
|
||
begin { | ||
if ($home) { | ||
$lightScriptRoot = Join-Path $home -ChildPath LightScript | ||
} | ||
} | ||
|
||
process { | ||
if (-not (Test-Path $lightScriptRoot)) { | ||
$createLightScriptDir = New-Item -ItemType Directory -Path $lightScriptRoot | ||
if (-not $createLightScriptDir) { return } | ||
} | ||
|
||
|
||
#region Find and Remove Connection | ||
$files = @(Get-ChildItem -Path $lightScriptRoot -ErrorAction SilentlyContinue -Filter *.huebridge.clixml -Force) | ||
$files | | ||
ForEach-Object { | ||
$file = $_ | ||
$fileInfo = Import-Clixml -LiteralPath $file.FullName | ||
if ($fileInfo.IPAddress -eq $HueBridgeIP -and $PSCmdlet.ShouldProcess("Remove $($fileInfo.DeviceID)")) { | ||
Remove-Item -LiteralPath $file.FullName -Force | ||
} | ||
} | ||
#endregion Find and Remove Connection | ||
} | ||
} | ||
|
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,49 @@ | ||
function Disconnect-Nanoleaf | ||
{ | ||
<# | ||
.Synopsis | ||
Disconnects a new Nanoleaf controller. | ||
.Description | ||
Disconnnects a new Nanoleaf controller and removes connection information. | ||
.Example | ||
Disconnect-NanoLeaf -IPAddress 1.2.3.4 | ||
.Link | ||
Connect-NanoLeaf | ||
#> | ||
[CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')] | ||
[OutputType([Nullable], [PSObject])] | ||
param( | ||
# The IP Address of the Nanoleaf | ||
[Parameter(Mandatory,ValueFromPipelineByPropertyName)] | ||
[Alias('IPAddress')] | ||
[IPAddress] | ||
$NanoLeafIP | ||
) | ||
|
||
begin { | ||
if ($home) { | ||
$lightScriptRoot = Join-Path $home -ChildPath LightScript | ||
} | ||
} | ||
|
||
process { | ||
if (-not (Test-Path $lightScriptRoot)) { | ||
$createLightScriptDir = New-Item -ItemType Directory -Path $lightScriptRoot | ||
if (-not $createLightScriptDir) { return } | ||
} | ||
|
||
#region Find and Remove Connection | ||
$files = @(Get-ChildItem -Path $lightScriptRoot -ErrorAction SilentlyContinue -Filter *.nanoleaf.clixml -Force) | ||
$files | | ||
ForEach-Object { | ||
$file = $_ | ||
$fileInfo = Import-Clixml -LiteralPath $file.FullName | ||
if ($fileInfo.IPAddress -eq $NanoLeafIP -and $PSCmdlet.ShouldProcess("Remove $($fileInfo.DeviceName)")) { | ||
Remove-Item -LiteralPath $file.FullName -Force | ||
} | ||
} | ||
|
||
|
||
#endregion Find and Remove Connection | ||
} | ||
} |
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,40 @@ | ||
function Disconnect-Pixoo | ||
{ | ||
<# | ||
.Synopsis | ||
Disconnects a Pixoo | ||
.Description | ||
Disconnects a Pixoo, removing stored device info | ||
.Example | ||
Disconnect-Pixoo 1.2.3.4 | ||
.Link | ||
Connect-Pixoo | ||
#> | ||
[OutputType([Nullable], [PSObject])] | ||
[CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')] | ||
param( | ||
# The IP Address for the Twinkly device. This can be discovered thru the phone user interface. | ||
[Parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName)] | ||
[Alias('PixooIPAddress')] | ||
[IPAddress] | ||
$IPAddress | ||
) | ||
|
||
begin { | ||
if ($home) { | ||
$lightScriptRoot = Join-Path $home -ChildPath LightScript | ||
} | ||
} | ||
|
||
process { | ||
@(Get-ChildItem -Filter *.pixoo.clixml -Path $lightScriptRoot) | | ||
Foreach-Object { | ||
$file = $_ | ||
$fileInfo = Import-Clixml -LiteralPath $file.FullName | ||
if ($fileInfo.IPAddress -eq $IPAddress -and $PSCmdlet.ShouldProcess("Remove $($fileInfo.MACAddress)")) { | ||
Remove-Item -LiteralPath $file.FullName -Force | ||
} | ||
} | ||
} | ||
} | ||
|
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,49 @@ | ||
function Disconnect-Twinkly | ||
{ | ||
<# | ||
.Synopsis | ||
Disconnects a Twinkly light controller. | ||
.Description | ||
Disconnects a Twinkly light controller | ||
.Example | ||
Disconnect-Twinkly 192.168.0.144 | ||
.Link | ||
Connect-Twinkly | ||
#> | ||
[OutputType([Nullable], [PSObject])] | ||
param( | ||
# The IP Address for the Twinkly device. This can be discovered thru the phone user interface. | ||
[Parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName)] | ||
[Alias('TwinklyIPAddress')] | ||
[IPAddress] | ||
$IPAddress, | ||
|
||
# If set, will output the connection information. | ||
[switch] | ||
$PassThru | ||
) | ||
|
||
begin { | ||
if ($home) { | ||
$lightScriptRoot = Join-Path $home -ChildPath LightScript | ||
} | ||
} | ||
|
||
process { | ||
if (-not (Test-Path $lightScriptRoot)) { | ||
$createLightScriptDir = New-Item -ItemType Directory -Path $lightScriptRoot | ||
if (-not $createLightScriptDir) { return } | ||
} | ||
|
||
@(Get-ChildItem -Filter *.twinkly.clixml -Path $lightScriptRoot) | | ||
Foreach-Object { | ||
$file = $_ | ||
$fileInfo = Import-Clixml -LiteralPath $file.FullName | ||
if ($fileInfo.IPAddress -eq $IPAddress -and $PSCmdlet.ShouldProcess("Remove $($fileInfo.uuid)")) { | ||
Remove-Item -LiteralPath $file.FullName -Force | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
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,3 @@ | ||
Write-formatView -TypeName Pixoo -Property IPAddress, MACAddress, Brightness | ||
|
||
Write-formatView -TypeName Pixoo -Property RotationFlag, GyrateAngle, MirrorFlag -Name Orientation |
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,58 @@ | ||
function Get-Pixoo | ||
{ | ||
<# | ||
.Synopsis | ||
Gets Pixoo Devices | ||
.Description | ||
Gets saved Pixoo Devices | ||
.Example | ||
Get-Pixoo | ||
.LINK | ||
Connect-Pixoo | ||
.LINK | ||
Set-Pixoo | ||
#> | ||
[CmdletBinding(DefaultParameterSetName="ListDevices")] | ||
param( | ||
# The IP Address for the Twinkly device. This can be discovered thru the phone user interface. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[Alias('PixooIPAddress')] | ||
[IPAddress[]] | ||
$IPAddress | ||
) | ||
|
||
begin { | ||
if (-not $script:PixooCache) { | ||
$script:PixooCache = @{} | ||
} | ||
if ($home) { | ||
$lightScriptRoot = Join-Path $home -ChildPath LightScript | ||
} | ||
} | ||
|
||
process { | ||
#region Default to All Devices | ||
if (-not $IPAddress) { # If no -IPAddress was passed | ||
if ($home) { | ||
# Read all .twinkly.clixml files beneath your LightScript directory. | ||
Get-ChildItem -Path $lightScriptRoot -ErrorAction SilentlyContinue -Filter *.pixoo.clixml -Force | | ||
Import-Clixml | | ||
ForEach-Object { | ||
if (-not $_) { return } | ||
$pixooConnection = $_ | ||
$script:PixooCache["$($pixooConnection.IPAddress)"] = $pixooConnection | ||
} | ||
|
||
$IPAddress = $script:PixooCache.Keys # The keys of the device cache become the -IPAddress. | ||
} | ||
if (-not $IPAddress) { # If we still have no -IPAddress | ||
return # return. | ||
} | ||
} | ||
#endregion Default to All Devices | ||
|
||
if ($PSCmdlet.ParameterSetName -eq 'ListDevices') { | ||
return $script:PixooCache.Values | ||
} | ||
} | ||
} |
Oops, something went wrong.