imhotep / hass-unifi-access

Unifi Access Integration for Home Assistant
Apache License 2.0
62 stars 16 forks source link

Unifi UA-Ultra - Keep it unlocked/unlock & reset not working #77

Open EmilionDK opened 1 week ago

EmilionDK commented 1 week ago

Describe the bug

First I would like to say thank you for this work you have done, It's super cool that there are so many people who are dictated to make things work for the Home assistant.

As such I don't think it's a bug, but more that it is not finished for Unifi UA-Ultra? but the Keep it unlocked/unlock & reset and custom set.Iis not working.

Home assistant gives this error message: Failed to perform the action select/select_option. 'data'

Is there anything I can do to help make it work?

Which Hub are you using

Unifi UA-Ultra

Versions:

Home Assistant DEBUG logs (MANDATORY)

2024-09-22 21:50:55.651 INFO (SyncWorker_36) [custom_components.unifi_access.hub] Setting door lock rule for Door ID 07ddb690-0b0d-4796-9ba3-4c2aaaf84414 {'type': 'keep_lock'} 2024-09-22 21:50:55.651 DEBUG (SyncWorker_36) [custom_components.unifi_access.hub] Making HTTP PUT Request with URL https://192.168.1.1:12445/api/v1/developer/doors/07ddb690-0b0d-4796-9ba3-4c2aaaf84414/lock_rule and data {'type': 'keep_lock'} 2024-09-22 21:50:55.711 DEBUG (SyncWorker_36) [custom_components.unifi_access.hub] HTTP Response {'code': 'CODE_SYSTEM_ERROR', 'msg': "An error occurred on the server's end."} 2024-09-22 21:50:55.712 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140544372489760] Unexpected exception Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/select/init.py", line 188, in async_handle_select_option await self.async_select_option(option) File "/config/custom_components/unifi_access/select.py", line 89, in async_select_option await self.hass.async_add_executor_job(self.door.set_lock_rule, option) File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/unifi_access/door.py", line 93, in set_lock_rule self._hub.set_door_lock_rule(self._id, new_door_lock_rule) File "/config/custom_components/unifi_access/hub.py", line 210, in set_door_lock_rule self._make_http_request( File "/config/custom_components/unifi_access/hub.py", line 269, in _make_http_request return response["data"]


KeyError: 'data'

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2024-09-22 21:50:58.774 INFO (SyncWorker_61) [custom_components.unifi_access.hub] Setting door lock rule for Door ID 07ddb690-0b0d-4796-9ba3-4c2aaaf84414 {'type': 'keep_unlock'}
2024-09-22 21:50:58.774 DEBUG (SyncWorker_61) [custom_components.unifi_access.hub] Making HTTP PUT Request with URL https://192.168.1.1:12445/api/v1/developer/doors/07ddb690-0b0d-4796-9ba3-4c2aaaf84414/lock_rule and data {'type': 'keep_unlock'}
2024-09-22 21:50:58.848 DEBUG (SyncWorker_61) [custom_components.unifi_access.hub] HTTP Response {'code': 'CODE_SYSTEM_ERROR', 'msg': "An error occurred on the server's end."}
2024-09-22 21:50:58.850 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140544372489760] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 188, in async_handle_select_option
    await self.async_select_option(option)
  File "/config/custom_components/unifi_access/select.py", line 89, in async_select_option
    await self.hass.async_add_executor_job(self.door.set_lock_rule, option)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/unifi_access/door.py", line 93, in set_lock_rule
    self._hub.set_door_lock_rule(self._id, new_door_lock_rule)
  File "/config/custom_components/unifi_access/hub.py", line 210, in set_door_lock_rule
    self._make_http_request(
  File "/config/custom_components/unifi_access/hub.py", line 269, in _make_http_request
    return response["data"]
           ~~~~~~~~^^^^^^^^
KeyError: 'data'

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2024-09-22 21:51:02.003 INFO (SyncWorker_14) [custom_components.unifi_access.hub] Setting door lock rule for Door ID 07ddb690-0b0d-4796-9ba3-4c2aaaf84414 {'type': 'reset'}
2024-09-22 21:51:02.003 DEBUG (SyncWorker_14) [custom_components.unifi_access.hub] Making HTTP PUT Request with URL https://192.168.1.1:12445/api/v1/developer/doors/07ddb690-0b0d-4796-9ba3-4c2aaaf84414/lock_rule and data {'type': 'reset'}
2024-09-22 21:51:02.067 DEBUG (SyncWorker_14) [custom_components.unifi_access.hub] HTTP Response {'code': 'CODE_SYSTEM_ERROR', 'msg': "An error occurred on the server's end."}
2024-09-22 21:51:02.069 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140544372489760] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 188, in async_handle_select_option
    await self.async_select_option(option)
  File "/config/custom_components/unifi_access/select.py", line 89, in async_select_option
    await self.hass.async_add_executor_job(self.door.set_lock_rule, option)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/unifi_access/door.py", line 93, in set_lock_rule
    self._hub.set_door_lock_rule(self._id, new_door_lock_rule)
  File "/config/custom_components/unifi_access/hub.py", line 210, in set_door_lock_rule
    self._make_http_request(
  File "/config/custom_components/unifi_access/hub.py", line 269, in _make_http_request
    return response["data"]
           ~~~~~~~~^^^^^^^^
KeyError: 'data'
imhotep commented 1 week ago

As such I don't think it's a bug, but more that it is not finished for Unifi UA-Ultra?

Oh it is 100% a bug :)

