Open andyb2000 opened 2 weeks ago
You should be able to just
c = tinytuya.Cloud(...)
ticket = c.cloudrequest( '/v1.0/smart-lock/devices/bfc28e88ad23bc91f6mwgz/password-ticket' )
unlock = c.cloudrequest( '/v1.1/devices/bfc28e88ad23bc91f6mwgz/door-lock/password-free/open-door', post={'ticket_id': '...'} )
cloudrequest:
def cloudrequest(self, url, action=None, post=None, query=None):
"""
Make a generic cloud request and return the results.
Args:
url: Required. The URL to fetch, i.e. "/v1.0/devices/0011223344556677/logs"
action: Optional. GET, POST, DELETE, or PUT. Defaults to GET, unless POST data is supplied.
post: Optional. POST body data. Will be fed into json.dumps() before posting.
query: Optional. A dict containing query string key/value pairs.
"""
I'm trying to add in cloud support for this door lock device. Device details first:
In the TUYA API I've worked out that you can trigger an unlock by the "Smart Lock Open Service" by grabbing a temporary key:
https://openapi.tuyaeu.com/v1.0/smart-lock/devices/bfc28e88ad23bc91f6mwgz/password-ticket
Which returns:
From that you can then trigger a temporary unlock using "Unlock Door Without Password" which uses the ticket_id above (8 character so in my example it's bxEhlNt2) so the unlock api call is:
https://openapi.tuyaeu.com/v1.1/devices/bfc28e88ad23bc91f6mwgz/door-lock/password-free/open-door
And the payload/data to set is {"ticket_id":"bxEhlNt2"}
What I'm struggling to work out is how to achieve this via the tinytuya cloud api commands. I've added/setup the cloud functions and can retrieve device state of the unit, etc. How would I turn this into commands? In the example for a smart switch you would:
However, I'm unsure how to do raw api calls/queries using this library. Any pointers please?