Tuya 3.3 version support
Jalleronline opened this issue · 9 comments
Hello, first of all thank you for your work.
I am having problems into getting the payload and decrypting it in the new 3.3 protocol version.
This problem was reported and discussed in this topic of tuyapi:
codetheweb/tuyapi#175
Have you got plans for update your python library in order to be compatible with the new 3.3 version?
Regards.
I got 3.3 working in my fork and it's now been integrated back. Give it a try and let me know if it doesn't work. I based it on the tuyaapi node.js code and tried to get it to fit into the existing framework.
Once you have a device you can call .set_version(3.3) to use the newer protocol. (There will be a constant once the next pull request is integrated).
I confirm, it works now.
Same here, works like a charm.
Thank you very much.
I can't seem to get 3.3 to work with the most recent version. After entering data = d.status() as per the example, I get the following. Any idea how to fix? Thanks.
Unexpected status() payload=b'3.3\x00\x00\x00\x00\x00\nw\xbf\x00\x00\x00\x01\xd2\x97Q1X\xd5[\xeb\xb6
\xa5k\x04{\xe6\xfe\x1e\x10\xb4\x0e\x0c<\xbd*G\x05\x9c[;\xe0\x12\x98\xa4]\x02\xd4\x14/\x87\xe4g\x1c\x
1e\xfc\xee\x87|\x9e\x9d9\x94A\xa3\x0c\x9c\x03\x94\xf4\xc3\xfe\xc9\xed\x18N\xaa\xd6Ac\xf3\x9a\x13u\xc
5"\x98MW\xe8\xd4\xb0\x1f'
Can you pastbin the code?
Sorry, what code?
Whatever code you're using that calls pytuya. For version 3.3 you need to call d.set_version(3.3) before calling .status() for example.
Ah - I was just using the sample code on the front page of this git, which I guess hasn't been updated to note that yet. Did that and it works fine on one of my Tuya plugs thanks. On the other I'm getting this error after checking d.status():
Traceback (most recent call last):
File "", line 1, in
File "C:\Python37\lib\site-packages\pytuya-7.0.4-py3.7.egg\pytuya_init_.py", line 307, in statu
s
result = cipher.decrypt(result, False)
File "C:\Python37\lib\site-packages\pytuya-7.0.4-py3.7.egg\pytuya_init_.py", line 94, in decryp
t
plain_text += cipher.feed() # flush final block
File "C:\Python37\lib\site-packages\pyaes\blockfeeder.py", line 169, in feed
result = self._final(self._buffer, self._padding)
File "C:\Python37\lib\site-packages\pyaes\blockfeeder.py", line 77, in _block_final_decrypt
return strip_PKCS7_padding(self.decrypt(data))
File "C:\Python37\lib\site-packages\pyaes\util.py", line 58, in strip_PKCS7_padding
raise ValueError("invalid padding byte")
ValueError: invalid padding byte
I also have problems to get status on 3.3 devices. You can see it does recognise the devices as 3.3, because the code fails in the 3.3 section, so the set_version must be ok. (I believe my devices are using 3.3. When I set the version to 3.2, it stops working completely. Here, the switches successfully turn on and off. )
The code traceback as follows
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 249, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 419, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/local_tuya/switch.py", line 158, in update
status = self._device.status()
File "/config/custom_components/local_tuya/switch.py", line 116, in status
self._cached_status = self.__get_status()
File "/config/custom_components/local_tuya/switch.py", line 94, in __get_status
status = self._device.status()
File "/config/custom_components/local_tuya/pytuya/init.py", line 311, in status
result = cipher.decrypt(result, False)
File "/config/custom_components/local_tuya/pytuya/init.py", line 87, in decrypt
raw = cipher.decrypt(enc)
File "/usr/local/lib/python3.7/site-packages/Crypto/Cipher/_mode_ecb.py", line 195, in decrypt
raise ValueError("Data must be aligned to block boundary in ECB mode")
ValueError: Data must be aligned to block boundary in ECB mode