diff --git a/RELEASE.md b/RELEASE.md index 4fbac6b..28b909c 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cf0e05a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[build-system] +requires = ["setuptools", "colorama", "requests", "cryptography"] diff --git a/setup.py b/setup.py index f8e69bd..ff33e6f 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/tinytuya/__main__.py b/tinytuya/__main__.py index e39d0b0..89ba258 100644 --- a/tinytuya/__main__.py +++ b/tinytuya/__main__.py @@ -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 [] [-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(" 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 [] [-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(" 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() diff --git a/tinytuya/core.py b/tinytuya/core.py index 2a4dd6b..dad15cc 100644 --- a/tinytuya/core.py +++ b/tinytuya/core.py @@ -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"