Skip to content

Commit

Permalink
Add pipx support #500
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed May 26, 2024
1 parent db9680d commit 1893ab9
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 80 deletions.
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# RELEASE NOTES

## v1.13.3 - PIPX Support

* Add support for `pipx install tinytuya` as raised by @felipecrs in https://github.com/jasonacox/tinytuya/issues/500 allowing for easier CLI use.
* Possible breaking change: Running `tinytuya` by itself will now produce a "Usage" page instead of running a scan. Use `tinytuya scan` or `python -m tinytuya scan`.

## v1.13.2 - Contrib Updates

* Add example for XmCosy+ RGBW patio string lights by @bikerglen in https://github.com/jasonacox/tinytuya/pull/445
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build-system]
requires = ["setuptools", "colorama", "requests", "cryptography"]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
url='https://github.com/jasonacox/tinytuya',
packages=setuptools.find_packages(exclude=("sandbox",)),
install_requires=INSTALL_REQUIRES,
entry_points={"console_scripts": ["tinytuya=tinytuya.__main__:main"]},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
160 changes: 81 additions & 79 deletions tinytuya/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,92 +19,94 @@
from . import wizard
from . import scanner

retries = None
state = 0
color = True
force = False
force_list = []
last_force = False
broadcast_listen = True
assume_yes = False
def main():
retries = None
state = 10
color = True
force = False
force_list = []
last_force = False
broadcast_listen = True
assume_yes = False

for i in sys.argv:
if i==sys.argv[0]:
continue
this_force = False
if i.lower() == "wizard":
state = 1
elif i.lower() == "scan":
state = 0
elif i.lower() == "-nocolor":
color = False
elif i.lower() == "-force" or i.lower() == "-f":
force = True
this_force = True
elif i.lower() == "-no-broadcasts":
broadcast_listen = False
elif i.lower() == "snapshot":
state = 2
elif i.lower() == "devices":
state = 3
elif i.lower() == "json":
state = 4
elif i.lower() == "-yes" or i.lower() == "-y":
assume_yes = True
elif i.lower() == "-debug" or i.lower() == "-d":
tinytuya.set_debug(True)
elif last_force and len(i) > 6:
this_force = True
force_list.append( i )
else:
try:
retries = int(i)
except:
state = 10
for i in sys.argv:
if i==sys.argv[0]:
continue
this_force = False
if i.lower() == "wizard":
state = 1
elif i.lower() == "scan":
state = 0
elif i.lower() == "-nocolor":
color = False
elif i.lower() == "-force" or i.lower() == "-f":
force = True
this_force = True
elif i.lower() == "-no-broadcasts":
broadcast_listen = False
elif i.lower() == "snapshot":
state = 2
elif i.lower() == "devices":
state = 3
elif i.lower() == "json":
state = 4
elif i.lower() == "-yes" or i.lower() == "-y":
assume_yes = True
elif i.lower() == "-debug" or i.lower() == "-d":
tinytuya.set_debug(True)
elif last_force and len(i) > 6:
this_force = True
force_list.append( i )
else:
try:
retries = int(i)
except:
state = 10

last_force = this_force
last_force = this_force

if force and len(force_list) > 0:
force = force_list
if force and len(force_list) > 0:
force = force_list

# State 0 = Run Network Scan
if state == 0:
scanner.scan(scantime=retries, color=color, forcescan=force, discover=broadcast_listen, assume_yes=assume_yes)
# State 0 = Run Network Scan
if state == 0:
scanner.scan(scantime=retries, color=color, forcescan=force, discover=broadcast_listen, assume_yes=assume_yes)

# State 1 = Run Setup Wizard
if state == 1:
wizard.wizard(color=color, retries=retries, forcescan=force, quicklist=assume_yes)
# State 1 = Run Setup Wizard
if state == 1:
wizard.wizard(color=color, retries=retries, forcescan=force, quicklist=assume_yes)

# State 2 = Snapshot Display and Scan
if state == 2:
scanner.snapshot(color=color)
# State 2 = Snapshot Display and Scan
if state == 2:
scanner.snapshot(color=color)

# State 3 = Scan All Devices
if state == 3:
scanner.alldevices(color=color, scantime=retries)
# State 3 = Scan All Devices
if state == 3:
scanner.alldevices(color=color, scantime=retries)

# State 4 = Scan All Devices
if state == 4:
scanner.snapshotjson()
# State 4 = Scan All Devices
if state == 4:
scanner.snapshotjson()

# State 10 = Show Usage
if state == 10:
print("TinyTuya [%s]\n" % (tinytuya.version))
print("Usage:\n")
print(" python -m tinytuya <command> [<max_time>] [-debug] [-nocolor] [-force [192.168.0.0/24 192.168.1.0/24 ...]] [-h]")
print("")
print(" wizard Launch Setup Wizard to get Tuya Local KEYs.")
print(" scan Scan local network for Tuya devices.")
print(" devices Scan all devices listed in devices.json file.")
print(" snapshot Scan devices listed in snapshot.json file.")
print(" json Scan devices listed in snapshot.json file [JSON].")
print(" <max_time> Maximum time to find Tuya devices [Default=%s]" % tinytuya.SCANTIME)
print(" -nocolor Disable color text output.")
print(" -force Force network scan of device IP addresses based on format:")
print(" [net1/mask1 net2/mask2 ...] Auto-detects if none provided.")
print(" -no-broadcasts Ignore broadcast packets when force scanning.")
print(" -debug Activate debug mode.")
print(" -h Show usage.")
print("")
# State 10 = Show Usage
if state == 10:
print("TinyTuya [%s]\n" % (tinytuya.version))
print("Usage:\n")
print(" python -m tinytuya <command> [<max_time>] [-debug] [-nocolor] [-force [192.168.0.0/24 192.168.1.0/24 ...]] [-h]")
print("")
print(" wizard Launch Setup Wizard to get Tuya Local KEYs.")
print(" scan Scan local network for Tuya devices.")
print(" devices Scan all devices listed in devices.json file.")
print(" snapshot Scan devices listed in snapshot.json file.")
print(" json Scan devices listed in snapshot.json file [JSON].")
print(" <max_time> Maximum time to find Tuya devices [Default=%s]" % tinytuya.SCANTIME)
print(" -nocolor Disable color text output.")
print(" -force Force network scan of device IP addresses based on format:")
print(" [net1/mask1 net2/mask2 ...] Auto-detects if none provided.")
print(" -no-broadcasts Ignore broadcast packets when force scanning.")
print(" -debug Activate debug mode.")
print(" -h Show usage.")
print("")

# End
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion tinytuya/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
# Colorama terminal color capability for all platforms
init()

version_tuple = (1, 13, 2)
version_tuple = (1, 13, 3)
version = __version__ = "%d.%d.%d" % version_tuple
__author__ = "jasonacox"

Expand Down

0 comments on commit 1893ab9

Please sign in to comment.