
    j3              
          d Z ddlZddlZ	 ddlZdZddlmZmZmZm	Z	m
Z
mZmZmZmZ ddlmZmZmZ ej&                  d   dd d	k(  rd
ndZdedZ ej,                  ee      Zej1                  dddd       ej1                  dddd       ej3                  dd      Zi Zddddddddd Zd!d"d#d$d%d&Zej=                  e       eD ]  ZejA                  eee   '      ee<   ee   j1                  ddddd()       ed*vred+k7  rleev ree   j1                  d,d-e	z  e!d./       nee   j1                  d.d-e	z  d0e!1       ee   j1                  d2d3d4d5d6d78       ee   j1                  d9d:d       ee   j1                  d;d<d       ee   j1                  d=d>d?d       ed@k7  reevree   j1                  dAdBdCd       edDk(  r:dEe
z  Z"ee   j1                  dFdGe"e
dHI       ee   j1                  dJdKez  edHI       ndLe
z  Z"ee   j1                  dFdGe"e
dHI       edMk(  r.ee   j1                  dNdOez  edH ejF                  dP      Q       eev ree   j1                  dNdRez  edHI        edD   jI                  dSdT      Z%e%j1                  dUdVez  dHW       e%j1                  dXdY'       e%j1                  dZd['       e%j1                  d\d]d^_       e%j1                  d`dad6dbc       edD   j1                  ddded       edf   j1                  dgdhd       eD ]  Zee   jI                  didj      Z&e&jO                  dk      Z(e(j1                  dldmdnW       e(j1                  dodpdqW       e&j1                  drdsdtW       e&j1                  dudvdwW       e&j1                  ddxde)dydz{       ed|v ree   j1                  d}d~de!d       edk(  ree   j1                  d}dde!d       edk(  see   j1                  d}dde!d       ee   j1                  dddd        er ejT                  e       d Z+ejY                         Z-e-j                  r e.de        ej^                  d       e-j`                  r e.de-        ed       e-jb                  re-jd                  re-j`                  s e.de-        ed       e-jb                  evrHe-jb                  dvr9e-jb                  dDk(  re-jf                  re-jf                  e_        e-jh                  r} e5e-jh                        e6k(  r#e-jh                  e_
        e-jh                  e_
        nEe-jh                  jn                  Z8e-jh                  js                          e8e-_4        e8e_
        e8e_
        e-jt                  rxe-jb                  dMk(  rGe-jt                  jn                  e_        e-jt                  js                          ej                  e-_:        n"e-jt                  e_        e-jt                  e_        e-jb                  d@k(  rO ejv                  e-jx                  e-jz                   e-j|                  e-j~                   e-j                         d ZNye-jb                  d+k(  r8 ej                  e-jz                   e-j                  e-j                         d ZNye-jb                  dk(  rZ ej                  e-jx                  e-jz                   e-j|                  e-j~                   e-j                  e-j                         d ZNye-jb                  dMk(  r ej                          d ZNye-jb                  dDk(  re-j                  re-j                  e_        e-j                  e-j                  e-j                  e-j                  ddZIe-j                  r%dj                   eLe-j                  g             eId<    ej                  e-jz                   e-jx                  e-j|                  e-j                  e-j                  e-j~                   e-j                  eI       d ZNye-jb                  dfk(  r ee-       d ZNye-jb                  dk(  r e.de       d ZNye-jb                  dk(  r e+        d ZNye-jb                  dk(  r ee-       d ZNye-jb                  ev r ee-       d ZNy e+        d ZNy#  dZY xY w)a4  
 Python module to interface with Tuya WiFi smart devices

 Author: Jason A. Cox
 For more information see https://github.com/jasonacox/tinytuya

 Run TinyTuya Setup Wizard:
    python -m tinytuya wizard
 This network scan will run if calling this module via command line:
    python -m tinytuya <max_time>

    NTF   )	wizardscannerversionSCANTIME
DEVICEFILESNAPSHOTFILE
CONFIGFILERAWFILE	set_debug)_run_list_command_run_device_command_monitor_deviceiz__main__.pyzpython3 -m tinytuyaz
TinyTuya [])progdescriptionz-debugz-dzEnable debug messages
store_true)helpactionz-vz	--versionzDisplay version informationcommandz4commands (run <command> -h to see usage information))desttitlez,Launch Setup Wizard to get Device Local Keysz#Scan local network for Tuya devicesz&Scan all devices listed in device-filez$Scan devices listed in snapshot-filezCScan devices listed in snapshot-file and display the result as JSONzList devices from device-filez%Show detailed help and usage examples)r   scandevicessnapshotjsonlistr   r   zTurn on a device switchzTurn off a device switchzSet a DPS value on a devicezRead a DPS value from a devicez*Read status and monitor device for updates)onoffsetgetmonitor)r   debug2)r   r   r   )r   r   r   z-maxtimez/Maximum time to find Tuya devices [Default: %s]max_time)r   typer   ?)r   nargsr%   z-forcez-fz
0.0.0.0/24zQForce network scan of device IP addresses. Auto-detects net/mask if none providedappend*)metavarr   r   r'   z-no-broadcastsz,Ignore broadcast packets when force scanningz-nocolorzDisable color text outputz-yesz-yzAnswer "yes" to all questionsr   z-no-pollz-noz'Answer "no" to "Poll?" (overrides -yes)r   z4JSON file to load/save devices from/to [Default: %s]z-device-filez--device-fileFILE)r   defaultr*   z-raw-response-filez:JSON file to save the raw server response to [Default: %s]z,JSON file to load devices from [Default: %s]r   z-snapshot-filez-JSON file to load snapshot from [Default: %s]r)r   r,   r*   r%   z5JSON file to load/save snapshot from/to [Default: %s]zCloud API Credentialsz/If no option is set then the Wizard will promptz-credentials-filez>JSON file to load/save Cloud credentials from/to [Default: %s])r   r*   z-keyzCloud API Key to usez-secretzCloud API Secret to usez-regionzCloud API Region to use)cneuzeu-winuszus-e)r   choicesz-devicezOne or more Device ID(s) to use+)r   r   r'   z-dry-runz$Do not actually connect to the Cloudr   z--jsonz"Display as JSON instead of a tableDevicezh--id or --name are required.  --id and --key are required if the --device-file/-device-file lookup fails)requiredz--idz	Device IDIDz--namez&Device name (looked up in device-file)NAMEz--keyzHDevice local encryption key (prompted if omitted and not in device-file)KEYz--ipzZDevice IP address (loaded from device-file if omitted or auto-discovered if set to "Auto")IPzPTuya protocol version (auto-discovered if omitted, defaults to 3.3 if not found)VERdev_version)r   r,   r%   r*   r   )r   r   z--dpszSwitch number [Default: 1]N)r   r,   r%   r*   r!   z.DPS index to read (omit to return full status)r    z	DPS index)r   r5   r%   r*   z--valuezdValue to set. Parsed as JSON if possible (e.g. true, 123, "text"), otherwise sent as a plain string.VALUE)r   r5   r*   c                  (    t        dt        z         y )Na
  
TinyTuya %s - Python module to interface with Tuya WiFi smart devices
https://github.com/jasonacox/tinytuya

Usage: python -m tinytuya <command> [options]

Setup & Discovery Commands:
  wizard       Launch Setup Wizard to get Device Local Keys from Tuya Cloud
                 python -m tinytuya wizard
  scan         Scan local network for Tuya devices (UDP broadcast)
                 python -m tinytuya scan
                 python -m tinytuya scan 30               # scan for 30 seconds
  devices      Scan all devices listed in devices.json and show status
                 python -m tinytuya devices
  snapshot     Scan devices listed in snapshot.json and show status
                 python -m tinytuya snapshot
  json         Scan snapshot devices and return results as JSON
                 python -m tinytuya json
  list         List all devices from devices.json as a table
                 python -m tinytuya list
                 python -m tinytuya list --json           # output as JSON

Device Control Commands (require --id or --name):
  on           Turn on a device switch
                 python -m tinytuya on --id <DeviceID> --key <LocalKey>
                 python -m tinytuya on --name "Kitchen Light"
  off          Turn off a device switch
                 python -m tinytuya off --id <DeviceID> --key <LocalKey>
                 python -m tinytuya off --name "Kitchen Light" --dps 2
  set          Set a DPS value on a device
                 python -m tinytuya set --id <DeviceID> --key <LocalKey> --dps 1 --value true
                 python -m tinytuya set --name "Fan" --dps 3 --value 50
  get          Read device status (or a single DPS value)
                 python -m tinytuya get --id <DeviceID> --key <LocalKey>
                 python -m tinytuya get --name "Sensor" --dps 8
  monitor      Connect to device and monitor for live status updates
                 python -m tinytuya monitor --id <DeviceID> --key <LocalKey>

Info Commands:
  version      Display the TinyTuya version
                 python -m tinytuya version
  help         Show this help message
                 python -m tinytuya help

Global Options:
  -d, -debug   Enable debug output
  -v           Display version and exit

Device Control Options:
  --id ID      Device ID (from devices.json)
  --name NAME  Device name (case-insensitive lookup in devices.json)
  --key KEY    Device local encryption key (16 chars)
  --ip IP      Device IP address (auto-discovered if omitted)
  --version N  Tuya protocol version (e.g. 3.3, 3.4, 3.5)
  --dps N      DPS index for on/off/set/get (default: 1)
  --value V    Value to set (parsed as JSON: true, false, 0-100, "text")

Note: --key, --ip, and --version are loaded automatically from devices.json
      if the device is found by --id or --name.
)printr        >/DATA/.local/lib/python3.12/site-packages/tinytuya/__main__.py_print_helprC      s    	 ;v w; ;rA   zTinyTuya version:zParsed args:)r   r   r   )scantimecolor	forcescandiscover
assume_yes)rE   rH   	skip_pollr   )rD   rE   rF   rG   rH   rI   )fileapiKey	apiSecret	apiRegionapiDeviceID,rN   )rE   retriesrF   nocloudrH   rG   rI   credentialsr   r   r"   c                       y )Nr@   r@   rA   rB   dummyrT     s    rA   )O__doc__sysargparseargcompleteHAVE_ARGCOMPLETE r   r   r   r   r   r	   r
   r   r   clir   r   r   argvr   r   ArgumentParserparseradd_argumentadd_subparsers	subparser
subparserscmd_listcontrol_cmdsupdatesp
add_parserintr   FileTypeadd_argument_group
cred_group	dev_groupadd_mutually_exclusive_groupname_id_groupfloatautocompleterC   
parse_argsargsr?   exitdebugr   r#   raw_response_filedevice_filer%   strnamefnameclosesnapshot_filer   r$   nocolorforceno_broadcastsyesr   no_poll
alldevicessnapshotjsoncredentials_filekeysecretregioncredsdevicejoinsumdry_runrT   r@   rA   rB   <module>r      sn
  
   k j j H H #CD 1] B!(*	 	 	 t	F   Xt*A,  X   T;-JS_  a!!	9o!q	
<176Q+,3	 %%(+; 	 
B))"8B<)@JrNrN46MVbiqs	!!\!2++Z>orz>z  BE  LV+  X2++Z>orz>z  CF  MP+  RrN''4  Uh  qy  AD'  FrN'')9@n  xD'  F2##Z6QZf#h2##VT8W`l#n<Bl2rN''UAjs'  B	X~E
R2##^_4Ycms#u2##%9@|  @G  AG  QX  bh#  	j=
J2##^_4Ycms#u	V|2##%5<knz<z  EQ  [a  hy  hp  hy  hy  z}  h~#  	@	|	 	2##%5<s  wC  =C  MY  ci#  	kE J !446M  PA  B
 
  ,3s  wA  4A  KQ   S 
  &<  > 
  )B  D 
  )BLt  v 
  )JS[cf  h 
8  ! !:4Zco ! q 6   /S\h  i B211(  =g  hI::D:IMvdKx1Ycij7-w  BG  H6  .J  TX  Y;-  JN  UZ  di  p}  ~	]2##G2NXY`cmp#q	u2##G2blpwz  EH#  	I	u2##G+SV`c#d2##I  5[  fj  t{#  	| " Kf&<~ <<	
w'CHHQK::	.$dO <<{{4::nd#$ ||<'DLL@[,[<<8#(>(>!33FND$$%,%)%5%5"$($4$4!((--  &&(#( %*"$)!||v%'+'9'9'>'>$""((*%,%9%9"'+'9'9$&*&8&8#<<6GLL4==T\\1Adjjhlhzhzdz  IM  IQ  IQ  S:	9 
\\ZG-488t||]6	5 
\\YG4<<7GTXT^T^nr  oA  oA  kA  OS  OW  OW  cg  co  co  q2	1 
\\VG.	- 
\\X 11++txxdkkhlhshs  EI  KE{{"xxDKK(<=mFMMdll*T]]djjbfbnbn{  |D  |D  TX  Tf  Tf  Pf  sw  s  s  MR  T 	 
\\Vd	 
\\Y	
w'	 
\\VM	 
\\YD	 
\\\!	 M	ks   c c"