-
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.
…Fixes #27)
- Loading branch information
James Brundage
committed
Oct 3, 2022
1 parent
dd6f320
commit d363a01
Showing
2 changed files
with
58 additions
and
2 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
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 | ||
} | ||
} | ||
} | ||
|