jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
923 stars 165 forks source link

Thermostat Setpoints Failing #325

Closed elockman closed 1 year ago

elockman commented 1 year ago

I am having trouble with local thermostat calls again.

This is my test code with DeviceID and LocalKey redacted:

from tinytuya import Contrib
import time

tstatdev = Contrib.ThermostatDevice( '{DEVICE_ID}', '192.168.1.106', '{LOCAL_KEY}' )

tstatdev.setUnits( 'f' )

#test 1 works
#tstatdev.setMiddleSetpoint( 72, 'f' )

#test 2 fails (TypeError: setMiddleSetpoint() takes from 2 to 3 positional arguments but 4 were given)
#tstatdev.setSetpoint( 72, 'f' )

#test 3 fails (Requested key 'cooling_setpoint_f' not found!)
#tstatdev.setMode( 'cool' )
#tstatdev.setCoolSetpoint( 72, 'f' )

#test 4 fails (Requested key 'cooling_setpoint_f' not found!)
#tstatdev.setMode( 'heat' )
#tstatdev.setHeatSetpoint( 72, 'f' )

data = tstatdev.status()
print('Device status: %r' % data)

Tests were ran one at a time by uncommenting the associated lines of code.

The first test works with setMiddleSetpoint() The second test fails with:

Traceback (most recent call last):
  File "/home/user/projects/xeal/tuya/new_test/tinytuya/examples/test_stat.py", line 12, in <module>
    tstatdev.setSetpoint( 72, 'f' )
  File "/home/user/.local/lib/python3.9/site-packages/tinytuya/Contrib/ThermostatDevice.py", line 306, in setSetpoint
    return self.setMiddleSetpoint( self, setpoint, cf )
TypeError: setMiddleSetpoint() takes from 2 to 3 positional arguments but 4 were given

The last 2 tests fail similarly with:

Requested key 'heating_setpoint_f' not found!
Traceback (most recent call last):
  File "/home/user/projects/xeal/tuya/new_test/tinytuya/examples/test_stat.py", line 20, in <module>
    tstatdev.setHeatSetpoint( 72, 'f' )
  File "/home/user/.local/lib/python3.9/site-packages/tinytuya/Contrib/ThermostatDevice.py", line 314, in setHeatSetpoint
    return self.setValue( k, setpoint )
  File "/home/user/.local/lib/python3.9/site-packages/tinytuya/Contrib/ThermostatDevice.py", line 353, in setValue
    dps, val = self.parseValue( key, val )
TypeError: cannot unpack non-iterable bool object

I'm not sure why the keys are not found, when they are clearly in the table.

@uzlonewolf, I know you've used the thermostats before. Have you ran into this, or have any insight?

elockman commented 1 year ago

Test # 2 was resolved by updating my install with: python3 -m pip install --upgrade tinytuya

Tests # 3 and # 4 are still failing.

uzlonewolf commented 1 year ago

Ok, I think I see what's going on. There are 2 different firmware versions: one which uses low-resolution temperatures on one set of DPs, and the other which uses high-resolution on a different set of DPs. Until it receives a .status() response it has no idea which set it needs to use. So, simply move that tstatdev.status() to above the tests.

elockman commented 1 year ago

Thank you @uzlonewolf. That worked!

uzlonewolf commented 1 year ago

As a side note, I've found that these thermostats get very confused if you send certain commands too quickly. For example, a .setMode(...) followed immediately by a .set____Setpoint(...) will result in it reporting and displaying that new setpoint, however internally it will still be using the old setpoint. In my program I ended up waiting for the status update before sending another command after either a mode change or setpoint change.

elockman commented 1 year ago

@uzlonewolf The setFanRuntime() function has a similar error, but it is a typo bug.

On line 350, it uses the 'fan_runtime' key. But on line 252 the table adds an underscore with 'fan_run_time'

elockman commented 1 year ago

Is this a bug related to issue #327?

uzlonewolf commented 1 year ago

Doesn't look like it. Are any of those tests still failing?

elockman commented 1 year ago

the tests work with the status call ran first

uzlonewolf commented 1 year ago

I'm going to close this one out as it looks like everything has been fixed. @elockman please re-open if you're still having issues.