character length of the 3 argument is too long
Opened this issue · 4 comments
Hello,
I have this error :
$LightName = "Lampe du salon"
[HueLight]::New($LightName, $Endpoint, $UserID)
Exception setting "Light": "The character length of the 3 argument is too long. Shorten the character length of the argument so it is fewer than or equal to "2" characters, and
then try the command again."
My light name is not so long. My endpoint is IP address.
When you have a moment, could you run this command manually, substituting in the API key and Bridge IP address and upload/attach the output?
$Hue = Invoke-RestMethod -Method Get -Uri "http://(BridgeIP)/api/(APIKey)/lights"
$Hue | ConvertTo-Json -Depth 99 | Out-File .\Output.json
Thanks
Lewis
I've checked my setting here:
- No problems with real long names (21 chars)
- No problems with real long names including space char
Code is from release 10th october 2017.
Seems we really need that JSON file ;-)
Thanks @andreaswditze
The "Light" variable is in the class and set in the constructor and used to send instructions to the API URLs for that "light". It's restricted to 2 characters so I'd like to see the output to understand if there's a luminaire with a number 100 or above. Could use an [int]
but the value is used only as a string in API calls so seems pointless. I understand that a bridge only supports up to 50 lights (luminaires) so I wouldn't expect light numbers to exceed 99 but you never know I guess. Hopefully that output sheds some...err, light.
[ValidateLength(1,2)][string] $Light
OK, I think this is resolved now. It does occur as a result of using an incorrect light name when attempting to instantiate the object but the error received is not informative because the error triggered was as a result of attempting to set the $Light property of the class to $null. The reason for that is that the search for the light's ID (number) came back empty.
So if you specified an incorrect name, group name or sensor name, you would see something like this:
Exception setting "Light": "The character length (0) of the argument is too short. Specify an argument with a length
that is greater than or equal to "1", and then try the command again."
The reason is that in each of the classes, the "search" function that sets the value of the $Light property was attempting to set the value too early... $this.Light being the class property so doing this works, but is obviously bad since the error would never have thrown.
$this.Light = $Lights | Where-Object {$_.Value.Name -eq $Name} | Select Name -ExpandProperty Name
If ($this.Light) {
Return $this.Light
}
Else {
Throw "No light name matching `"$Name`" was found in the Hue Bridge `"$($this.BridgeIP)`".`r`nTry using [HueBridge]::GetLightNames() to get a full list of light names in this Hue Bridge."
}
If we replace the above use of $this.Light with some other variable set only within that method and the light name wasn't found, the error will throw since it would be empty. I've updated the [HueLight] class as follows to fix this issue.
$SelectedLight = $Lights | Where-Object {$_.Value.Name -eq $Name} | Select-Object Name -ExpandProperty Name
If ($SelectedLight) {
Return $SelectedLight
}
Else {
Throw "No light name matching `"$Name`" was found in the Hue Bridge `"$($this.BridgeIP)`".`r`nTry using [HueBridge]::GetLightNames() to get a full list of light names in this Hue Bridge."
}
The [HueGroup] and [HueSensor] classes have been fixed in similar ways but if the name of the light, group or sensor doesn't exist and/or can't be found, you will now see the informative error telling you as much.
@tomaaa - can you please let me know if you have any more issues? I'll be upping 1.2.6 to the PowerShell Gallery shortly.
Thanks for the report.