Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Tuya 3.3 version support #54

Open
Jalleronline opened this issue Jun 18, 2019 · 9 comments
Open

Tuya 3.3 version support #54

Jalleronline opened this issue Jun 18, 2019 · 9 comments

Comments

@Jalleronline
Copy link

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.

@Jalleronline Jalleronline changed the title New tuya 3.3 version Tuya 3.3 version support Jun 18, 2019
@belzedaar
Copy link
Contributor

belzedaar commented Jul 8, 2019

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).

@sunwire
Copy link

sunwire commented Jul 8, 2019

I confirm, it works now.

@Jalleronline
Copy link
Author

Same here, works like a charm.
Thank you very much.

@mobamoba
Copy link

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'

@belzedaar
Copy link
Contributor

Can you pastbin the code?

@mobamoba
Copy link

Sorry, what code?

@belzedaar
Copy link
Contributor

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.

@mobamoba
Copy link

mobamoba commented Jul 15, 2019

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

@cschutte
Copy link

cschutte commented Aug 18, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants