Skip to content

Commit a3cb697

Browse files
committed
Relax color check as colorama is only required on Windows
1 parent e271f35 commit a3cb697

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

tinytuya/core/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
except ImportError:
8787
HAVE_COLORAMA = False
8888

89+
HAVE_COLOR = HAVE_COLORAMA or not sys.platform.startswith('win')
90+
8991
from .crypto_helper import AESCipher
9092

9193
# Backward compatibility for python2
@@ -130,7 +132,7 @@ def hex2bin(x):
130132

131133
def set_debug(toggle=True, color=True):
132134
"""Enable tinytuya verbose logging"""
133-
color = color and HAVE_COLORAMA
135+
color = color and HAVE_COLOR
134136
if toggle:
135137
if color:
136138
logging.basicConfig(
@@ -204,7 +206,7 @@ def appenddevice(newdevice, devices):
204206

205207
# Terminal color helper
206208
def termcolor(color=True):
207-
color = color and HAVE_COLORAMA
209+
color = color and HAVE_COLOR
208210
if color is False:
209211
# Disable Terminal Color Formatting
210212
bold = subbold = normal = dim = alert = alertdim = cyan = red = yellow = ""

tinytuya/scanner.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
except ImportError:
3434
HAVE_COLORAMA = False
3535

36+
HAVE_COLOR = HAVE_COLORAMA or not sys.platform.startswith('win')
3637

3738
# Optional libraries required for forced scanning
3839
#try:
@@ -1153,7 +1154,7 @@ def devices(verbose=False, scantime=None, color=True, poll=True, forcescan=False
11531154
11541155
"""
11551156
# Terminal formatting
1156-
color = color and HAVE_COLORAMA
1157+
color = color and HAVE_COLOR
11571158
termcolors = tinytuya.termcolor(color)
11581159
#(bold, subbold, normal, dim, alert, alertdim, cyan, red, yellow) = termcolors
11591160
term = TermColors( *termcolors )
@@ -1928,7 +1929,7 @@ def snapshot(color=True, assume_yes=False, skip_poll=None):
19281929
skip_poll = True or False, auto-answer 'no' to "Poll local devices?" (overrides assume_yes)
19291930
"""
19301931
# Terminal formatting
1931-
color = color and HAVE_COLORAMA
1932+
color = color and HAVE_COLOR
19321933
termcolors = tinytuya.termcolor(color)
19331934
term = TermColors( *termcolors )
19341935

@@ -2001,7 +2002,7 @@ def alldevices(color=True, scantime=None, forcescan=False, discover=True, assume
20012002
color = True or False, print output in color [Default: True]
20022003
"""
20032004
# Terminal formatting
2004-
color = color and HAVE_COLORAMA
2005+
color = color and HAVE_COLOR
20052006
#(bold, subbold, normal, dim, alert, alertdim, cyan, red, yellow) = tinytuya.termcolor(color)
20062007
termcolors = tinytuya.termcolor(color)
20072008
term = TermColors( *termcolors )
@@ -2041,7 +2042,7 @@ def alldevices(color=True, scantime=None, forcescan=False, discover=True, assume
20412042
return
20422043

20432044
def poll_and_display( tuyadevices, color=True, scantime=None, snapshot=False, forcescan=False, discover=True ): # pylint: disable=W0621
2044-
color = color and HAVE_COLORAMA
2045+
color = color and HAVE_COLOR
20452046
termcolors = tinytuya.termcolor(color)
20462047
term = TermColors( *termcolors )
20472048

tinytuya/wizard.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
import json
2727
from datetime import datetime
2828
import tinytuya
29+
import sys
2930

3031
try:
3132
from colorama import init
3233
HAVE_COLORAMA = True
3334
except ImportError:
3435
HAVE_COLORAMA = False
3536

37+
HAVE_COLOR = HAVE_COLORAMA or not sys.platform.startswith('win')
38+
3639
# Backward compatibility for python2
3740
try:
3841
input = raw_input
@@ -120,7 +123,7 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False, assume_yes=
120123
except:
121124
old_devices = {}
122125

123-
color = color and HAVE_COLORAMA
126+
color = color and HAVE_COLOR
124127
(bold, subbold, normal, dim, alert, alertdim, cyan, red, yellow) = tinytuya.termcolor(color)
125128

126129
print(bold + 'TinyTuya Setup Wizard' + dim + ' [%s]' % (tinytuya.version) + normal)

0 commit comments

Comments
 (0)