Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HomeKit HMHome and HMRoom identifiers / extra metadata

In my application I am using HomeKit. You can add/remove HMHome and HMRoom object, but I would also like to add some metadata to them. For example in my application I want to be able to add an icon to a HMRoom and add an Array of items to it too.

My solution is that I use it in combination with CoreData and store the extra information about the HMRoom, but there is no way to identify the HMHome and HMRoom objects, other than their name. This would not be a problem if my application would be the only application in the world to edit the HomeKit objects, but of course there could be other applications, also adjusting the HMHome and HMRoom objects (removing them, renaming them).

So I would really have a problem, when the user does one of the following things:

  1. Start my application
  2. Add a HMHome and HMRoom object
  3. Add some metadata to the HMRoom object, through my application, which is stored in my CoreData database
  4. Quit my application
  5. Start another application and rename the HMRoom they just created
  6. Start my application again

Because there is no known identifier for the HMHome and HMRoom objects, I cannot find the metadata I stored in CoreData anymore and that metadata is actually lost, because I can no longer match the name with the created HMRoom with the data in my CoreData database.

So, my question is: Is there a way to 'identify' HMRoom and HMHome objects other than their name?

like image 427
Wim Haanstra Avatar asked Sep 28 '22 18:09

Wim Haanstra


2 Answers

In iOS9, you can use the uniqueIdentifier to always identify the same object. This UUID stays the same whether the room gets renamed.

like image 144
Maria Avatar answered Oct 06 '22 20:10

Maria


According to the documentation there is no other identifier for HMHome and HMRoom than the name. But they both have accessories property, and HMAccessory has the identifier property, which is persistent (at least until the user removes an accessory and adds it again, which wouldn't be a common thing to see, I hope).

So you can save accessories assigned to a given home or room along with other metadata. And if the home's or room's name changes, in most of the cases you should still be able to detect what the original name was, looking at the stored accessories.

like image 31
Michał Ciuba Avatar answered Oct 06 '22 18:10

Michał Ciuba