SmartThings integration never "finishes" with nabucasa

Hi

Downloaded latest images yesterday (hass.io)

Following instructions here (SmartThings - Home Assistant) and using nabucasa as my webhook provider

I get to step 5.4 but after closing the other tab/window, I don’t get the finish button

Just the same window

I did this from chrome browser in incognito mode in case extensions were causing the issue, same behaviour. I did a network capture (in browser debug window) and see that all messages from browser to smart things are successful

I see this error in the logs

Exception in functools.partial(<function smartapp_update at 0x6ad7cf58>, <homeassistant.core.HomeAssistant object at 0x748d3e08>) when dispatching 'smartthings_smartap_UPDATE': (<pysmartapp.update.UpdateRequest object at 0x6ad8cfa0>, <pysmartapp.request.EmptyDataResponse object at 0x6acf8e38>, <pysmartapp.smartapp.SmartApp object at 0x6c7db2f8>) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/smartthings/smartapp.py", line 444, in smartapp_update await _continue_flow( File "/usr/src/homeassistant/homeassistant/components/smartthings/smartapp.py", line 387, in _continue_flow flow = next( File "/usr/src/homeassistant/homeassistant/components/smartthings/smartapp.py", line 391, in <genexpr> if flow["handler"] == DOMAIN and flow["context"]["unique_id"] == unique_id KeyError: 'unique_id'

Is there anything I can do to debug this further?

I had the same problem without nabu casa (my home assistant is directly reachable via HTTPS). I have no idea what the cause is, but I found a workaround. In the file that the error occurs in (/usr/src/homeassistant/homeassistant/components/smartthings/smartapp.py), change line 391 to read:

           if flow["handler"] == DOMAIN and "unique_id" in flow["context"] and flow["context"]["unique_id"] == unique_id

instead of

            if flow["handler"] == DOMAIN and flow["context"]["unique_id"] == unique_id

This code tries to check if an object contains a specific id, but it fails to handle the case that the object has no id at all. My fix adds a check for that - no id is handled the same way as wrong id.

With the fix in place, UI flow continues after granting Home Assistant access in SmartThings, and my Samsung TV appears as a device.

It appears to be caused by other integrations that don’t set a unique ID. I think you can work around this by not leaving any flows incomplete or add the SmartThings integration after a restart before any others.

A PR has been opened to fix this issue.

Edit: Add check for flow objects with missing id in SmartThings setup flow by solarpanzer · Pull Request #38667 · home-assistant/core · GitHub