@@ -140,10 +140,7 @@ def __init__(self, *args, **kwargs):
140
140
self .has_brightness = None
141
141
self .has_colourtemp = None
142
142
self .has_colour = None
143
- self .old_retry = None
144
- self .old_sendwait = None
145
- self .old_persist = None
146
- self .have_old_musicmode = False
143
+ self .tried_status = False
147
144
self .dpset = {
148
145
'switch' : None ,
149
146
'mode' : None ,
@@ -166,6 +163,7 @@ def __init__(self, *args, **kwargs):
166
163
167
164
def status (self , nowait = False ):
168
165
result = super (BulbDevice , self ).status (nowait = nowait )
166
+ self .tried_status = True
169
167
if result and (not self .bulb_configured ) and ('dps' in result ):
170
168
self .detect_bulb (result , nowait = nowait )
171
169
return result
@@ -406,10 +404,13 @@ def _set_values_check( self, check_values, nowait=False ):
406
404
407
405
def turn_onoff (self , on , switch = 0 , nowait = False ):
408
406
"""Turn the device on or off"""
409
- if switch == 0 :
410
- if not self .bulb_has_capability ( 'switch' , nowait = nowait ):
411
- return error_json (ERR_FUNCTION , 'Could not detect bulb switch DP.' )
412
- return self .set_status (on , self .dpset ['switch' ], nowait = nowait )
407
+ if not switch :
408
+ if not self .tried_status :
409
+ self .detect_bulb ( nowait = nowait )
410
+ # some people may use BulbDevice as the default even for non-bulb
411
+ # devices, so default to '1' if we can't detect it
412
+ switch = self .dpset ['switch' ] if self .dpset ['switch' ] else 1
413
+ return self .set_status (on , switch , nowait = nowait )
413
414
414
415
def turn_on (self , switch = 0 , nowait = False ):
415
416
"""Turn the device on"""
@@ -842,8 +843,8 @@ def detect_bulb(self, response=None, nowait=False):
842
843
log .debug ('No cached status, but nowait set! detect_bulb() exiting without detecting bulb!' )
843
844
else :
844
845
response = self .status ()
845
- # return here as self.status() will call us again
846
- return
846
+ # return here as self.status() will call us again
847
+ return
847
848
if response and 'dps' in response and isinstance (response ['dps' ], dict ):
848
849
# Try to determine type of BulbDevice Type based on DPS indexes
849
850
# 1+2 or 20+21 are required per https://developer.tuya.com/en/docs/iot/product-function-definition?id=K9tp155s4th6b
@@ -884,8 +885,6 @@ def detect_bulb(self, response=None, nowait=False):
884
885
elif not self .bulb_configured :
885
886
# response has no dps
886
887
log .debug ("No DPs in response, cannot detect bulb type!" )
887
- #self.bulb_type = default
888
- #self.assume_bulb_attribs()
889
888
890
889
def set_bulb_type (self , bulb_type = None , mapping = None ):
891
890
self .bulb_type = bulb_type
@@ -897,6 +896,9 @@ def set_bulb_capabilities(self, mapping):
897
896
else :
898
897
default_dpset = {}
899
898
899
+ if not isinstance ( mapping , dict ):
900
+ mapping = {}
901
+
900
902
for k in self .dpset :
901
903
if k in mapping :
902
904
self .dpset [k ] = mapping [k ]
0 commit comments