Skip to content

Commit

Permalink
Add force flag to set_colour() and set_white()
Browse files Browse the repository at this point in the history
  • Loading branch information
uzlonewolf committed Jul 30, 2024
1 parent f9c14fe commit edad81d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tinytuya/BulbDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def set_scene(self, scene, nowait=False):

return self.set_value( self.DPS_INDEX_MODE[self.bulb_type], s, nowait=nowait )

def set_colour(self, r, g, b, nowait=False):
def set_colour(self, r, g, b, nowait=False, force=False):
"""
Set colour of an rgb bulb.
Expand Down Expand Up @@ -319,7 +319,7 @@ def set_colour(self, r, g, b, nowait=False):

# check to see if power and mode also need to be set
state = self.cached_status(nowait=True)
if state and self.DPS in state and state[self.DPS]:
if (not force) and state and self.DPS in state and state[self.DPS]:
# last state is cached, so check to see if 'mode' needs to be set
if (dp_index_mode not in state[self.DPS]) or (state[self.DPS][dp_index_mode] != self.DPS_MODE_COLOUR):
payload[dp_index_mode] = self.DPS_MODE_COLOUR
Expand Down Expand Up @@ -404,7 +404,7 @@ def set_white_percentage(self, brightness=100, colourtemp=0, nowait=False):
data = self.set_white(b, c, nowait=nowait)
return data

def set_white(self, brightness=-1, colourtemp=-1, nowait=False):
def set_white(self, brightness=-1, colourtemp=-1, nowait=False, force=False):
"""
Set white coloured theme of an rgb bulb.
Expand Down Expand Up @@ -456,9 +456,9 @@ def set_white(self, brightness=-1, colourtemp=-1, nowait=False):

# check to see if power and mode also need to be set
state = self.cached_status(nowait=True)
if state and self.DPS in state and state[self.DPS]:
if (not force) and state and self.DPS in state and state[self.DPS]:
# last state is cached, so check to see if 'mode' needs to be set
if (dp_index_mode not in state[self.DPS]) or (state[self.DPS][dp_index_mode] != self.DPS_MODE_COLOUR):
if (dp_index_mode not in state[self.DPS]) or (state[self.DPS][dp_index_mode] != self.DPS_MODE_WHITE):
payload[dp_index_mode] = self.DPS_MODE_WHITE
# last state is cached, so check to see if 'power' needs to be set
if (dp_index_on not in state[self.DPS]) or (not state[self.DPS][dp_index_on]):
Expand Down

0 comments on commit edad81d

Please sign in to comment.