-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLightScript.splatter.ps1
107 lines (94 loc) · 8.89 KB
/
LightScript.splatter.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#requires -Module Splatter
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path
Push-Location $myRoot
$excludeFromGet = 'Schedule', 'Sensor', 'Rule', 'Scene', 'Group', 'Configuration', 'Capability', 'Resource', 'Light', 'Detailed'
foreach ($api in 'Sensors', 'Rules', 'Schedules', 'Groups', 'Scenes', 'ResourceLinks')
{
$cmdletNoun = "Hue$($api.TrimEnd('s'))"
if ($api -eq 'Groups') {
$cmdletNoun = "HueRoom"
}
if ($api -eq 'ResourceLinks') {
$cmdletNoun = 'HueResource'
}
$SplatBase = @{
CommandName = "Get-HueBridge"
DefaultParameter = @{$api = $true }
InputParameter = 'Name', 'ExactMatch', 'RegularExpression','ID', 'Detailed'
}
#region Get-$CmdletNoun
$OutSplat = $SplatBase + @{
Synopsis = "Gets Hue $api"
Description = "Gets $api from one or more Hue Bridges"
FunctionName = "Get-$cmdletNoun"
Example = "Get-$cmdletNoun"
Link = "Remove-$cmdletNoun", "Get-HueBridge", "Send-HueBridge"
}
Out-Splat @OutSplat | Set-Content ".\$($OutSplat.FunctionName).ps1"
#endregion Get-$CmdletNoun
#region Remove-$CmdletNoun
$OutSplat = $SplatBase + @{
FunctionName = "Remove-$cmdletNoun"
Where = [ScriptBlock]::Create('$PSCmdlet.ShouldProcess("Delete ' + $api.TrimEnd('s') + '$($_.Name) ($($_.ID))")')
PipeTo = [ScriptBlock]::Create('Send-HueBridge -Method DELETE -Command {"' + $api.ToLower() + '/$($_.ID)"}')
CmdletBinding = 'SupportsShouldProcess=$true,ConfirmImpact="High"'
Synopsis = "Removes Hue $api"
Description = "Removes $api from one or more Hue Bridges"
Example = "Remove-$cmdletNoun -Name '${cmdletNoun}Name'"
Link = "Get-$cmdletNoun", "Get-HueBridge", "Send-HueBridge"
ExcludeParameter = $excludeFromGet
}
Out-Splat @OutSplat | Set-Content ".\$($OutSplat.FunctionName).ps1"
#endregion Remove-$CmdletNoun
}
Out-Splat -CommandName Get-HueBridge -FunctionName Read-HueSensor -DefaultParameter @{
Sensor=$true
} -InputParameter Name, ExactMatch, RegularExpression,ID -ExcludeParameter $excludeFromGet -Synopsis "Reads Hue Sensors" -Description "Reads Sensors values from the Hue Bridge" -AdditionalParameter @{
Config = @'
# If set, will read values from the configuration. By default, values are read from the sensor state.
[switch]
'@
} -Example 'Read-HueSensor -Name Daylight' -Link 'Write-HueSensor', 'Get-HueSensor', 'Get-HueBridge','Add-HueSensor', 'Remove-HueSensor' -Process {
$sensor = $_
$outObj =
if ($Config) {
$sensor.config.pstypenames.clear()
$sensor.config.pstypenames.add("Hue.Sensor.Config.$($sensor.Type)")
$sensor.config
} else {
$sensor.state.pstypenames.clear()
$sensor.state.pstypenames.add("Hue.Sensor.State.$($sensor.Type)")
$sensor.State
}
$outObj |
Add-Member NoteProperty Name $sensor.Name -PassThru -Force |
Add-Member NoteProperty UniqueID $sensor.UniqueID -PassThru -Force
} |
Set-Content .\Read-HueSensor.ps1
Out-Splat -CommandName Get-HueBridge -FunctionName Write-HueSensor -DefaultParameter @{
Sensor=$true
} -InputParameter Name, ExactMatch, RegularExpression,ID -ExcludeParameter $excludeFromGet -Synopsis "Write Hue Sensors" -Description "Writes data to sensors on the Hue Bridge" -AdditionalParameter @{
Config = @'
# If set, will write values from to configuration. By default, values are written to the sensor state.
[switch]
'@
Data = @'
# The data that will be written to the sensor
[Parameter(Mandatory,ValueFromPipeline)]
[PSObject]
'@
OutputInput = @'
# If set, will output the data that would be sent to the bridge. This is useful for creating scheudles, routines, and other macros.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
'@
} -Example 'Write-HueSensor -Name ChaseStatus1 -Data @{status=0}' -Link 'Read-HueSensor', 'Get-HueSensor', 'Get-HueBridge','Add-HueSensor', 'Remove-HueSensor' -Process {
$sensor = $_
if ($Config) {
$sensor | Send-HueBridge -Command "sensors/$($sensor.Id)/config" -Data $Data -Method PUT
} else {
$sensor | Send-HueBridge -Command "sensors/$($sensor.Id)/state" -Data $Data -Method PUT
}
} |
Set-Content .\Write-HueSensor.ps1
Pop-Location