Python interface to Tuya WiFi smart devices.
Project description
TuyaFace
Tuya client that allows you to locally communicate with tuya devices without the tuya-cloud.
Installation
pip install tuyaface
Public Interface
Request current device status
status(device: dict)
Returns dict
Update device dps state
set_state(device: dict, value: bool, idx: int = 1)
Returns dict
Update device status
set_status(device: dict, dps: dict)
Returns dict
TuyaClient
Initialize client
TuyaClient(device: dict, on_status: callable=None, on_connection: callable=None)
Request current device status
status()
Returns dict
Update device dps state
set_state(value: bool, idx: int = 1)
Returns dict
Close the connection and stop the worker thread
stop_client()
example
from tuyaface.tuyaclient import TuyaClient
def on_status(data:dict):
print(data)
def on_connection(value: bool):
print(value)
device = {
'protocol': '3.3', # 3.1 | 3.3
'deviceid': '34280100600194d17c96',
'localkey': 'e7e9339aa82abe61',
'ip': '192.168.1.101',
}
client = TuyaClient(device, on_status, on_connection)
client.start()
data = client.status()
client.set_state(!data['dps']['1'], 1) #toggle
client.stop_client()
Data structure
Device dict
device = {
'protocol': '3.3', # 3.1 | 3.3
'deviceid': '34280100600194d17c96',
'localkey': 'e7e9339aa82abe61',
'ip': '192.168.1.101',
}
DPS dict
dps = {
'1': True,
'2': False,
'101': 255,
'102': 128,
...etc...
}
Todo v1.1.8
- validate/sanitize request
Changelog
v1.1.7
- added tuyaclient
- Correct message header generation
- fix typo in decrypt
https://github.com/TradeFace/tuya/wiki
Implementations
- https://github.com/TradeFace/tuyamqtt
- let me know, I'll add it here
Acknowledgements
- This module is a rewrite of https://github.com/clach04/python-tuya
- https://github.com/codetheweb/tuyapi as reference on commands
- https://github.com/SDNick484 for testing protocol 3.1 reimplementation
- https://github.com/jkerdreux-imt several improvements
- https://github.com/PortableProgrammer help on #20
- https://github.com/emontnemery tuyaclient
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tuyaface-1.1.7.tar.gz
(7.3 kB
view hashes)