Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d.status() not working #16

Closed
TheConfax opened this issue Jan 5, 2021 · 6 comments
Closed

d.status() not working #16

TheConfax opened this issue Jan 5, 2021 · 6 comments

Comments

@TheConfax
Copy link

The outlet is correctly turning on and off, but d.status() is raising a JSONDecodeError

Traceback (most recent call last): File "C:/Users/theco/Desktop/AA.py", line 11, in <module> data= d.status() File "C:\Users\theco\AppData\Local\Programs\Python\Python39\lib\site-packages\tinytuya\__init__.py", line 502, in status result = json.loads(result) File "C:\Users\theco\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) File "C:\Users\theco\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\theco\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Any help on this?

@jasonacox
Copy link
Owner

Can you paste the code you are using (AA.py)? Based on the error trace, it is getting a null response (None).

Also are you seeing the outlet when you do a scan?:

python -m tinytuya scan

@TheConfax
Copy link
Author

TheConfax commented Jan 6, 2021

The code is just a simple test:

import tinytuya
LOC_KEY = "local key string"
DEV_ID = "device id string"
IP_ADDR = "192.168.1.9"

d = tinytuya.OutletDevice(DEV_ID,IP_ADDR,LOC_KEY)
d.set_version(3.3)
d.status()

d.turn_off() // d.turn_on() are working regularly.

This is the result of scan in Windows:
Scan

@jasonacox
Copy link
Owner

Thanks for the tests!

There seems to be some strange behavior with some devices that have a 22 character IDs. I don't know if that is your case. Try adding device22 to the initialization for dev_type:

a = tinytuya.OutletDevice('here_is_my_key', '192.168.1.9', 'secret_key_here', 'device22')
a.set_version(3.3)
data =  a.status()
print(data)

Also, in case it helps, I see you are using a Windows command window instead of a powershell terminal. Tinytuya sends terminal color codes that don't show up in command windows, but you can disable color codes:

python -m tinytuya scan -nocolor      

If you can, I would also recommend pulling the local key again and let tinytuya run a scan on the device as well:

python -m tinytuya wizard -nocolor      

Finally, if none of that helps, make sure there isn't a firmware update for the device (I have seem some odd tuya behavior on early 3.3 devices).

@TheConfax
Copy link
Author

TheConfax commented Jan 6, 2021

The wizard produced the same local key as before, but my device has indeed a 22 character id. By using "device22" the error changed into this:

Traceback (most recent call last):
  File "C:\Users\theco\Desktop\SS Off.pyw", line 10, in <module>
    data =  d.status()
  File "C:\Users\theco\AppData\Local\Programs\Python\Python39\lib\site-packages\tinytuya\__init__.py", line 467, in status
    payload = self.generate_payload(DP_QUERY)
  File "C:\Users\theco\AppData\Local\Programs\Python\Python39\lib\site-packages\tinytuya\__init__.py", line 410, in generate_payload
    json_data['dps'] = self.dpsUsed
AttributeError: 'OutletDevice' object has no attribute 'dpsUsed'

I don't know if could be useful to you, but by using the tuyapy module I am able to retrieve the on/off status correctly (that module is using the cloud based approach though).

@jasonacox
Copy link
Owner

jasonacox commented Jan 7, 2021

Ah! That's encouraging result. I left out a line, try this (notice set_dpsUsed):

a = tinytuya.OutletDevice('here_is_my_key', '192.168.1.9', 'secret_key_here', 'device22')
a.set_version(3.3)
a.set_dpsUsed({"1": None})
data =  a.status()
print(data)

I need to add code to the library to automatically try device22 specifics for those edge-case devices. It's on my list. ;)

@TheConfax
Copy link
Author

Solved! 🎉🎉
Thank you for your help Jason, I'm really a beginner at Python but maybe you could add remarks to 22 characters id and dps & 22 edits to the main guide, that could have been useful!

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

No branches or pull requests

3 participants
@jasonacox @TheConfax and others