Can you set door locking rules through your Unifi Access mobile app or web UI? If not, it is possible that the UA-Ultra does not support Door Locking rules and the integration needs to remove access to this feature (same way we do for UGT and UAH-Ent).

The truth is that there are too many UA hubs and I only own the Unifi Access Hub (OG) so short of community support, people that own hubs that want to contribute to this integration, I will have hard time supporting all of them, sadly.

Johnnybyzhang commented 4 days ago

I have a UA-Ultra and am happy to help. Do let me know if there's anything I can do to bring support for UA-Ultra.

imhotep commented 4 days ago

@Johnnybyzhang could you answer the question above?

Johnnybyzhang commented 3 days ago

@Johnnybyzhang could you answer the question above?

I don’t think I am able to find a relevant setting in my application, attached is a screenshot of the settings page of UA-Ultra Picsew_20241002190909

Johnnybyzhang commented 3 days ago

Additionally I can confirm that I am able to use this integration alongside UID (license-free version)

imhotep commented 3 days ago

Can you tap/click on unlock schedule at the bottom and tell me what you see? Also are you seeing the same errors above when setting door locking rules?

Johnnybyzhang commented 3 days ago

Here’s the unlock schedule IMG_3724 I currently don’t have access to my instance, will add that later when I’m back at home.

imhotep commented 2 days ago

@Johnnybyzhang are you seeing the errors listed in the issue when using door locking rules in the integration?

Johnnybyzhang commented 11 hours ago

I'm sorry for the delay in getting back to you, I was moving to a new site and spent 2 days installing home assistant on the UDM Pro directly. Here's the debug log: (TL;DR, there does seems to be the same error)

Keep lock

