Skip to content

Commit

Permalink
Restore the reference to 'self' in all __init__() functions, and make…
Browse files Browse the repository at this point in the history
… sure __init__() exceptions are printed correctly
  • Loading branch information
uzlonewolf committed Oct 28, 2022
1 parent da7378c commit 3684ee9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions tinytuya/BulbDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ class BulbDevice(Device):
has_colourtemp = False
has_colour = False

def __init__(*args, **kwargs):
def __init__(self, *args, **kwargs):
# set the default version to None so we do not immediately connect and call status()
if 'version' not in kwargs or not kwargs['version']:
kwargs['version'] = None
super(BulbDevice, args[0]).__init__(*args[1:], **kwargs)
super(BulbDevice, self).__init__(*args, **kwargs)

@staticmethod
def _rgb_to_hexvalue(r, g, b, bulb="A"):
Expand Down
17 changes: 6 additions & 11 deletions tinytuya/Contrib/ClimateDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Python module to interface with Tuya Portable Air Conditioner devices
Local Control Classes
ClimateDevice(dev_id, address, local_key=None, dev_type='default', version=3.3)
ClimateDevice(dev_id, ...)
Functions
ClimateDevice:
Expand Down Expand Up @@ -50,12 +50,6 @@
class ClimateDevice(Device):
"""
Represents a Tuya based Air Conditioner
Args:
dev_id (str): The device id.
address (str): The network address.
local_key (str, optional): The encryption key. Defaults to None.
version (float, optional): Tuya Device Version (look at Device.set_version)
"""

DPS_POWER = "1"
Expand All @@ -69,10 +63,11 @@ class ClimateDevice(Device):
DPS_SWING = "30"
DPS_STATE = "101"

def __init__(self, dev_id, address, local_key="", dev_type="default", version=3.3):
super(ClimateDevice, self).__init__(
dev_id, address, local_key, dev_type, version=version
)
def __init__(self, *args, **kwargs):
# set the default version to 3.3 as there are no 3.1 devices
if 'version' not in kwargs or not kwargs['version']:
kwargs['version'] = 3.3
super(ClimateDevice, self).__init__(*args, **kwargs)

def status_json(self):
"""Wrapper around status() that replace DPS indices with human readable labels."""
Expand Down
4 changes: 2 additions & 2 deletions tinytuya/Contrib/IRRemoteControlDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ class IRRemoteControlDevice(Device):
NSDP_HEAD = "head" # Actually used but not documented
NSDP_KEY1 = "key1" # Actually used but not documented

def __init__(*args, **kwargs):
def __init__(self, *args, **kwargs):
# set the default version to 3.3 as there are no 3.1 devices
if 'version' not in kwargs or not kwargs['version']:
kwargs['version'] = 3.3
super(IRRemoteControlDevice, args[0]).__init__(*args[1:], **kwargs)
super(IRRemoteControlDevice, self).__init__(*args, **kwargs)

def receive_button( self, timeout ):
log.debug("Receiving button")
Expand Down
4 changes: 2 additions & 2 deletions tinytuya/Contrib/ThermostatDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ class ThermostatDevice(Device):
'130': { 'name': 'weather_forcast' }
}

def __init__(*args, **kwargs):
def __init__(self, *args, **kwargs):
# set the default version to 3.3 as there are no 3.1 devices
if 'version' not in kwargs or not kwargs['version']:
kwargs['version'] = 3.3
# set persistant so we can receive sensor broadcasts
if 'persist' not in kwargs:
kwargs['persist'] = True
super(ThermostatDevice, args[0]).__init__(*args[1:], **kwargs)
super(ThermostatDevice, self).__init__(*args, **kwargs)

self.high_resolution = None
self.schedule = None
Expand Down
15 changes: 9 additions & 6 deletions tinytuya/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,13 @@ def __init__(

def __del__(self):
# In case we have a lingering socket connection, close it
if self.socket is not None:
# self.socket.shutdown(socket.SHUT_RDWR)
self.socket.close()
self.socket = None
try:
if self.socket:
# self.socket.shutdown(socket.SHUT_RDWR)
self.socket.close()
self.socket = None
except:
pass

def __repr__(self):
# FIXME can do better than this
Expand Down Expand Up @@ -1287,8 +1290,8 @@ def generate_payload(self, command, data=None, gwId=None, devId=None, uid=None):


class Device(XenonDevice):
def __init__(*args, **kwargs):
super(Device, args[0]).__init__(*args[1:], **kwargs)
#def __init__(self, *args, **kwargs):
# super(Device, self).__init__(*args, **kwargs)

def status(self):
"""Return device status."""
Expand Down

0 comments on commit 3684ee9

Please sign in to comment.