core icon indicating copy to clipboard operation
core copied to clipboard

failled to setup integration Unifi Protect

Open PoVPoV29 opened this issue 1 year ago • 2 comments

The problem

Unable to start to Unifi Protect intégration after the upgrade to 2024.10.0

What version of Home Assistant Core has the issue?

core-2024.10.0

What was the last working version of Home Assistant Core?

core-2024.9.3

What type of installation are you running?

Home Assistant OS

Integration causing the issue

unifiprotect

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Error setting up entry UDMP for unifiprotect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/unifiprotect/__init__.py", line 75, in async_setup_entry
    await protect.update()
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 826, in update
    bootstrap = await self.get_bootstrap()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 1176, in get_bootstrap
    data = await self.api_request_obj("bootstrap")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 476, in api_request_obj
    data = await self.api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 450, in api_request
    data = await self.api_request_raw(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 392, in api_request_raw
    response = await self.request(
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 328, in request
    await self.ensure_authenticated()
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 512, in ensure_authenticated
    await self._load_session()
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 601, in _load_session
    session_cookie = await self._read_auth_config()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 610, in _read_auth_config
    async with aiofiles.open(self.config_file, "rb") as f:
               ^^^^^^^^^^^^^
AttributeError: module 'aiofiles' has no attribute 'open'

Additional information

No response

PoVPoV29 avatar Oct 04 '24 07:10 PoVPoV29

Logger: homeassistant.config_entries
Source: config_entries.py:399
First occurred: October 12, 2024 at 12:14:23 AM (4 occurrences)
Last logged: 6:18:35 AM

Error setting up entry UCK G2 Plus for unifiprotect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 399, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/unifiprotect/__init__.py", line 105, in async_setup_entry
    await _async_setup_entry(hass, entry, data_service)
  File "/usr/src/homeassistant/homeassistant/components/unifiprotect/__init__.py", line 137, in _async_setup_entry
    await data_service.async_setup()
  File "/usr/src/homeassistant/homeassistant/components/unifiprotect/data.py", line 114, in async_setup
    await self.async_refresh()
  File "/usr/src/homeassistant/homeassistant/components/unifiprotect/data.py", line 134, in async_refresh
    updates = await self.api.update(force=force)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/api.py", line 600, in update
    self._bootstrap = await self.get_bootstrap()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/api.py", line 776, in get_bootstrap
    return Bootstrap.from_unifi_dict(**data, api=self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/base.py", line 124, in from_unifi_dict
    data = cls.unifi_dict_to_dict(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/bootstrap.py", line 202, in unifi_dict_to_dict
    return super().unifi_dict_to_dict(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/base.py", line 356, in unifi_dict_to_dict
    data[key] = cls._clean_protect_obj_dict(data[key], unifi_dicts[key], api)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/base.py", line 302, in _clean_protect_obj_dict
    items[key] = cls._clean_protect_obj(value, klass, api)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/base.py", line 286, in _clean_protect_obj
    return klass.unifi_dict_to_dict(data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/user.py", line 70, in unifi_dict_to_dict
    return super().unifi_dict_to_dict(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/base.py", line 351, in unifi_dict_to_dict
    data[key] = cls._clean_protect_obj_list(data[key], unifi_lists[key], api)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/base.py", line 294, in _clean_protect_obj_list
    items[index] = cls._clean_protect_obj(item, klass, api)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/base.py", line 286, in _clean_protect_obj
    return klass.unifi_dict_to_dict(data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/user.py", line 34, in unifi_dict_to_dict
    data["nodes"] = [PermissionNode(n) for n in parts[1].split(",")]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/user.py", line 34, in <listcomp>
    data["nodes"] = [PermissionNode(n) for n in parts[1].split(",")]
                     ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/enum.py", line 712, in __call__
    return cls.__new__(cls, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/enum.py", line 1128, in __new__
    raise ve_exc
ValueError: 'readlive' is not a valid PermissionNode

Same but different problem for me

LVLAaron avatar Oct 14 '24 10:10 LVLAaron

I have something similar starting with 2024.10.0 and seems to continue in 2024.11.1:

Logger: homeassistant.config_entries
Source: config_entries.py:635
First occurred: 12:18:36 PM (2 occurrences)
Last logged: 12:23:48 PM

Error setting up entry Dream Machine Professional for unifiprotect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 635, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/unifiprotect/__init__.py", line 75, in async_setup_entry
    await protect.update()
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 827, in update
    bootstrap = await self.get_bootstrap()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 1177, in get_bootstrap
    data = await self.api_request_obj("bootstrap")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 477, in api_request_obj
    data = await self.api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 451, in api_request
    data = await self.api_request_raw(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 393, in api_request_raw
    response = await self.request(
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 329, in request
    await self.ensure_authenticated()
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 515, in ensure_authenticated
    await self.authenticate()
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 538, in authenticate
    response = await self.request("post", url=url, json=auth)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 350, in request
    await self._update_last_token_cookie(response)
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 554, in _update_last_token_cookie
    await self._update_last_token_cookie(response)
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 562, in _update_last_token_cookie
    await self._update_auth_config(self._last_token_cookie)
  File "/usr/local/lib/python3.12/site-packages/uiprotect/api.py", line 570, in _update_auth_config
    await aos.makedirs(self.config_dir, exist_ok=True)
          ^^^^^^^^^^^^
AttributeError: module 'aiofiles.os' has no attribute 'makedirs'

brthrsam avatar Nov 12 '24 11:11 brthrsam

I'm having the same problem, here is log file from most recent attempt to setup: home-assistant_unifiprotect_2024-11-19T20-40-22.918Z.log

jeremyroberts0 avatar Nov 19 '24 20:11 jeremyroberts0

@PoVPoV29 @brthrsam @jeremyroberts0 Errors like AttributeError: module 'aiofiles.os' has no attribute 'makedirs' are usually related to dependency issues where the installed version of a library is incompatible or outdated. (I'm new to the Python world and am drawing on my experience from the Java world, but the concept should be analogous.)

Interestingly, I also came across the following issue: GitHub - Home Assistant Core Issue #118004. If I had to guess, it might be related to some HACS plugin that is no longer maintained.

RaHehl avatar Nov 22 '24 19:11 RaHehl

File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/user.py", line 34, in data["nodes"] = [PermissionNode(n) for n in parts[1].split(",")] ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/enum.py", line 712, in call return cls.new(cls, value) ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/enum.py", line 1128, in new raise ve_exc ValueError: 'readlive' is not a valid PermissionNode


Same but different problem for me

@LVLAaron Looking at the stack trace, it seems like you're running an outdated Home Assistant installation that still relies on the old Protect library. However, your Protect app appears to be using the new readlive permission, which leads to an API incompatibility.

Updating Home Assistant to the latest version should resolve this issue.

RaHehl avatar Nov 22 '24 20:11 RaHehl

File "/usr/local/lib/python3.11/site-packages/pyunifiprotect/data/user.py", line 34, in data["nodes"] = [PermissionNode(n) for n in parts[1].split(",")] ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/enum.py", line 712, in call return cls.new(cls, value) ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/enum.py", line 1128, in new raise ve_exc ValueError: 'readlive' is not a valid PermissionNode


Same but different problem for me

@LVLAaron Looking at the stack trace, it seems like you're running an outdated Home Assistant installation that still relies on the old Protect library. However, your Protect app appears to be using the new readlive permission, which leads to an API incompatibility.

Updating Home Assistant to the latest version should resolve this issue.

Wow.. yeah I do. I was trying to do something else and getting errors about not being able to reach the internet... I had to jiggle the IP address back and forth, reboot, and then I magically had lots of updates to do.

Everything seems to be working now!

LVLAaron avatar Nov 23 '24 19:11 LVLAaron

Probably need to add a constraint for a minimum aiofiles version to prevent custom integrations from downgrading it to a non-working older version.

bdraco avatar Nov 24 '24 19:11 bdraco