|
25 | 25 | import errno |
26 | 26 | import base64 |
27 | 27 | import traceback |
28 | | -from colorama import init |
29 | 28 | import tinytuya |
30 | 29 |
|
| 30 | +try: |
| 31 | + from colorama import init |
| 32 | + HAVE_COLORAMA = True |
| 33 | +except ImportError: |
| 34 | + HAVE_COLORAMA = False |
| 35 | + |
| 36 | +HAVE_COLOR = HAVE_COLORAMA or not sys.platform.startswith('win') |
| 37 | + |
31 | 38 | # Optional libraries required for forced scanning |
32 | 39 | #try: |
33 | 40 | # from getmac import get_mac_address |
|
54 | 61 | PSULIBS = False |
55 | 62 |
|
56 | 63 | # Colorama terminal color capability for all platforms |
57 | | -init() |
| 64 | +if HAVE_COLORAMA: |
| 65 | + init() |
58 | 66 |
|
59 | 67 | # Configuration Files |
60 | 68 | DEVICEFILE = tinytuya.DEVICEFILE |
@@ -205,6 +213,10 @@ def get_ip_to_broadcast(): |
205 | 213 | def send_discovery_request( iface_list=None ): |
206 | 214 | close_sockets = False |
207 | 215 |
|
| 216 | + if not tinytuya.AESCipher.CRYPTOLIB_HAS_GCM: |
| 217 | + # GCM is required for discovery requests |
| 218 | + return False |
| 219 | + |
208 | 220 | if not iface_list: |
209 | 221 | close_sockets = True |
210 | 222 | iface_list = {} |
@@ -1146,6 +1158,7 @@ def devices(verbose=False, scantime=None, color=True, poll=True, forcescan=False |
1146 | 1158 |
|
1147 | 1159 | """ |
1148 | 1160 | # Terminal formatting |
| 1161 | + color = color and HAVE_COLOR |
1149 | 1162 | termcolors = tinytuya.termcolor(color) |
1150 | 1163 | #(bold, subbold, normal, dim, alert, alertdim, cyan, red, yellow) = termcolors |
1151 | 1164 | term = TermColors( *termcolors ) |
@@ -1920,6 +1933,7 @@ def snapshot(color=True, assume_yes=False, skip_poll=None): |
1920 | 1933 | skip_poll = True or False, auto-answer 'no' to "Poll local devices?" (overrides assume_yes) |
1921 | 1934 | """ |
1922 | 1935 | # Terminal formatting |
| 1936 | + color = color and HAVE_COLOR |
1923 | 1937 | termcolors = tinytuya.termcolor(color) |
1924 | 1938 | term = TermColors( *termcolors ) |
1925 | 1939 |
|
@@ -1992,6 +2006,7 @@ def alldevices(color=True, scantime=None, forcescan=False, discover=True, assume |
1992 | 2006 | color = True or False, print output in color [Default: True] |
1993 | 2007 | """ |
1994 | 2008 | # Terminal formatting |
| 2009 | + color = color and HAVE_COLOR |
1995 | 2010 | #(bold, subbold, normal, dim, alert, alertdim, cyan, red, yellow) = tinytuya.termcolor(color) |
1996 | 2011 | termcolors = tinytuya.termcolor(color) |
1997 | 2012 | term = TermColors( *termcolors ) |
@@ -2031,6 +2046,7 @@ def alldevices(color=True, scantime=None, forcescan=False, discover=True, assume |
2031 | 2046 | return |
2032 | 2047 |
|
2033 | 2048 | def poll_and_display( tuyadevices, color=True, scantime=None, snapshot=False, forcescan=False, discover=True ): # pylint: disable=W0621 |
| 2049 | + color = color and HAVE_COLOR |
2034 | 2050 | termcolors = tinytuya.termcolor(color) |
2035 | 2051 | term = TermColors( *termcolors ) |
2036 | 2052 |
|
|
0 commit comments