home-assistant / iOS

:iphone: Home Assistant for Apple platforms
https://companion.home-assistant.io
Other
1.55k stars 301 forks source link

Deleting & Reinstalling Mobile App Creates Multiple Integration Instances in HA #819

Closed mwunderling closed 4 years ago

mwunderling commented 4 years ago

Model Name: iPhoneXR, iPhone8, multiple iPad models... Software Version: 13.5.1 App version: 2020.3.1(1)

Home Assistant Core Version 0.112.4

Describe the bug Reinstalling the mobile app on an iOS device where the app had previously been installed & configured will create multiple integration instances and new (duplicate) entities in HA (see imgs 1&2)

To Reproduce 1) Download & configure mobile app on iOS device 2) Delete app from device 3) re-download and configure mobile app 4) Check mobile app integrations instances in HA Note: removing the prior integration from the HA side between steps 2&3 appears to have no impact. When I've reinstalled the mobile app across my devices, each time, 2 integration instances appeared on the HA integrations page (see img1).

Expected behavior Either: a) Preserve the prior integration instance when the app is reinstalled (...from the HA .storage files) b) Wipe the older integration instance and start anew

Screenshots HA mobile app img1 HA mobile app img2

Additional context This issue makes entity mgmt difficult and confusing. It also potentially wrecks havoc with device presence detection.

Current Workaround: 1) Remove both integration instances from HA 2) From the device, open the app and instantiate a refresh event via pull down method ...this appears to create a reset event with the integration on the HA side. 3) Review integration in HA, should only have one instance now with corresponding single set of entities

It's probably worth adding to your documentation on the companion website what users should expect from the HA side if they have to delete & reinstall the mobile app on their device.

Note: I did have to recover my HA instance a few months back due to a disk corruption event, so it is possible this issue is unique to my environment (I am just now getting around to re-establishing presence detection....)

TomBrien commented 4 years ago

The app was recently updated to stop duplicates being created however I believe it cannot apply retrospectively to integrations created prior to that update (2020.1). Is the original integration you are seeing a duplicate of more than a couple of months old?

zacwest commented 4 years ago

Re: multiple integrations during delete. If you are doing:

  1. Delete the app
  2. Delete all the mobile_app integrations
  3. Reinstall the app

I would not expect to go from 0 integrations to 2. I could see from 1 to 2 depending on device IDs. This sounds like a bug, so if you're able to confirm 0 to 2 that would be helpful to know.


Re: stable device IDs. The change made in #612 use the Apple-provided identifierForVendor which is the blessed "use this to identify the device" identifier. It is documented as:

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

We could investigate using something like the device name as the identifier for the integration, but it's generally desired to make it more guaranteed-unique than that, because it would restrict having 2 phones named "iPhone" (which is fairly common).

mwunderling commented 4 years ago

Yes, my original integration is quite old <maybe that is still part of the problem??>, but it seems I can still easily replicate the issue.

Here's what I've done since your comments: 1) After having reinstalled the mobile app on my ipad last night, deleted app from the device, downloaded again and resinstalled 2nd time. Note: I did not manually remove the integration from HA before the 2nd reinstall, and after the 2nd install I had 2 integration instances (probably an example of going from 1 to 2 per Zac's comment. 2) Deleted the app from the device again and deleted both integration instances in HA. Pic of my other mobile app integrations after this step: HA mobile app 1 3) Downloaded the app again from itunes, and reinstalled on ipad. Refreshed integrations page in HA. Went from 0 integrations for this device to 2: HA mobile app 2 4) Clicking on each integration shows a different entity count: HA mobile app 3 HA mobile app 4 I think I deactivated some entities in my orig integration so I suspect that it's perhaps getting picked up again.... 5) Deleted both integration instances from HA again, went back to the app on my device and refreshed the page. Went back to HA integration page and this time only had one mobile app instance for the ipad .....but this time had 9 entities?? HA mobile app 5

Here's the history log: HA mobile app Entity Hist

Odd that there are a few mixed-case differences with some of the entity labels...

zacwest commented 4 years ago

I have an idea why this is happening and an idea of how to fix it. Thanks for the detailed timeline and information!