Closed PonchoPowers closed 2 years ago
I am wondering if the FFFE is irrelevant or not, as in do all Hue Bridges contain it and it is relatively meaningless? I will debug later and see if the MAC address (or serial number) as it is called in the code is being returned with the FFFE missing and report back here once I've done so.
I have seen the same thing: https://github.com/michielpost/Q42.HueApi/issues/226
Ah I never spotted that it had been previously reported. I've also just noticed that on the bottom of the bridge that it is only the last 6 characters that matter so this could be a path forwards to substring the value and rename it to serial number or something within the library itself, and then add an explanation as to why, otherwise people will keep coming across this and they will end up wasting time trying to work out what is going on.
I've created the following extension class, I'm wondering if it will be accepted into the library as a PR?
public static class HueBridgeSerialNumberExtensions
{
private const int _SERIAL_NUMBER_LENGTH = 6;
public static string GetSerialNumber(this LocatedBridge locatedBridge)
{
if (locatedBridge == null)
{
throw new ArgumentNullException(nameof(locatedBridge));
}
return GetSerialNumber(locatedBridge.BridgeId);
}
public static string GetSerialNumber(this BridgeConfig bridgeConfig)
{
if (bridgeConfig == null)
{
throw new ArgumentNullException(nameof(bridgeConfig));
}
return GetSerialNumber(bridgeConfig.BridgeId);
}
private static string GetSerialNumber(string bridgeId)
{
if (bridgeId == null)
{
throw new ArgumentNullException(nameof(bridgeId));
}
if (bridgeId.Length < _SERIAL_NUMBER_LENGTH)
{
throw new ArgumentException($"Hue Bridge ID must be at least {_SERIAL_NUMBER_LENGTH} characters in length.");
}
return bridgeId[^_SERIAL_NUMBER_LENGTH..];
}
}
As doing so gives a consistent way to get the bridge serial number rather than the bridge ID, without breaking any existing code.
For the HttpBridgeLocator, https://discovery.meethue.com is used, it returns an id
property that is set as 'BridgeId'
For the other locators, when a bridge is found, it is checked by doing a request to http://bridge-ip/description.xml
, then the serialNumber
field is used to fill BridgeId
The value of these fields does not match and description.xml misses the extra fffe
Getting the BridgeConfig also has the extra fffe
for BridgeId
V2 API also returns the extra fffe
in the 'bridge_id' property
All Hue APIs return the extra fffe
. So considering this, I'd think the best way is to treat that as the correct value to work with.
So what would be the best way to solve this? I can see a few options:
fffe
in the ID fieldThese changes would break compatibility. Might not be a huge problem?
If it is a problem, we can create a new Id property that always includes the extra fffe
I think making it consistent by inserting the fffe makes the most sense. I've worked around the issue with my own extension method, so from my perspective it doesn't matter anymore, but future developers might be caught out by this and if this change is made I can update to the latest version and remove the extension methods I've added to my codebase.
Ok. Fixed in version 3.20.0. Correct BridgeId is now always returned.
Sometimes the LocatedBridge BridgeId is not set correctly.
I'm using the following code:
If I run the code a few times in quick succession, the MAC address goes from ecb5fafffe2d12ab to ecb5fa2d12ab.
I haven't debugged yet to see where the problem is coming from, but I wanted to log this as a bug because the issue isn't arising in the code I've written, so I was wondering if this was a known issue or not?