Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Exception: Invalid authentication data' when running a service on multiple entities #488

Closed
fcastilloec opened this issue Dec 20, 2023 · 4 comments

Comments

@fcastilloec
Copy link

fcastilloec commented Dec 20, 2023

Description

First, this might be related to #478 but the error message there is different than mine, and my case can be reproduced reliably. Also, I've never experienced this error with other integrations, so I'm inclined to think it's Tapo's fault more than Home Assistant.

Reproduction Steps

Run a service/script that selects an option from various entities, it has to be 3+ entities to reproduce the error.

service: select.select_option
target:
  entity_id:
    - select.camera_person_detection
    - select.camera_motion_detection
    - select.camera_pet_detection
    - select.camera_meow_detection
    - select.camera_glass_break_detection
data:
  option: normal

Expected behavior

I'm expecting to have those entities set to the particular option, in the case of the above code normal, or any of the other options: off, low, high, etc

If applicable, add error logs.

2023-12-20 13:05:03.839 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281472260724544] Error handling message: Unknown error (unknown_error) Felipe from 192.168.1.2 (Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
await func(hass, connection, msg)
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 782, in handle_execute_script
script_result = await script_obj.async_run(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2067, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2104, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service
return await service.entity_service_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 903, in entity_service_call
raise result from None
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1233, in async_request_call
return await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/select/init.py", line 106, in async_select_option
await entity.async_select_option(option)
File "/config/custom_components/tapo_control/select.py", line 701, in async_select_option
result = await self.hass.async_add_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pytapo/init.py", line 1358, in setMeowDetection
return self.executeFunction("setMeowDetectionConfig", data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pytapo/init.py", line 491, in executeFunction
data = self.performRequest(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pytapo/init.py", line 616, in performRequest
self.refreshStok()
File "/usr/local/lib/python3.11/site-packages/pytapo/init.py", line 423, in refreshStok
raise Exception("Invalid authentication data")
Exception: Invalid authentication data

Device Firmware

Tapo C120: 1.1.7 Build 231107 Rel.71524n

Integration Version

5.4.12

Using stream component

Yes

Does camera work via official integrations?

Yes

Camera has all attributes filled out in developer tools

Yes

HASS Environment

Debian supervised

Search for similar issues

Yes

Additional information

Toggling the entities on the GUI doesn't show any errors. That might be because it has to be done one at a time. I also tried multiple combinations of entities, thinking a particular one might cause the problem, but the error was shown no matter which entities I selected, or which option I picked, as long as it was 3 or more entities.

@JurajNyiri
Copy link
Owner

New firmwares expect messages in sequential order. Sending them in parallel can lead to 401 code from camera which can be seen here.

Solution to this would be fairly complex and require pretty big rewrite. As a workaround, send the automation actions in sequence instead, possibly with delay as well if needed.

@fcastilloec
Copy link
Author

fcastilloec commented Dec 20, 2023

That's my workaround right now, I'm sending actions for two entities at a time. I tested with a delay and without, and without works without any problems.
I think it'll be a good idea to add some description of this issue to the Troubleshooting | FAQ section.
If more people want to simulate the "Away" and "Home" modes from the Tapo app, which just sets some entities to a specific state, by sending parallel actions, will encounter this message too.

Thanks for the quick reply!

@JurajNyiri
Copy link
Owner

Added to FAQ. Thank you!

@Subseedshiva
Copy link

As a workaround, send the automation actions in sequence instead, possibly with delay as well if needed.

Ok. So where do i find this setting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants