rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.91k stars 557 forks source link

Can not remove device #1101

Open Nikitian opened 2 years ago

Nikitian commented 2 years ago

The problem

Have some covers, that correctly working into tuya smart application, but unavailable into localtuya. Tried to remove this devices by uncheck checkbox "Entities (uncheck an entity to remove it)" for re-add and gets error: An unknown error occurred. See log for details. At logs see:

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

  1. "Edit a device" in intergration settings
  2. Select device
  3. Uncheck checkbox "Entities (uncheck an entity to remove it)" and click "confirm"

Configuration configuration.yaml or config_flow

{
"84076817a4e57c10720e": {
        "active_time": 1635529538,
        "biz_type": 0,
        "category": "cl",
        "create_time": 1635529538,
        "icon": "smart/icon/ay1557197822668c8orI/c9f2276f9c8ea183514a374cac3d54b6.png",
        "id": "84076817a4e57c10720e",
        "ip": "5.*.*.214",
        "lat": "60.0089",
        "local_key": "fbb...f55",
        "lon": "30.2775",
        "model": "M515EGWT V2",
        "name": "\u0433\u043e\u0441\u0442\u0438\u043d\u0430\u044f \u0448\u0442\u043e\u0440\u0430 1",
        "online": true,
        "owner_id": "34595471",
        "product_id": "t6ief6k56sapz1ey",
        "product_name": "EGWT V2 ",
        "status": [
          {
            "code": "control",
            "value": "stop"
          },
          {
            "code": "percent_control",
            "value": 100
          },
          {
            "code": "control_back_mode",
            "value": false
          },
          {
            "code": "work_state",
            "value": "opening"
          },
          {
            "code": "fault",
            "value": "0"
          },
          {
            "code": "border",
            "value": "up"
          },
          {
            "code": "position_best",
            "value": 0
          }
        ],
        "sub": false,
        "time_zone": "+03:00",
        "uid": "eu162714894871653wwn",
        "update_time": 1639883647,
        "uuid": "84076817a4e57c10720e"
      },
}

DP dump

$ ./test.py 84076817a4e57c10720e 192.168.0.114 ***
INFO:localtuya:localtuya version 1.0.0
INFO:localtuya:Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
INFO:localtuya:Using pytuya version '8.1.0'
INFO:localtuya:Detecting list of available DPS of device 84076817a4e57c10720e [192.168.0.114], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"84076817a4e57c10720e","devId":"84076817a4e57c10720e"}'
DEBUG:localtuya.pytuya:Failed to connect to 192.168.0.114. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: [Errno 104] Connection reset by peer
INFO:localtuya:Detecting list of available DPS of device 84076817a4e57c10720e [192.168.0.114], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"84076817a4e57c10720e","devId":"84076817a4e57c10720e"}'
DEBUG:localtuya.pytuya:Failed to connect to 192.168.0.114. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: [Errno 104] Connection reset by peer
INFO:localtuya:Detecting list of available DPS of device 84076817a4e57c10720e [192.168.0.114], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"84076817a4e57c10720e","devId":"84076817a4e57c10720e"}'
DEBUG:localtuya.pytuya:Failed to connect to 192.168.0.114. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: [Errno 104] Connection reset by peer
INFO:localtuya:TIMEOUT: No response from device 84076817a4e57c10720e [192.168.0.114] after 2 attempts.

Provide Home Assistant taceback/logs

Эта ошибка возникла в кастомной интеграции.

Logger: custom_components.localtuya.config_flow
Source: custom_components/localtuya/config_flow.py:247 
Integration: LocalTuya integration (documentation, issues) 
First occurred: 21 октября 2022 г., 13:27:56 (7 occurrences) 
Last logged: 14:14:49

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'
8xiom commented 2 years ago

Same phenomenon here with a Tuya led/CCT light entity which I wanted to remove. Log entry with the same error w.r.t. the Local Tuya integration, I have to check the rest of it (traceback etc.), though. Same version of integration (4.1.1), HAOS 2022.10.4, supervisor 2022.10.0 and operating system 9.2

snigehere commented 2 years ago

I found the only way to remove a device was via the settings, integrations and then on the tuya integration click on devices and remove from there.

neuronflow commented 1 year ago

How did you remove it from there?

snigehere commented 1 year ago

How did you remove it from there?

Its a while since I did it (a lot of releases ago) but as far as I recall from the integration click the "xx devices" .. with the list of devices click the device in in question, click on the device control to open the info properties then on the settings tab click advanced options and disable the device and then the "delete" option should be enabled .. if that does not solve it then maybe disabling the integration then doing the same ... hope it helps ... if it does not I don't have a different suggestion other than deleting the integration and starting again (tedious process I know)

yangyeq1n commented 1 year ago

How did you remove it from there?

Its a while since I did it (a lot of releases ago) but as far as I recall from the integration click the "xx devices" .. with the list of devices click the device in in question, click on the device control to open the info properties then on the settings tab click advanced options and disable the device and then the "delete" option should be enabled .. if that does not solve it then maybe disabling the integration then doing the same ... hope it helps ... if it does not I don't have a different suggestion other than deleting the integration and starting again (tedious process I know)

I delete the integration and start again, but some device cannot be added into ha, it shows"An unknown error occurred. See log for details." Btw, I can control those devices by tuya app.

My log: 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 245, in validate_input interface = await pytuya.connect( File "/config/customcomponents/localtuya/pytuya/init.py", line 704, in connect , protocol = await loop.create_connection( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection raise exceptions[0] File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') OSError: [Errno 113] Connect call failed ('192.168.0.145', 6668)

snigehere commented 1 year ago

Is it an "always on" device.. some devices like leak detectors and level sensors only come alive to report a change and then go off line again.. for smartlife it's not an issue but I found them nearly impossible to get working on local.. in the end I decided to not bother.. i did manage to get one on local by keep triggering it but then it kept reporting an error while it was off line.

neuronflow commented 1 year ago

I managed to remove a device by reloading localtuya, then clicking on the device. then the three dots menu with the delete option became visible.

mgrandi commented 1 year ago

happens to me too when i try and remove a cree connected max 60w lightbulb

CrazyCoder commented 1 year ago

Can't remove a device by unchecking the entity:

2022-12-12 10:26:51.012 ERROR (MainThread) [custom_components.localtuya.config_flow] 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'
idorose commented 1 year ago

happens to me too