Closed felipecrs closed 1 month ago
Hi @felipecrs - The issue is that tinytuya is primarily a library, not a command line tool. The pipx
tool is used for command line python tools. The note it provided also indicated that:
If you are attempting to install a library, pipx should not be used. Consider using pip or a similar tool instead.
However, since TinyTuya does have a CLI, it seems like there may be a way to trigger it. If someone has some time to explore, it looks like there might be a way based on how setup is configured.
I'll flag this.
Not sure if it's going to help with this any, but a couple months ago I rewrote the CLI to use argparse. I was almost done but then work kept me really busy for a few weeks and I completely forgot where I was with it T_T Anyway, looking at https://pipx.pypa.io/stable/how-pipx-works/#__tabbed_1_3 it seems just a couple lines in setup.py should do it.
I rewrote the CLI to use argparse
Good idea. I'm slowly converting my other projects over to that. My only hesitation with tinytuya is related to it being a CLI breaking change for some of the options. But it is probably time and we can signal that with a major version update.
Having said that, It looks like I was able to get it to work with some updates to setup.py and main.py. I uploaded a pre-release version:
pipx install "tinytuya==1.13.3b1"
Can you give that a try @felipecrs ?
My only hesitation with tinytuya is related to it being a CLI breaking change for some of the options.
I'll need to double-check but I think I got it so none of the options changed. The only possible issue is everything except the debug switch needs to come after the command (allowing them both before and after is a pain to implement).
$ python3 -m tinytuya -h
usage: python -m tinytuya [-h] [-debug] {wizard,scan,devices,snapshot,json} ...
TinyTuya [1.13.2]
positional arguments:
{wizard,scan,devices,snapshot,json}
options:
-h, --help show this help message and exit
-debug, -d Enable debug messages
$ python3 -m tinytuya wizard -h
usage: python -m tinytuya wizard [-h] [-debug] [-nocolor] [-yes] [-no-poll] [-force [0.0.0.0/24 ...]] [-no-broadcasts] [-device-file FILE] [-snapshot-file FILE] [-credentials-file FILE] [-key KEY]
[-secret SECRET] [-region {cn,eu,eu-w,in,us,us-e}] [-device DEVICE [DEVICE ...]] [-dry-run]
[max_time]
positional arguments:
max_time Maximum time to find Tuya devices [Default: 18]
options:
-h, --help show this help message and exit
-debug, -d Enable debug messages
-nocolor Disable color text output
-yes, -y Answer "yes" to all questions
-no-poll, -no Answer "no" to "Poll?" (overrides -yes)
-force [0.0.0.0/24 ...], -f [0.0.0.0/24 ...]
Force network scan of device IP addresses. Auto-detects net/mask if none provided
-no-broadcasts Ignore broadcast packets when force scanning
-device-file FILE JSON file to load/save devices from/to [Default: devices.json]
-snapshot-file FILE JSON snapshot file to load devices from [Default: snapshot.json]
-dry-run Do not actually connect to the Cloud
Cloud API Credentials:
If no option is set then the Wizard will prompt
-credentials-file FILE
JSON file to load/save Cloud credentials from/to [Default: tinytuya.json]
-key KEY Cloud API Key to use
-secret SECRET Cloud API Secret to use
-region {cn,eu,eu-w,in,us,us-e}
Cloud API Region to use
-device DEVICE [DEVICE ...]
One or more Device ID(s) to use
$ python3 -m tinytuya scan -h
usage: python -m tinytuya scan [-h] [-debug] [-nocolor] [-yes] [-force [0.0.0.0/24 ...]] [-no-broadcasts] [-device-file FILE] [-snapshot-file FILE] [max_time]
positional arguments:
max_time Maximum time to find Tuya devices [Default: 18]
options:
-h, --help show this help message and exit
-debug, -d Enable debug messages
-nocolor Disable color text output
-yes, -y Answer "yes" to all questions
-force [0.0.0.0/24 ...], -f [0.0.0.0/24 ...]
Force network scan of device IP addresses. Auto-detects net/mask if none provided
-no-broadcasts Ignore broadcast packets when force scanning
-device-file FILE JSON file to load/save devices from/to [Default: devices.json]
-snapshot-file FILE JSON snapshot file to load devices from [Default: snapshot.json]
Can you give that a try @felipecrs ?
Awesome, it works like a charm!
I don't know what it takes to make it work better with
pipx
, but it would be super nice if possible.I am no Python expert. Maybe you just need to declare the tinytuya executable/binary in some manifest? Also, not sure about this "normalizer" thing.