-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hue] Fix migration of API v1 legacy data to new v2 things #16714
Conversation
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@jlaur ping. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/philips-hue-clip-2-api-v2-discussion-thread/142111/473 |
@andrewfg - I did a quick test run by finding a sensor and a light with same numerical id:
In my case I selected 38:
I then created a v1 bridge and these two devices as v1 things. But before testing a migration, I checked the console command (shortened to relevant output here): openhab> hue hue:bridge-api2:home things
// Device things
Thing device 38 "Snowdrop" [resourceId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"] // Color temperature light idV1:/lights/38 The sensor "Hue ambient light sensor 6" didn't show up. For the light, I suppose the expected result would be:
and that the sensor is also included? |
@jlaur the 'Thing device 38 "Snowdrop"' is expected; it allows the v2 device 38 thing to be created and to take over the properties and linked items of the v1 [light] 38 thing. That is as intended. However I am surprised that the console did not find the '38 Hue ambient light sensor' thing. => Is that correct? EDIT: the console should have found that sensor thing but it's thing Id should not be 38 but rather a full v2 API resource id string. As the binding could not try to migrate the v1 38 sensor thing.. |
Ah, got it. I created another v1 thing which also got a thing id like that.
Correct.
Perhaps the generated thing ids should be "light-38" and "sensor-38" rather than just "38" to really solve this? |
I thought about that. It would avoid ambiguity between sensors and lights of the same name. And allow both sensors and lights to be migrated. However the issue is that we try to automatically migrate all the legacy items (and thus rules, sitemaps, etc) that are linked to 'hue:bridge:[light]:38:channelId' to 'hue:bridge-api2:device:38:channelId' -- And if we would actually change the thing id in that process, it would not be at all transparent. Indeed if we would change the id from 38 we might just as well use the new 20+ character resource id. EDIT: rather than talking about (say) '38' maybe it helps to understand if I talk about a normal thing id. Lets say that a legacy system has one light and one switch in one room. There are basically two scenarios.. Scenario A the two legacy devices have unique names:
Scenario B the two legacy devices have identical names:
EDIT 2: For the avoidance of doubt, the issue is NOT primarily caused by two things having the Hue internal id '/sensors/38' resp. '/lights/38', but rather due to the fact that in OH those things might have been created as legacy things with the same thing id (38) albeit with different thing type id; and when those would be migrated to v2 then there is a conflict migrating due to the target thing id (38) and thing type id (device) being the same. |
@jlaur the good news is that I tested it again on my system, and I confirm that it works as I had intended; the bad news is that I realised that there is a yet more complex edge case -- namely if the user would have one of each v1 type of light and one of each v1 type of sensor in their home then it would be theoretically possible for them to have created all of the v1 things below which all have unique ThingUIDs; however all of those unique things would be candidates to (try to) migrate their data to a v2
Ideally the thing data migration v1 to v2 should use the same source and target thing id -- wherever possible -- since it is easier for the user to keep track of what is going on in their items, rules, and sitemaps etc. But in the case above there could be worst case 14 things with potentially the same id of which OH would consider 13 to be illegal. I can think of a few possible ways forward..
|
@andrewfg - I think I do not yet have the full understanding. I'm now realizing I might already have started mixing up things here:
I was considering the ids from the API, but actually they just happened to be auto-generated Thing IDs from the discovery. So in my case, the last part of the Thing UID was 38 for the light, but actually it could be anything if I had created that Thing manually. Hence your kitchen examples? I would need to get back to this with more focus and understanding. For now, my input would be:
Therefore, I wouldn't encourage you to invest too much in getting this totally right, although it probably itches a bit that it is currently flawed. To me, it doesn't make much difference if option 1 or 2 is chosen. Perhaps conflicts can be logged, in order to be handled manually by the user? However, if you want to invest into getting this right, I can certainly assist, but would need some focus time in order to be helpful. I don't even remember the current "mechanism" for detecting when Things are migrated and how to migrate them. A quick scratch in the surface. Mostly for my own train of thought, but please correct me where I'm wrong.
So I think it's certainly possible to do the mapping and thus a reliable migration? Now I get back to wondering why the Thing UID is significant at all in the migration process? Sorry for the slow ride. 😄 |
@jlaur many thanks for your inputs. Yes it does 'itch'. But probably a bad fix would itch more.
You are probably right. The migration process basically does two things..
|
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@jlaur I think this is now fixed and ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM. Only one minor comment for consideration.
...b.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2BridgeHandler.java
Show resolved
Hide resolved
@andrewfg - new console test having added v1 sensor and light both with id 37 and adding "my label" in the Thing labels: Thing device 00000000-0000-0000-0000-000000000001 "Loftlampe my label" [resourceId="00000000-0000-0000-0000-000000000001"] // Color temperature light idV1:/lights/37
Thing device 00000000-0000-0000-0000-000000000002 "Postkasse sensor my label" [resourceId="00000000-0000-0000-0000-000000000002"] // Hue motion sensor idV1:/sensors/37 The |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
…6714) Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
…6714) Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
…6714) Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch> Signed-off-by: Paul Smedley <paul@smedley.id.au>
…6714) Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch> Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
…6714) Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
…6714) Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
…6714) Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
Resolves #16711
When migrating a system from API v1 to v2, there could under some circumstances, be conflicts preventing a) the creation of new v2 things, and b) the migration thing attributes and linked items from the legacy v1 thing to the respective new v2 thing. This was due to ambiguous thing ids if there happened to be multiple v1 legacy things having identical thing ids and different thing type ids.
This PR resolves that issue by ensuring that:
Signed-off-by: Andrew Fiddian-Green software@whitebear.ch