core: UniFi integration failed to setup due to KeyError

The problem

After upgrading from 2023.8 to 2023.9 the UniFi integration fails to setup.

What version of Home Assistant Core has the issue?

2023.9.0

What was the last working version of Home Assistant Core?

2023.8.3

What type of installation are you running?

Home Assistant OS

Integration causing the issue

unifi

Link to integration documentation on our website

https://www.home-assistant.io/integrations/unifi

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/unifi/__init__.py", line 43, in async_setup_entry
    await controller.initialize()
  File "/usr/src/homeassistant/homeassistant/components/unifi/controller.py", line 252, in initialize
    self.is_admin = self.api.sites[self.config_entry.unique_id].role == "admin"
                    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiounifi/interfaces/api_handlers.py", line 165, in __getitem__
    return self._items[obj_id]
           ~~~~~~~~~~~^^^^^^^^
KeyError: '60375bd3ddb88d0148571192'


### Additional information

_No response_

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 39 (13 by maintainers)

Most upvoted comments

I ran into the same issue, and try to resolve it by deleting the integration and configuring it again. Now I can’t even connect though, and all I’m getting is “Failed to connect”. Not much more in the logs. I verified the host of the controller can be pinged from HA, I’ve verified the credentials I’m using, and I can connect the web interface of the controller using the credentials. Any ideas would be very welcome, because I ran out of them 😕

One issue per issue. Try restart your hardware.

I’m not sure how to do these steps. Will it also work if I remove the integration and add it again?

Yes 👍🏻