rospogrigio / localtuya

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

Exception in callback _SelectorDatagramTransport._read_ready() #1588

Open BettySwallocks opened 10 months ago

BettySwallocks commented 10 months ago

My logs are getting filled with errors (every few seconds) like this:

2023-12-15 15:07:45.646 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
data = decrypt_udp(data)
^^^^^^^^^^^^^^^^^
File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 186, in finalize
data = self._ctx.finalize()
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 222, in finalize
raise ValueError(
ValueError: The length of the provided data is not a multiple of the block length.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1163, in _read_ready
self._protocol.datagram_received(data, addr)
File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
data = data.decode()
^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 4: invalid continuation byte

Any ideas folks?

kozfelipe commented 10 months ago

What are the names of your discovered devices? My guess is one of them has invalid characters at the name / attributes

BettySwallocks commented 10 months ago

What are the names of your discovered devices? My guess is one of them has invalid characters at the name / attributes

Standard alphanumeric names - nothing notable, no special characters at all:

image

kozfelipe commented 10 months ago

look up for invalid characters at the configuration attributes too

BettySwallocks commented 10 months ago

There are no odd characters in any attributes or other areas of config that I can find. Mostly there is no complexity in my basic Tuya plug items, just two CT clamp style meters that have more attributes:

type: entities
entities:
  - entity: sensor.ltdm_ac_freq
    name: AC Freq
    secondary_info: last-updated
  - entity: sensor.ltdm_current_a
    name: Hob Current
  - entity: sensor.ltdm_current_b
    name: Ovens Current
  - entity: sensor.ltdm_energy_forward_a
    name: Hob Energy Forward
  - entity: sensor.ltdm_energy_forward_b
    name: Ovens Energy Forward
  - entity: sensor.ltdm_energy_reverse_a
    name: Hob Energy Reverse
  - entity: sensor.ltdm_energy_reverse_b
    name: Ovens Energy Reverse
  - entity: sensor.ltdm_power_a
    name: Hob Power
  - entity: sensor.ltdm_power_b
    name: Ovens Power
  - entity: sensor.ltdm_voltage
    name: Voltage
title: Hob Oven Meter
type: entities
entities:
  - entity: sensor.hp_imm_meter_current_a
    name: Current A
  - entity: sensor.hp_imm_meter_current_b
    name: Current B
  - entity: sensor.hp_imm_meter_power_a
    name: Power A
  - entity: sensor.hp_imm_meter_power_b
    name: Power B
    secondary_info: last-updated
  - entity: sensor.hp_imm_meter_today_energy_a
    name: Today energy A
  - entity: sensor.hp_imm_meter_today_energy_b
    name: Today energy B
  - entity: sensor.hp_imm_meter_total_energy
    name: Total energy
  - entity: sensor.hp_imm_meter_total_energy_a
    name: Total energy A
  - entity: sensor.hp_imm_meter_total_energy_b
    name: Total energy B
  - entity: sensor.hp_imm_meter_voltage_a
    name: Voltage A
  - entity: sensor.hp_imm_meter_voltage_b
    name: Voltage B
title: Heat Pump & Immersion Meter

If you're talking about the Tuya IOT Cloud configs - again I don't see anything in there with odd characters, bar one of the meters which does have come Chinese characters in the "Product name" value, but that's been there for months and months.

My errors seemed to start on 15th December 2023.

kozfelipe commented 10 months ago

not the cloud configs, confirm there is no odd characters at the localtuya config

image

BettySwallocks commented 10 months ago

OK - I may not be looking in exactly the right way here, but here is my dual meter used for hob and oven monitoring:

image

image

Is this the area to check?

BettySwallocks commented 10 months ago

Other than above my other items are single attribute plugs. I have version 3.3 used for my plugs and did use version 3.4 for the dual meter - anything wrong with that?

kozfelipe commented 10 months ago

my guess is that your discovery process is failing to read an invalid datagram from one of your devices according to the logs

BettySwallocks commented 10 months ago

Thanks for all the help.

That one meter is the only complex item in my config, so I'm guessing it's that as each of the other four are just plugs with simple on-off switch. I may remove those plugs as they aren't actually used for anything as they are in normal Tuya integration also.

As for the meter I just didn't want to completely reset that as it's used in my energy statistics in HA. Hoping that it can be wiped and re-installed with the same name and then the stats will be picked back up...

BettySwallocks commented 10 months ago

Interesting, I've taken out all the plugs AND the meter so no devices are linked to the integration. I've waited for 5 minutes and done a reload of the LocalTuya integration also. The error in the logs is still regularly repeating:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/localtuya/discovery.py:67
Integration: LocalTuya integration (documentation, issues)
First occurred: 15 December 2023 at 15:07:45 (74581 occurrences)
Last logged: 22:45:45

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
                                              ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 186, in finalize
    data = self._ctx.finalize()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 222, in finalize
    raise ValueError(
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1163, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 4: invalid continuation byte

Next I'll try wiping LocalTuya from my system and re-installing.

amichaelwagner commented 10 months ago

Having the same problem on my end as well

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/localtuya/discovery.py:67
Integration: LocalTuya (documentation, issues)
First occurred: 9:08:03 AM (350 occurrences)
Last logged: 9:17:44 AM

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
                                              ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 186, in finalize
    data = self._ctx.finalize()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 222, in finalize
    raise ValueError(
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1163, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 0: invalid start byte
BuckinghamIO commented 10 months ago

Same problem here and I have no devices existing currently so this is failing at the discovery phase.

mad-tunes commented 10 months ago

Same here, I think. Swear I searched but didnt find this issue to begin with, logged in a new issue, then found this one.

Environment

Localtuya version: 5.2.1
Home Assistant Core version: 2024.1.2
Are you using the Tuya/SmartLife App in parallel ?

Steps to reproduce

Download LocalTuya through HACS
Restart HA
Settings>Devices & Services>Add Integration>Local Tuya
On Cloud API account configuration screen, change nothing apart from ticking 'Do not configure a Cloud API account', Submit

Feels like I must be missing something basic somewhere? Provide Home Assistant traceback/logs

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/localtuya/discovery.py:67
Integration: LocalTuya integration (documentation, issues)
First occurred: 21:40:48 (3 occurrences)
Last logged: 21:40:51

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
                                              ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 186, in finalize
    data = self._ctx.finalize()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 222, in finalize
    raise ValueError(
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1163, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 5: invalid start byte

Additional information

No devices, no API account set up, similar messages all over HAs logs I was going to remove https://github.com/rospogrigio/localtuya/issues/1618 after finding this issue, but tbh I cant see how to. If this issue's the right place for it, pls do remove 1618

MrBamse commented 3 months ago

Same here

GKG-ctrl commented 3 months ago

Same issue here.. any ideas please