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

Add new function in class 'DEVICE' #275

Closed CStan77 closed 1 year ago

CStan77 commented 1 year ago

Hi friend, I am French, excuse me for my English ;)

I have equipment of the 'qn' category Until now, I used the Cloud OpenAPI but it's a trial version that needs to be extended every 6 months... not great for home automation. 👎🏻

While searching I came across your module 'tinytuya' what happiness with local commands 🥇

On the other hand, in my case, my equipment is a heater so when I send an ignition command, I also want to adjust the set temperature, the ventilation speed.

Rather than making 3 successive commands, I added a '_set_valuedict()' function in the 'Device' class in order to pass all the commands at once.

def set_value_dict(self, dict_value='', nowait=False):
        #Set value of any index.
        #Args:
        #    dict_value(dict): liste de commande index et value
        #    nowait(bool): True to send without waiting for response.

        # open device, send request, then close connection
        if (isinstance(dict_value, dict) and (len(dict_value) > 0)):
            payload = self.generate_payload(CONTROL, dict_value)
            data = self._send_receive(payload, getresponse=(not nowait))
        else:
            data["Err"]=914
            data["Error"]="dict_value required!"
        return data  

in my Python script :

        dict_reglages = {}
        dict_reglages["5"]= "2" # niveau de ventillation [1;2]
        dict_reglages["2"]= 29  # consigne de temperature [10;49]
        dict_reglages["1"]= False # etat du radiateur [True;False]
        # dict_reglages["1"]= True # etat du radiateur [True;False]

        # envoi la commande a l'equipement
        data = d.set_value_dict(dict_reglages)
        data = d.status() 
        print('%s ===> status() result %r' % (time.strftime('%H:%M:%S'),data))

# 12:28:59 ===> status(False 28 2) result {u'devId': u'102***********1a3c', u'dps': {u'1': False, u'2': 29, u'5': u'2'}, u't': 1675510137}

can you include it in your module? thank you very much for your work

uzlonewolf commented 1 year ago

This actually exists already as .set_multiple_values(). I see the documentation is missing for this function, I'l try to get it added.

That said, have you tried it yet? Some devices get really upset if you try and set multiple options at once. The thermostats I have do not like changing the temperature if anything else (fan, system mode, etc) is changed within 2-3 seconds; they'll display the new temperature, however they will not actually use it.

CStan77 commented 1 year ago

In the core and the doc, there was nothing so I had done it. I tested .set_multiple_values() it works perfectly

in my case the equipment takes well, all the values at once