`2024-10-06 03:34:24.235 INFO (SyncWorker_8) [custom_components.unifi_access.hub] Setting door lock rule for Door ID eb3ebf20-fc46-4cbe-ab50-ed5289b916ad {'type': 'keep_lock'} 2024-10-06 03:34:24.235 DEBUG (SyncWorker_8) [custom_components.unifi_access.hub] Making HTTP PUT Request with URL https://192.168.11.100:12445/api/v1/developer/doors/eb3ebf20-fc46-4cbe-ab50-ed5289b916ad/lock_rule and data {'type': 'keep_lock'} 2024-10-06 03:34:24.393 DEBUG (SyncWorker_8) [custom_components.unifi_access.hub] HTTP Response {'code': 'CODE_SYSTEM_ERROR', 'msg': 'An error occurred on the server.'} 2024-10-06 03:34:24.394 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546545809824] Unexpected exception Traceback (most recent call last): File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2761, in async_call response_data = await coro ^^^^^^^^^^ File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2804, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 996, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 1068, in _handle_entity_call result = await task ^^^^^^^^^^ File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/select/init.py", line 188, in async_handle_select_option await self.async_select_option(option) File "/home/homeassistant/.homeassistant/custom_components/unifi_access/select.py", line 89, in async_select_option await self.hass.async_add_executor_job(self.door.set_lock_rule, option) File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/homeassistant/.homeassistant/custom_components/unifi_access/door.py", line 93, in set_lock_rule self._hub.set_door_lock_rule(self._id, new_door_lock_rule) File "/home/homeassistant/.homeassistant/custom_components/unifi_access/hub.py", line 210, in set_door_lock_rule self._make_http_request( File "/home/homeassistant/.homeassistant/custom_components/unifi_access/hub.py", line 269, in _make_http_request return response["data"]


KeyError: 'data'`
### Keep unlocked
`2024-10-06 03:37:40.666 INFO (SyncWorker_2) [custom_components.unifi_access.hub] Setting door lock rule for Door ID eb3ebf20-fc46-4cbe-ab50-ed5289b916ad {'type': 'keep_unlock'}
2024-10-06 03:37:40.666 DEBUG (SyncWorker_2) [custom_components.unifi_access.hub] Making HTTP PUT Request with URL https://192.168.11.100:12445/api/v1/developer/doors/eb3ebf20-fc46-4cbe-ab50-ed5289b916ad/lock_rule and data {'type': 'keep_unlock'}
2024-10-06 03:37:40.812 DEBUG (SyncWorker_2) [custom_components.unifi_access.hub] HTTP Response {'code': 'CODE_SYSTEM_ERROR', 'msg': 'An error occurred on the server.'}
2024-10-06 03:37:40.813 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546545809824] Unexpected exception
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/select/__init__.py", line 188, in async_handle_select_option
    await self.async_select_option(option)
  File "/home/homeassistant/.homeassistant/custom_components/unifi_access/select.py", line 89, in async_select_option
    await self.hass.async_add_executor_job(self.door.set_lock_rule, option)
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/unifi_access/door.py", line 93, in set_lock_rule
    self._hub.set_door_lock_rule(self._id, new_door_lock_rule)
  File "/home/homeassistant/.homeassistant/custom_components/unifi_access/hub.py", line 210, in set_door_lock_rule
    self._make_http_request(
  File "/home/homeassistant/.homeassistant/custom_components/unifi_access/hub.py", line 269, in _make_http_request
    return response["data"]
           ~~~~~~~~^^^^^^^^
KeyError: 'data'`
### Custom
`2024-10-06 03:38:25.983 INFO (SyncWorker_12) [custom_components.unifi_access.hub] Setting door lock rule for Door ID eb3ebf20-fc46-4cbe-ab50-ed5289b916ad {'type': 'custom', 'interval': 10}
2024-10-06 03:38:25.983 DEBUG (SyncWorker_12) [custom_components.unifi_access.hub] Making HTTP PUT Request with URL https://192.168.11.100:12445/api/v1/developer/doors/eb3ebf20-fc46-4cbe-ab50-ed5289b916ad/lock_rule and data {'type': 'custom', 'interval': 10}
2024-10-06 03:38:26.127 DEBUG (SyncWorker_12) [custom_components.unifi_access.hub] HTTP Response {'code': 'CODE_SYSTEM_ERROR', 'msg': 'An error occurred on the server.'}
2024-10-06 03:38:26.127 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546545809824] Unexpected exception
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/select/__init__.py", line 188, in async_handle_select_option
    await self.async_select_option(option)
  File "/home/homeassistant/.homeassistant/custom_components/unifi_access/select.py", line 89, in async_select_option
    await self.hass.async_add_executor_job(self.door.set_lock_rule, option)
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/unifi_access/door.py", line 93, in set_lock_rule
    self._hub.set_door_lock_rule(self._id, new_door_lock_rule)
  File "/home/homeassistant/.homeassistant/custom_components/unifi_access/hub.py", line 210, in set_door_lock_rule
    self._make_http_request(
  File "/home/homeassistant/.homeassistant/custom_components/unifi_access/hub.py", line 269, in _make_http_request
    return response["data"]
           ~~~~~~~~^^^^^^^^
KeyError: 'data'`

EDIT: include the log file as an attachment
[home-assistant_unifi_access_2024-10-05T19-41-55.570Z.log](https://github.com/user-attachments/files/17267296/home-assistant_unifi_access_2024-10-05T19-41-55.570Z.log)
Johnnybyzhang commented 11 hours ago

Additionally, there is no doorbell on the UA-Ultra, so this entity should also be removed following the same logic.