Open downriverbob opened 1 year ago
I am having the same issue.
I too have this issue. I'm trying to delete an entry as I used the incorrect DPS (103). I untick the box to remove the entity and this is the response from the logs.
HA 2023.01.1 HASS on Nuc - fully updated
Logger: custom_components.localtuya.config_flow
Source: custom_components/localtuya/config_flow.py:247
Integration: LocalTuya ([documentation](https://github.com/rospogrigio/localtuya/), [issues](https://github.com/rospogrigio/localtuya/issues))
First occurred: 2:44:33 PM (5 occurrences)
Last logged: 2:51:32 PM
Unexpected exception
Traceback (most recent call last):
File "/config/custom_components/localtuya/config_flow.py", line 580, in async_step_configure_device
self.dps_strings = await validate_input(self.hass, user_input)
File "/config/custom_components/localtuya/config_flow.py", line 247, in validate_input
data[CONF_DEVICE_ID],
KeyError: 'device_id'
I have the same issue. Deleting the last entity of a device causes this problem.
`Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/config_flow.py:247 Integration: LocalTuya integration (documentation, issues) First occurred: 21:06:52 (2 occurrences) Last logged: 22:35:05 Unexpected exception
Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 580, in async_step_configure_device self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 247, in validate_input data[CONF_DEVICE_ID], KeyError: 'device_id'`
I had this issue as well until I discovered that I need to go to Integrations, find Local Tuya, click on the devices link, choose the device I want to delete, then in the Device Info box, click on the 3 dots next to Download Diagnostics and select delete. Restart HA after deleting.
I initially was trying to delete by using the Integration Configuration, edit device, then uncheck the box to delete, but that has never worked.
I had this issue as well until I discovered that I need to go to Integrations, find Local Tuya, click on the devices link, choose the device I want to delete, then in the Device Info box, click on the 3 dots next to Download Diagnostics and select delete. Restart HA after deleting.
I initially was trying to delete by using the Integration Configuration, edit device, then uncheck the box to delete, but that has never worked.
Thanks @foxymichelle, that works great. I'm sure I used to be able to delete by unchecking the device, but it doesn't really matter, doing it your way is easier, and more in line with how other integrations work. I hadn't seen that option before
I have a similar problem. But trying to delete the device with the 3 dots doesn't work. It only deletes the entity and throws an error in the logs. But the device stays there. After HAOS restart, the Entity is back as well.
So:
After HAOS restart: 9 devices 9 entities. After "three dots and delete device": 9 devices 8 entities + error in logs (see below). After HAOS restart: 9 devices 9 entities again
Im stuck in this loop =(
What I did to cause this was "wipe and reset" the Tuya socket in the Tuya app, because it was connecting to the WiFi AP 2 floors below instead of the AP right next to it (same SSID and password). I then added it again in the Tuya app (which by the way didn't help, it still connected to the weak signal AP 2 floors below). After that, the plug showed up as a new device in localtuya under "add devices" (it was recognized by the localtuya cloud API function). But the old one remained under "edit devices".
Edit devices dropdown:
List of devices before delete attempt (after HAOS restart):
Before "delete device" via three dots menu:
After delete attempt and thrown log error:
Log error after delete attempt:
Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/localtuya/common.py:308
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 22:29:51 (2 occurrences)
Last logged: 22:29:53
[139902151493664] Error handling message: Unknown error (unknown_error) from 192.168.178.199 (Mozilla/5.0 (Linux; Android 13; Mi MIX 2S Build/TP1A.220905.004; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/109.0.5414.85 Mobile Safari/537.36 Home Assistant/2022.12.0-3026 (Android 13; Mi MIX 2S))
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
await func(hass, connection, msg)
File "/usr/src/homeassistant/homeassistant/components/config/device_registry.py", line 143, in websocket_remove_config_entry_from_device
if not await component.async_remove_config_entry_device(
File "/config/custom_components/localtuya/__init__.py", line 345, in async_remove_config_entry_device
await hass.data[DOMAIN][TUYA_DEVICES][dev_id].close()
File "/config/custom_components/localtuya/common.py", line 308, in close
await self._connect_task
TypeError: '>' not supported between instances of 'str' and 'int'
So the issue is that when the device is reconnected in the Tuya app, the app recalls the original device info you had, so it looks like nothing changed, but it is assigned a new local key. This new local key is what causes the device to "break" in Local Tuya. Next time this happens to one of my devices, my plan is to look up the new local key in my developer account, then see if a simple update of the key fixes it. Updating the key after already having tried other solutions that resulted in the lost entity didn't work, but fixing the key likely also played a role in successfully deleting it. With the wrong local key, HA spits out errors with anything you try to do with it.
So, like I said, you can look up the new local key in your developer account, but the easiest way to get it at this point would be to start setting up the new device in Local Tuya, which automatically finds the local key for you. Copy that, then go back and edit your old, not working device with the new key... then try deleting it. After it's done and gone, add your new device.
I do recall having to fiddle with getting an active, working entity with the new device. I think I had to open the advanced entity setting and enable it (it was automatically disabled), then restart HA, but then it still didn't show up as active. I may have restarted a couple of times as well trying to turn the light on and off to get it to communicate with the device and realize that it can... I don't remember.
Hopefully something here helps you get the job done!
Thanks! I'm getting closer.
I had already added the plug as a new device (Smart Plug 1). And that new device/entity worked ok.
I copied over the localkey from the new device (Smwrt Plug 1) to the old one (Smart Plug 1 (old)), and that made the old one work as well. So now I can control the plug with both Smart Plug 1 and Smart Plug 1 (old) localtuya devices/entities. However, I cannot delete either. Both only delete the entity and throw the error I pasted in the previous post. The devices stay.
I will keep tinkering.
EDIT: The deleting problem seems to be wider than just the smart plug in question. I just tried to delete another device (a light bulb), and that has the same problem. Only deletes the entity, not the device. And throws the same error. And after restart, the entity is back.
So I'm not so sure anymore this problem started when I "wipe and reset" the smart plug. Maybe it was already like that, but I didn't notice because I didn't delete any devices until now.
EDIT2: It seems like it is connected to the smart plug afterall: After a fresh restart, I can delete other devices without errors. But as soon as I try to delete the "Smart Plug 1" or "Smart Plug 1 (old)" , it seems to crash/error and after that other devices also cannot be deleted anymore.
Ik had dit probleem ook totdat ik ontdekte dat ik naar Integraties moet gaan, Lokale Tuya moet zoeken, op de koppeling apparaten moet klikken, het apparaat moet kiezen dat ik wil verwijderen en vervolgens in het vak Apparaatinfo op de 3 puntjes naast Diagnostische gegevens downloaden moet klikken en verwijderen moet selecteren. Start HA opnieuw op na het verwijderen.
Ik probeerde in eerste instantie te verwijderen met behulp van de integratieconfiguratie, bewerk apparaat en schakel vervolgens het selectievakje uit om te verwijderen, maar dat heeft nooit gewerkt.
Top, dat is de goede manier om te verwijderen.
Having the same issue right now. Trying to remove an alarm device, and it just keeps popping back up after restarting HASSIO and/or the LocalTuya integration
Same issue here. I have added a smart socket configured in Cloud API and it was working great until I've decided to edit some values via 'Edit a device' option. Then after reconfiguring, integration removed socket's entity leaving it as a device only. I've tried reverting settings back, but no luck. Then I've tried to remove it to re-add again, and deletion fails exactly the same way:
... await hass.data[DOMAIN][TUYA_DEVICES][dev_id].close() KeyError: 'socket_device_key_here'
I got a similar problem, when I try to delete a device ( 3 dots , delete), only the entity is deleted not the device and the entity comes back on the next reload/restart .... But there is a catch , only unavailable devices are affected not working ones. It seems the delete process checks the device first. So I am stuck with unavailable devices ...
When trying to delete a device following error is received:
`This error originated from a custom integration.
Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/config_flow.py:247 Integration: LocalTuya integration (documentation, issues) First occurred: 6:20:58 pm (3 occurrences) Last logged: 6:22:13 pm
Unexpected exception Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 580, in async_step_configure_device self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 247, in validate_input data[CONF_DEVICE_ID], KeyError: 'device_id' `
Environment
Steps to reproduce
Configuration
configuration.yaml
orconfig_flow
DP dump
Provide Home Assistant taceback/logs
Additional information