-
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 #33 from StartAutomating/HueSensorImprovement
Hue sensor improvement
- Loading branch information
Showing
113 changed files
with
4,381 additions
and
1,064 deletions.
There are no files selected for viewing
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,110 @@ | ||
function Add-HueSensor | ||
{ | ||
<# | ||
.Synopsis | ||
Adds a sensor to a Hue Bridge. | ||
.Description | ||
Adds sensors to a Hue Bridge. | ||
Sensors can be physical sensors, such as a motion detector, or virtual sensors, such as GenericFlag. | ||
.Link | ||
Get-HueSensor | ||
.Example | ||
Add-HueSensor -Name "ChaseStatus1" -SensorType GenericStatus | ||
#> | ||
[OutputType([PSObject])] | ||
[CmdletBinding(SupportsShouldProcess)] | ||
param( | ||
# The name of the sensor. | ||
[Parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName,ParameterSetName='CustomSensor')] | ||
[string] | ||
$Name, | ||
|
||
<# | ||
The sensor type. | ||
Sensors can be: | ||
* Switches | ||
* OpenClose | ||
* Presence (motion detectors) | ||
* Temperature | ||
* Humidity | ||
* LightLevel | ||
* GenericFlag (used for virtual sensors) | ||
* GenericStatus (used for virtual sensors) | ||
#> | ||
[Parameter(Mandatory,Position=1,ValueFromPipelineByPropertyName,ParameterSetName='CustomSensor')] | ||
[ValidateSet('Switch','OpenClose','Presence','Temperature','Humidity','LightLevel', 'GenericFlag', 'GenericStatus')] | ||
[string] | ||
$SensorType, | ||
|
||
# The sensor ModelID | ||
[Parameter(Position=2,ValueFromPipelineByPropertyName,ParameterSetName='CustomSensor')] | ||
[string] | ||
$ModelID = "ABCD-12345", | ||
|
||
# The sensor manufacturer | ||
[Parameter(Position=2,ValueFromPipelineByPropertyName,ParameterSetName='CustomSensor')] | ||
[string] | ||
$Manufacturer = "ACME LTD", | ||
|
||
# The sensor unique ID. | ||
[Parameter(Position=3,ValueFromPipelineByPropertyName,ParameterSetName='CustomSensor')] | ||
[string] | ||
$UniqueID= [guid]::NewGuid().tostring('n'), | ||
|
||
# The sensor version. | ||
[Parameter(Position=4,ValueFromPipelineByPropertyName,ParameterSetName='CustomSensor')] | ||
[Version] | ||
$Version = '0.1', | ||
|
||
# If set, will search for new sensors to add. | ||
[Parameter(Mandatory,ParameterSetName='NewSensor')] | ||
[Alias('Find','Discover')] | ||
[switch] | ||
$New | ||
) | ||
|
||
begin { | ||
$myCmd = $MyInvocation.MyCommand | ||
} | ||
|
||
process { | ||
#region Prepare REST Input | ||
$sensorRest = | ||
if ($PSCmdlet.ParameterSetName -eq 'CustomSensor') { | ||
if ($SensorType) { | ||
$sensorType = | ||
foreach ($_ in $myCmd.Parameters['SensorType'].Attributes) { | ||
if (-not $_.ValidValues) { continue } | ||
$_.ValidValues -eq $SensorType | ||
break | ||
} | ||
} | ||
|
||
@{ | ||
name = $Name | ||
modelid = $ModelID | ||
swversion = "$Version" | ||
type = 'CLIP' + $SensorType | ||
uniqueid = $UniqueID | ||
manufacturername = $Manufacturer | ||
recycle = $false | ||
} | ||
} elseif ($New) { | ||
$name = "new" | ||
} | ||
#endregion Prepare REST Input | ||
|
||
|
||
if ($WhatIfPreference) { | ||
return $sensorRest | ||
} | ||
|
||
if ($PSCmdlet.ShouldProcess("Add-HueSensor $name")) { | ||
Get-HueBridge | | ||
Send-HueBridge -Method POST -Data $sensorRest -Command "sensors" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,35 @@ | ||
This directory contains LightScript's functions for [Philips Hue Bridges](https://www.philips-hue.com/). | ||
|
||
|
||
|Name |Verb |Noun |Source | | ||
|--------------------|----------|-----------|----------------------------------------------------| | ||
|Add-HueLight |Add |HueLight |[Add-HueLight.ps1](Add-HueLight.ps1) | | ||
|Add-HueRoom |Add |HueRoom |[Add-HueRoom.ps1](Add-HueRoom.ps1) | | ||
|Add-HueSchedule |Add |HueSchedule|[Add-HueSchedule.ps1](Add-HueSchedule.ps1) | | ||
|Add-HueSensor |Add |HueSensor |[Add-HueSensor.ps1](Add-HueSensor.ps1) | | ||
|Connect-HueBridge |Connect |HueBridge |[Connect-HueBridge.ps1](Connect-HueBridge.ps1) | | ||
|Disconnect-HueBridge|Disconnect|HueBridge |[Disconnect-HueBridge.ps1](Disconnect-HueBridge.ps1)| | ||
|Find-HueBridge |Find |HueBridge |[Find-HueBridge.ps1](Find-HueBridge.ps1) | | ||
|Get-HueBridge |Get |HueBridge |[Get-HueBridge.ps1](Get-HueBridge.ps1) | | ||
|Get-HueLight |Get |HueLight |[Get-HueLight.ps1](Get-HueLight.ps1) | | ||
|Get-HueResource |Get |HueResource|[Get-HueResource.ps1](Get-HueResource.ps1) | | ||
|Get-HueRoom |Get |HueRoom |[Get-HueRoom.ps1](Get-HueRoom.ps1) | | ||
|Get-HueRule |Get |HueRule |[Get-HueRule.ps1](Get-HueRule.ps1) | | ||
|Get-HueScene |Get |HueScene |[Get-HueScene.ps1](Get-HueScene.ps1) | | ||
|Get-HueSchedule |Get |HueSchedule|[Get-HueSchedule.ps1](Get-HueSchedule.ps1) | | ||
|Get-HueSensor |Get |HueSensor |[Get-HueSensor.ps1](Get-HueSensor.ps1) | | ||
|Read-HueSensor |Read |HueSensor |[Read-HueSensor.ps1](Read-HueSensor.ps1) | | ||
|Remove-HueResource |Remove |HueResource|[Remove-HueResource.ps1](Remove-HueResource.ps1) | | ||
|Remove-HueRoom |Remove |HueRoom |[Remove-HueRoom.ps1](Remove-HueRoom.ps1) | | ||
|Remove-HueRule |Remove |HueRule |[Remove-HueRule.ps1](Remove-HueRule.ps1) | | ||
|Remove-HueScene |Remove |HueScene |[Remove-HueScene.ps1](Remove-HueScene.ps1) | | ||
|Remove-HueSchedule |Remove |HueSchedule|[Remove-HueSchedule.ps1](Remove-HueSchedule.ps1) | | ||
|Remove-HueSensor |Remove |HueSensor |[Remove-HueSensor.ps1](Remove-HueSensor.ps1) | | ||
|Rename-HueLight |Rename |HueLight |[Rename-HueLight.ps1](Rename-HueLight.ps1) | | ||
|Rename-HueSensor |Rename |HueSensor |[Rename-HueSensor.ps1](Rename-HueSensor.ps1) | | ||
|Send-HueBridge |Send |HueBridge |[Send-HueBridge.ps1](Send-HueBridge.ps1) | | ||
|Set-HueLight |Set |HueLight |[Set-HueLight.ps1](Set-HueLight.ps1) | | ||
|Set-HueRule |Set |HueRule |[Set-HueRule.ps1](Set-HueRule.ps1) | | ||
|Write-HueSensor |Write |HueSensor |[Write-HueSensor.ps1](Write-HueSensor.ps1) | | ||
|
||
|
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,15 @@ | ||
This directory contains LightScript's functions for [Philips Hue Bridges](https://www.philips-hue.com/). | ||
|
||
~~~PipeScript { | ||
Import-Module ../../LightScript.psd1 -Global | ||
[PSCustomObject]@{ | ||
Table = Get-Command -Module LightScript | | ||
Where-Object { $_.ScriptBlock.File -like "$pwd*" } | | ||
.Name .Verb .Noun .Source { | ||
$relativePath = $_.ScriptBlock.File.Substring("$pwd".Length) -replace '^[\\/]' | ||
"[$relativePath]($relativePath)" | ||
} | ||
} | ||
} | ||
~~~ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,55 @@ | ||
function Rename-HueSensor | ||
{ | ||
<# | ||
.Synopsis | ||
Renames Hue Sensors | ||
.Description | ||
Renames one or more Hue Sensors. | ||
.Example | ||
Rename-HueSensor | ||
.Link | ||
Get-HueBridge | ||
.Link | ||
Get-HueSensor | ||
#> | ||
[OutputType([PSObject])] | ||
param( | ||
# The old name of the Sensor. This can be a wildcard or regular expression. | ||
[Parameter(Mandatory,ValueFromPipelineByPropertyName)] | ||
[Alias('ID')] | ||
[string] | ||
$OldName, | ||
|
||
# The new name of the Sensor. A number sign will be replaced with the match number. | ||
[Parameter(Mandatory,ValueFromPipelineByPropertyName)] | ||
[string] | ||
$NewName | ||
) | ||
|
||
begin { | ||
$Sensors = Get-HueSensor | ||
$bridges = Get-HueBridge | ||
} | ||
|
||
process { | ||
$Sensors | | ||
Where-Object { | ||
#region Find matching Sensors | ||
($_.Id -eq $oldName) -or | ||
($_.Name -like $OldName) -or | ||
($oldName -as [regex] -and $_.Name -match $oldName) | ||
#endregion Find matching Sensors | ||
} | | ||
ForEach-Object -Begin { | ||
$matchCount = 0 | ||
} -Process { | ||
#region Rename the Sensors | ||
$MatchCount++ | ||
$realNewName = $NewName -replace '#', $MatchCount | ||
$SensorToRename = $_ | ||
$bridges | Send-HueBridge -Command "sensors/$($SensorToRename.id)" -Method PUT -Data @{name=$realNewName} | ||
#endregion Rename the Sensors | ||
} | ||
} | ||
} | ||
|
File renamed without changes.
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
Oops, something went wrong.