Closed uzlonewolf closed 1 month ago
I like this. It includes my updates so I'm good pushing this one forward instead.
To test pipx from parent directory of tinytuya:
pipx install ./tinytuya
It required that I create a pyproject.toml
to install dependencies in the build phase:
[build-system]
requires = ["setuptools", "colorama", "requests", "cryptography"]
I was able to pipx
install this PR and started some testing...
$ tinytuya
TinyTuya Setup Wizard [1.14.0]
Enter API Key from tuya.com:
It looks like default is wizard. Do we want that or the usage map?
tinytuya -h
usage: python -m tinytuya [-h] [-debug] {wizard,scan,devices,snapshot,json} ...
TinyTuya [1.14.0]
positional arguments:
{wizard,scan,devices,snapshot,json}
options:
-h, --help show this help message and exit
-debug, -d Enable debug messages
This was the old help - I think we can probably get some of the descriptors back in there:
TinyTuya [1.13.2]
Usage:
python -m tinytuya <command> [<max_time>] [-debug] [-nocolor] [-force [192.168.0.0/24 192.168.1.0/24 ...]] [-h]
wizard Launch Setup Wizard to get Tuya Local KEYs.
scan Scan local network for Tuya devices.
devices Scan all devices listed in devices.json file.
snapshot Scan devices listed in snapshot.json file.
json Scan devices listed in snapshot.json file [JSON].
<max_time> Maximum time to find Tuya devices [Default=18]
-nocolor Disable color text output.
-force Force network scan of device IP addresses based on format:
[net1/mask1 net2/mask2 ...] Auto-detects if none provided.
-no-broadcasts Ignore broadcast packets when force scanning.
-debug Activate debug mode.
-h Show usage.
It looks like default is wizard. Do we want that or the usage map?
I was just about to ask that. Although I'm leaning towards displaying the help, I'm fine either way. I made it auto-run the wizard since that's what it does now. What do you think would be better?
I think we can probably get some of the descriptors back in there
The issue is how argparse handles subparsers. I don't know of any good way to add them without having the command specified. The list of options also changes depending on which command is given.
Although I'm leaning towards displaying the help
Same! Yes, I think the usage help is the right option. It shows the version and commands.
The issue is how argparse handles subparsers. I don't know of any good way to add them without having the command specified. The list of options also changes depending on which command is given.
I know, it may break it from current use, but is probably the cleaner thing to do. We could have each command as a subparser. This is what we did for pypowerwall:
Gives:
$ python3 -m pypowerwall -h main
usage: PyPowerwall [-h] [-debug] {setup,fleetapi,scan,set,get,version} ...
PyPowerwall Module v0.9.1
options:
-h, --help show this help message and exit
-debug Enable debug output
commands (run <command> -h to see usage information):
{setup,fleetapi,scan,set,get,version}
setup Setup Tesla Login for Cloud Mode access
fleetapi Setup Tesla FleetAPI for Cloud Mode access
scan Scan local network for Powerwall gateway
set Set Powerwall Mode and Reserve Level
get Get Powerwall Settings and Power Levels
version Print version information
This is what we did for pypowerwall
Ah, that's what I wanted but wasn't able to figure out how to do. Thanks for the example, I'll get that implemented.
$ tinytuya
usage: tinytuya [-h] [-debug] {wizard,scan,devices,snapshot,json} ...
TinyTuya [1.14.0]
options:
-h, --help show this help message and exit
-debug, -d Enable debug messages
commands (run <command> -h to see usage information):
{wizard,scan,devices,snapshot,json}
wizard Launch Setup Wizard to get Device Local Keys
scan Scan local network for Tuya devices
devices Scan all devices listed in device-file
snapshot Scan devices listed in snapshot-file
json Scan devices listed in snapshot-file and display the result as JSON
$ python3 -m tinytuya
usage: python3 -m tinytuya [-h] [-debug] {wizard,scan,devices,snapshot,json} ...
TinyTuya [1.14.0]
options:
-h, --help show this help message and exit
-debug, -d Enable debug messages
commands (run <command> -h to see usage information):
{wizard,scan,devices,snapshot,json}
wizard Launch Setup Wizard to get Device Local Keys
scan Scan local network for Tuya devices
devices Scan all devices listed in device-file
snapshot Scan devices listed in snapshot-file
json Scan devices listed in snapshot-file and display the result as JSON
I banged on it pretty good and only found 1 minor bug with wizard. That's fixed and I made a couple other tweaks while I was at it. So, I'm going to call this one good to go.
Two notes from my side:
--help
function shows python -m tinytuya
, and I think that's unnecessary now, it can probably just be tinytuya
.
- Maybe you should refactor README now to suggest using pipx instead of pip. (developers who understands and wants it to be used as a library will know they should install it with pip/poetry whatever).
No, pip would be the recommended way with pipx just being an option as the tinytuya CLI is rather pointless by itself. The vast majority of users use tinytuya as a library to control devices using their own scripts.
2. but the
--help
function showspython -m tinytuya
, and I think that's unnecessary now, it can probably just betinytuya
That actually changes depending on how it was called, as shown in the example I posted above.
$ tinytuya
usage: tinytuya [-h] [-debug] {wizard,scan,devices,snapshot,json} ...
$ python3 -m tinytuya
usage: python3 -m tinytuya [-h] [-debug] {wizard,scan,devices,snapshot,json} ...
No, pip would be the recommended way with pipx just being an option as the tinytuya CLI is rather pointless by itself. The vast majority of users use tinytuya as a library to control devices using their own scripts.
Sure, it's your call. By the way I use tinytuya because of tuya-local. To find out the devices information to supply to it. I suppose several users also do the same.
That actually changes depending on how it was called, as shown in the example I posted above.
I see. I was testing with 1.13.3b1
, maybe that's why.
By the way I use tinytuya because of tuya-local. To find out the devices information to supply to it. I suppose several users also do the same.
Sure, you can use it for that, but if that's all you need it for there are other much easier ways of getting the keys (such as https://github.com/blakadder/tuya-uncover ).
Oh. That's cool. Thank you!
Great work on this @uzlonewolf - I love the move to argparse and the additional arguments. Thank you! 🙇 I tweaked the docs to represent this change and added a RELEASE note.
@felipecrs Thanks for your help and feedback! While I agree with @uzlonewolf that this is primarily a library, the pipx
CLI support is a very nice addition. I use the command line options quite a bit myself. 😁 I updated the README to highlight that and how to install and use. Again, thank you! 🙏
Awesome!
Released: https://pypi.org/project/tinytuya/1.14.0/
pipx install tinytuya
I just need to add a few comments to explain some of the code and bang on it a bit to make sure I didn't forget to implement any of the options and I think it's done.
Also closes #500
v0.14.0
pipx install tinytuya
as raised by @felipecrs in https://github.com/jasonacox/tinytuya/issues/500 allowing for easier CLI use.Also closes #501