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

"Auto" IP address detection does not work when localtuya is installed #408

Open
make-all opened this issue Feb 14, 2023 · 2 comments
Open
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@make-all
Copy link
Owner

Describe the bug
When IP address is set to "Auto", tinytuya uses device discovery in the background to find the IP address. If localtuya is installed, it already has the ports required for Tuya discovery open, so trying to open them fails.

To Reproduce

  1. install localtuya
  2. add a new Tuya Local device with IP address set to "Auto"

Expected behavior
Users expect things to just work, even though there is a technical explanation for this.

Additional context

The below exception is now caught in main, but the core problem remains (just is more gracefully handled now).

Logger: aiohttp.server
Source: custom_components/tuya_local/device.py:69
Integration: Tuya Local (documentation, issues)
First occurred: 11:12:52 (1 occurrences)
Last logged: 11:12:52

Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
resp = await request_handler(request)
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 145, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
return await super().post(request, flow_id)
File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
result = await method(view, request, data, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
result = await self._flow_mgr.async_configure(flow_id, data)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 253, in async_configure
result = await self._async_handle_step(
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step
result: FlowResult = await getattr(flow, method)(user_input)
File "/config/custom_components/tuya_local/config_flow.py", line 41, in async_step_user
self.device = await async_test_connection(user_input, self.hass)
File "/config/custom_components/tuya_local/config_flow.py", line 175, in async_test_connection
device = TuyaLocalDevice(
File "/config/custom_components/tuya_local/device.py", line 69, in init
self._api = tinytuya.Device(dev_id, address, local_key)
File "/usr/local/lib/python3.10/site-packages/tinytuya/core.py", line 732, in init
raise Exception("Unable to find device on network (specify IP address)")
Exception: Unable to find device on network (specify IP address)
@make-all make-all added the bug Something isn't working label Feb 14, 2023
@Oglaf
Copy link
Contributor

Oglaf commented Feb 14, 2023

Do not use localtuya and tuya_local together, both will use discovery every few seconds and some devices do not handle multiple communication in quick succession very well.

For 3.3 devices, both discoveries may cause "Unable to find device on network (specify IP address)", "Access denied", "Address in use". "Access denied" was only fixed after resetting every Tuya device I own to fix this problem.

I don't own any 3.4 device but 3.5 devices run without problems.

Edit: This could also be reproduced by using localtuya and tinytuya in debug mode, as well as using localtuya and pinging the device.

@make-all make-all added the wontfix This will not be worked on label Jul 29, 2023
@make-all
Copy link
Owner Author

Added wontfix label, as this is a technical limitation that can only be fixed by architectural change in Home Assistant to allow integrations to share a common broadcast port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
Status: 🏗 Stalled
Development

No branches or pull requests

2 participants