Skip to content

Commit

Permalink
Merge pull request #33 from StartAutomating/HueSensorImprovement
Browse files Browse the repository at this point in the history
Hue sensor improvement
  • Loading branch information
StartAutomating authored Oct 3, 2022
2 parents ff17d61 + 1d7892b commit f85ecfd
Show file tree
Hide file tree
Showing 113 changed files with 4,381 additions and 1,064 deletions.
Binary file removed Add-HueSensor.ps1
Binary file not shown.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
## 0.2.5:
* Set-HueRule: Easier conditions (Fixes #28) and plural aliases (Fixes #31)
* Adding Rename-HueSensor (Fixes #26).
* Rename-HueLight: Adding [Alias('ID')] to -OldName (Fixes #27)
* Get-HueBridge: SupportShouldProcess (Fixes #30)
* Set-HueLight: Fixing -Brightness/SaturationIncrement (Fixes #29)
* Add-HueSensor: Adding -New (Fixes #25)
* Improved Repository Organization (Fixes #32)
---

## 0.2.4.1
* Adding help for Add-HueLight (#23)
* Fixing other markdown documentation layout issues
---


## 0.2.4
* Adding Add-HueLight (#18)
* Adding Get-HueLight -New (#21)
Expand Down
8 changes: 3 additions & 5 deletions Add-HueLight.ps1 → Functions/Hue/Add-HueLight.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function Add-HueLight {
<#
<#
.SYNOPSIS
Adds lights to Hue
.DESCRIPTION
Expand All @@ -15,12 +15,10 @@ function Add-HueLight {
Get-HueLight
.LINK
Set-HueLight
#>

[CmdletBinding(SupportsShouldProcess)]

#>

[CmdletBinding(SupportsShouldProcess)]
param(
# One or more Device Identifiers (serial numbers ).
# Use this parameter when adding lights that have already been assigned to another bridge.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
110 changes: 110 additions & 0 deletions Functions/Hue/Add-HueSensor.ps1
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.
5 changes: 3 additions & 2 deletions Get-HueBridge.ps1 → Functions/Hue/Get-HueBridge.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
.Example
Get-HueBridge
#>
[CmdletBinding(DefaultParameterSetName='ConnectionInfo')]
[OutputType([PSObject])]
[CmdletBinding(DefaultParameterSetName='ConnectionInfo',SupportsShouldProcess)]
[OutputType([PSObject])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="Parameters used as hints for Parameter Sets")]
param(
# If set, will get the schedules defined on the Hue bridge
Expand Down Expand Up @@ -131,6 +131,7 @@
$bridges | # Get all bridges
Send-HueBridge -Command $PSCmdlet.ParameterSetName.ToLower() | # get the set of data we want from the bridge.
ForEach-Object {
if ($WhatIfPreference) { return $_ }
if ('Config', 'Capabilities' -contains $psCmdlet.ParameterSetName) {
return $_ # config and capabilities are directly returned.
}
Expand Down
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.
35 changes: 35 additions & 0 deletions Functions/Hue/README.md
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) |


15 changes: 15 additions & 0 deletions Functions/Hue/README.ps1.md
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.
5 changes: 3 additions & 2 deletions Rename-HueLight.ps1 → Functions/Hue/Rename-HueLight.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ function Rename-HueLight
[OutputType([PSObject])]
param(
# The old name of the light. This can be a wildcard or regular expression.
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias('ID')]
[string]
$OldName,

# The new name of the light. A number sign will be replaced with the match number.
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[string]
$NewName
)
Expand Down
55 changes: 55 additions & 0 deletions Functions/Hue/Rename-HueSensor.ps1
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.
30 changes: 28 additions & 2 deletions Set-HueLight.ps1 → Functions/Hue/Set-HueLight.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,42 @@ function Set-HueLight
[float[]]
$XY,

# The increment in saturation. This will adjust the intensity of the color
# The increment in saturation. This will adjust the intensity of the color.
[Parameter(ValueFromPipelineByPropertyName)]
[ComponentModel.DefaultBindingProperty('sat_inc')]
[ValidateRange(-1,1)]
[ComponentModel.AmbientValue({
if ($_ -lt 0) {
[Math]::max(-254,
([int][Math]::Floor(([Math]::Abs($_) / 1) * [byte]::maxValue)) * -1
)
} elseif ($_ -gt 0) {
[Math]::min(254,
[int][Math]::Floor(($_ / 1) * [byte]::maxValue)
)
} else {
0
}
})]
[float]
$SaturationIncrement,

# An increment in luminance. This will adjust the brightness of the light
# An increment in luminance. This will adjust the brightness of the light.
[Parameter(ValueFromPipelineByPropertyName)]
[ComponentModel.DefaultBindingProperty('bri_inc')]
[ComponentModel.AmbientValue({
if ($_ -lt 0) {
[Math]::max(-254,
([int][Math]::Floor(([Math]::Abs($_) / 1) * [byte]::maxValue)) * -1
)
} elseif ($_ -gt 0) {
[Math]::min(254,
[int][Math]::Floor(($_ / 1) * [byte]::maxValue)
)
} else {
0
}
})]
[Alias('LuminanceIncrement')]
[ValidateRange(-1,1)]
[float]
Expand Down
Loading

0 comments on commit f85ecfd

Please sign in to comment.