Skip to content

Commit

Permalink
Merge pull request #276 from jasonacox/pylint
Browse files Browse the repository at this point in the history
Added command line -debug flag and code cleanup based on pylint
  • Loading branch information
jasonacox authored Feb 9, 2023
2 parents 5089da9 + 0c80d2a commit ce91405
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 411 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
python -m pip install --upgrade pip
pip install pylint
pip install -r requirements.txt
- name: Analysing the code with pylint
- name: Analyzing the code with pylint
run: |
pylint tinytuya/*.py
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[MESSAGES CONTROL]
disable=consider-iterating-dictionary, import-error, invalid-name, missing-docstring, no-else-return, no-member, too-many-lines, line-too-long, too-many-ancestors, too-many-arguments, too-many-branches, too-many-instance-attributes, too-many-locals, too-many-nested-blocks, too-many-return-statements, too-many-statements, too-few-public-methods, ungrouped-imports, use-dict-literal, superfluous-parens, fixme, consider-using-f-string, bare-except, broad-except, unused-variable, unspecified-encoding, redefined-builtin, consider-using-dict-items, redundant-u-string-prefix, useless-object-inheritance
disable=consider-iterating-dictionary, consider-swap-variables, consider-using-enumerate, cyclic-import, consider-using-max-builtin, no-else-continue, consider-using-min-builtin, consider-using-in, super-with-arguments, protected-access, import-outside-toplevel, multiple-statements, unidiomatic-typecheck, no-else-break, import-error, invalid-name, missing-docstring, no-else-return, no-member, too-many-lines, line-too-long, too-many-ancestors, too-many-arguments, too-many-branches, too-many-instance-attributes, too-many-locals, too-many-nested-blocks, too-many-return-statements, too-many-statements, too-few-public-methods, ungrouped-imports, use-dict-literal, superfluous-parens, fixme, consider-using-f-string, bare-except, broad-except, unused-variable, unspecified-encoding, redefined-builtin, consider-using-dict-items, redundant-u-string-prefix, useless-object-inheritance

[SIMILARITIES]
min-similarity-lines=8
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,20 @@ Tuya devices use AES encryption which is not available in the Python standard li
### Command Line
```
python -m tinytuya [command] [<max_retry>] [-nocolor] [-h]
command = scan Scan local network for Tuya devices.
command = wizard Launch Setup Wizard to get Tuya Local KEYs.
command = devices Scan all devices listed in devices.json file.
command = snapshot Scan devices listed in snapshot.json file.
command = json Scan devices listed in snapshot.json file [JSON].
max_retry Maximum number of retries to find Tuya devices [Default=15]
-nocolor Disable color text output.
-force Force network scan for device IP addresses.
-h Show 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 for device IP addresses. Auto-detects network range if none provided.
[net1/mask1 net2/mask2 ...]
-no-broadcasts Ignore broadcast packets when force scanning.
-debug Activate debug mode.
-h Show usage.
```
### Scan Tool
Expand Down
6 changes: 6 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# RELEASE NOTES

## v1.10.2 - Misc PyLint Cleanup

* PyPI 1.10.2 (unreleased)
* Miscellaneous PyLint Cleanup
* Fix Contrib.ThermostatDevice.SetSetpoint() #273

## v1.10.1 - Bug Fix for BulbDevice and Zigbee Devices

* PyPI 1.10.1
Expand Down
6 changes: 3 additions & 3 deletions tinytuya/BulbDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(r, g, b) = colour_rgb():
(h,s,v) = colour_hsv()
result = state():
Inherited
json = status() # returns json payload
set_version(version) # 3.1 [default] or 3.3
Expand Down Expand Up @@ -55,7 +55,7 @@

import colorsys

from .core import *
from .core import * # pylint: disable=W0401, W0614

class BulbDevice(Device):
"""
Expand Down Expand Up @@ -215,7 +215,7 @@ def _hexvalue_to_hsv(hexvalue, bulb="A"):

return (h, s, v)

def set_version(self, version):
def set_version(self, version): # pylint: disable=W0621
"""
Set the Tuya device version 3.1 or 3.3 for BulbDevice
Attempt to determine BulbDevice Type: A or B based on:
Expand Down
20 changes: 9 additions & 11 deletions tinytuya/Cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
i.e. "start=-1" is 1 day ago, "start=-7" is 7 days ago
Reference
* https://developer.tuya.com/en/docs/cloud/device-connection-service?id=Kb0b8geg6o761
"""
* https://developer.tuya.com/en/docs/cloud/device-connection-service?id=Kb0b8geg6o761
from .core import *
"""

import hashlib
import hmac
import json
import time
import requests

from .core import * # pylint: disable=W0401, W0614

########################################################
# Cloud Classes and Functions
########################################################
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(self, apiRegion=None, apiKey=None, apiSecret=None, apiDeviceID=None
"Tuya Cloud Key and Secret required",
)
#return self.error
raise TypeError('Tuya Cloud Key and Secret required')
raise TypeError('Tuya Cloud Key and Secret required') # pylint: disable=W0707

self.setregion(apiRegion)
# Attempt to connect to cloud and get token
Expand Down Expand Up @@ -444,10 +444,10 @@ def sendcommand(self, deviceid=None, commands=None):
"Error from Tuya Cloud: %r", response_dict['msg'],
)
return response_dict

def getconnectstatus(self, deviceid=None):
"""
Get the device Cloud connect status.
Get the device Cloud connect status.
"""
if not self.token:
return self.error
Expand All @@ -460,12 +460,10 @@ def getconnectstatus(self, deviceid=None):
response_dict = self._tuyaplatform(uri, ver='v1.0')

if not response_dict['success']:
log.debug(
"Error from Tuya Cloud: %r" % response_dict['msg'],
)
log.debug("Error from Tuya Cloud: %r", response_dict['msg'])
return(response_dict["result"]["online"])

def getdevicelog(self, deviceid=None, start=None, end=None, evtype=None, size=0, max_fetches=50, start_row_key=None, params={}):
def getdevicelog(self, deviceid=None, start=None, end=None, evtype=None, size=0, max_fetches=50, start_row_key=None, params={}): # pylint: disable=W0102
"""
Get the logs for a device.
Expand Down
2 changes: 1 addition & 1 deletion tinytuya/Contrib/IRRemoteControlDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ def _merge_similar_pulse_times( p_count, fudge ):
p_map[b] = new_p
for i in p_map:
if p_map[i] == a or p_map[i] == b:
p_map[i] = new_p
p_map[i] = new_p # pylint: disable=E4702

return p_map

Expand Down
4 changes: 2 additions & 2 deletions tinytuya/CoverDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
open_cover(switch=1):
close_cover(switch=1):
stop_cover(switch=1):
Inherited
json = status() # returns json payload
set_version(version) # 3.1 [default] or 3.3
Expand All @@ -38,7 +38,7 @@
detect_available_dps() # Return list of DPS available from device
generate_payload(command, data) # Generate TuyaMessage payload for command with data
send(payload) # Send payload to device (do not wait for response)
receive()
receive()
"""

from .core import Device
Expand Down
4 changes: 2 additions & 2 deletions tinytuya/OutletDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Functions
OutletDevice:
set_dimmer(percentage):
Inherited
json = status() # returns json payload
set_version(version) # 3.1 [default] or 3.3
Expand All @@ -42,7 +42,7 @@
detect_available_dps() # Return list of DPS available from device
generate_payload(command, data) # Generate TuyaMessage payload for command with data
send(payload) # Send payload to device (do not wait for response)
receive()
receive()
"""

from .core import Device
Expand Down
2 changes: 1 addition & 1 deletion tinytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Cloud(apiRegion, apiKey, apiSecret, apiDeviceID, new_sign_algorithm)
Functions
Device(XenonDevice)
Device(XenonDevice)
json = status() # returns json payload
set_version(version) # 3.1 [default] or 3.3
set_socketPersistent(False/True) # False [default] or True
Expand Down
6 changes: 5 additions & 1 deletion tinytuya/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
state = 4
elif i.lower() == "-yes":
assume_yes = True
elif i.lower() == "-debug":
tinytuya.set_debug(True)
elif last_force and len(i) > 6:
this_force = True
force_list.append( i )
Expand Down Expand Up @@ -89,7 +91,7 @@
if state == 10:
print("TinyTuya [%s]\n" % (tinytuya.version))
print("Usage:\n")
print(" python -m tinytuya <command> [<max_time>] [-nocolor] [-force [192.168.0.0/24 192.168.1.0/24 ...]] [-h]")
print(" python -m tinytuya <command> [<max_time>] [-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.")
Expand All @@ -99,7 +101,9 @@
print(" <max_time> Maximum time to find Tuya devices [Default=%s]" % tinytuya.SCANTIME)
print(" -nocolor Disable color text output.")
print(" -force Force network scan for device IP addresses. Auto-detects network range if none provided.")
print(" [net1/mask1 net2/mask2 ...]")
print(" -no-broadcasts Ignore broadcast packets when force scanning.")
print(" -debug Activate debug mode.")
print(" -h Show usage.")
print("")

Expand Down
Loading

0 comments on commit ce91405

Please sign in to comment.