home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.58k stars 29.49k forks source link

Cannot power cycle POE ports of unifi switches #121526

Closed amorfinv closed 1 month ago

amorfinv commented 1 month ago

The problem

Hello,

I am no longer able to power cycle POE ports or use them as a switch in the Unifi Network integration. I keep getting one of the following errors that show up in the GUI:

Failed to call service button/press. Call https://192.168.178.1:443/proxy/network/api/s/default/cmd/devmgr received 401 Unauthorized

Failed to call service button/press. {'meta': {'rc': 'error', 'port': 4, 'msg': 'api.err.InvalidTargetPort'}, 'data': []}

I have tried deleting the integration and restarting the UNIFI controller. I made sure that the user in the integration is a super user so it should have access to the unifi network. Interestingly, I am able to switch of the network connectivity of clients. I just can't access the POE ports of my switches.

I am in unifi network version 8.2.93 and UniFi OS 4.0.6 with a UDR.

What version of Home Assistant Core has the issue?

core-2024.7.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

unifi

Link to integration documentation on our website

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

Diagnostics information

config_entry-unifi-01J2970R7R9629DWM0TFR0KK55.json

Anything in the logs that might be useful for us?

024-07-08 15:14:03.758 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546655262256] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 132, in _async_press_action
    await self.async_press()
  File "/usr/src/homeassistant/homeassistant/components/unifi/button.py", line 141, in async_press
    await self.entity_description.control_fn(self.hub.api, self._obj_id)
  File "/usr/src/homeassistant/homeassistant/components/unifi/button.py", line 60, in async_power_cycle_port_control_fn
    await api.request(DevicePowerCyclePortRequest.create(mac, int(index)))
  File "/usr/local/lib/python3.12/site-packages/aiounifi/controller.py", line 65, in request
    return await self.connectivity.request(api_request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiounifi/interfaces/connectivity.py", line 102, in request
    data = api_request.decode(bytes_data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiounifi/models/api.py", line 52, in decode
    raise ERRORS.get(data["meta"]["msg"], AiounifiException)(data)
aiounifi.errors.AiounifiException: {'meta': {'rc': 'error', 'port': 1, 'msg': 'api.err.InvalidTargetPort'}, 'data': []}
home-assistant[bot] commented 1 month ago

Hey there @kane610, mind taking a look at this issue as it has been labeled with an integration (unifi) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `unifi` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign unifi` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


unifi documentation unifi source (message by IssueLinks)

kernel610 commented 1 month ago

I'm seeing the same issue. It seems to be related all switch entities. I cannot toggle on/off my guest wifi, POE, and individual device connections (kid's tablets). I experienced on 2024.7.1 and then upgraded to 2024.7.2 and I'm still seeing it. I also notice that it starts with the error below, followed by the 401 error. Unifi logs show the HA user accessing successfully and there hasn't been any authentication changes so I'm not sure why it's throwing this error when it seems the integration is talking to my Unifi.

Failed to call service switch/turn_on. Call https://192.168.3.1:443/api/auth/login received 429: b'{"code":"AUTHENTICATION_FAILED_LIMIT_REACHED","message":"You\'ve reached the login attempt limit","level":"debug"}'

Kane610 commented 1 month ago

I have validated that I have the same issue with Power cycle button does not work with the same error

I'm seeing the same issue. It seems to be related all switch entities. I cannot toggle on/off my guest wifi, POE, and individual device connections (kid's tablets). I experienced on 2024.7.1 and then upgraded to 2024.7.2 and I'm still seeing it. I also notice that it starts with the error below, followed by the 401 error. Unifi logs show the HA user accessing successfully and there hasn't been any authentication changes so I'm not sure why it's throwing this error when it seems the integration is talking to my Unifi.

Failed to call service switch/turn_on. Call https://192.168.3.1:443/api/auth/login received 429: b'{"code":"AUTHENTICATION_FAILED_LIMIT_REACHED","message":"You\'ve reached the login attempt limit","level":"debug"}'

All other switch functions seem to work for me, seem you have some login issue which would be a different thing @kernel610

jidknoll commented 1 month ago

I am also experiencing the same issue as @kernel610. Same 429 error at first attempt to toggle individual device connections, and then 401 errors on subsequent attempts. Per the logs in HA the errors started immediately following the 4.0.6 update.

I should add, I've tried creating a new local account for HA in Unifi and removing/re-adding the integration in HA.

Kane610 commented 1 month ago

Looking at UniFi and testing things it seems that trying to do Power cycle on a device without a PoE connected device will generate this error aiounifi.errors.AiounifiException: {'meta': {'rc': 'error', 'port': 1, 'msg': 'api.err.InvalidTargetPort'}

Can you validate this?