Skip to content

Commit

Permalink
Add transition_time to more methods (#120)
Browse files Browse the repository at this point in the history
Added to and tested for the following methods:

- set_color_temp
- set_hex_color
- set_xy_color
- set_hsb
- set_predefined_color
  • Loading branch information
jurriaan authored and lwis committed Nov 24, 2017
1 parent 26f66df commit fd4add4
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions pytradfri/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,42 +195,66 @@ def set_dimmer(self, dimmer, *, index=0, transition_time=None):
values = {
ATTR_LIGHT_DIMMER: dimmer
}

if transition_time is not None:
values[ATTR_TRANSITION_TIME] = transition_time

return self.set_values(values, index=index)

def set_color_temp(self, color_temp, *, index=0):
def set_color_temp(self, color_temp, *, index=0, transition_time=None):
"""Set color temp a light."""
return self.set_values({
values = {
ATTR_LIGHT_MIREDS: color_temp
}, index=index)
}

if transition_time is not None:
values[ATTR_TRANSITION_TIME] = transition_time

return self.set_values(values, index=index)

def set_hex_color(self, color, *, index=0):
def set_hex_color(self, color, *, index=0, transition_time=None):
"""Set xy color of the light."""
return self.set_values({
values = {
ATTR_LIGHT_COLOR_HEX: color,
}, index=index)
}

if transition_time is not None:
values[ATTR_TRANSITION_TIME] = transition_time

return self.set_values(values, index=index)

def set_xy_color(self, color_x, color_y, *, index=0):
def set_xy_color(self, color_x, color_y, *, index=0, transition_time=None):
"""Set xy color of the light."""
return self.set_values({
values = {
ATTR_LIGHT_COLOR_X: color_x,
ATTR_LIGHT_COLOR_Y: color_y
}, index=index)
}

if transition_time is not None:
values[ATTR_TRANSITION_TIME] = transition_time

return self.set_values(values, index=index)

def set_hsb(self, hue, saturation, brightness, *, index=0):
def set_hsb(self, hue, saturation, brightness, *, index=0,
transition_time=None):
"""Set HSB color settings of the light."""
return self.set_values({
values = {
ATTR_LIGHT_COLOR_SATURATION: hue,
ATTR_LIGHT_COLOR_HUE: saturation,
ATTR_LIGHT_DIMMER: brightness
}, index=index)
}

if transition_time is not None:
values[ATTR_TRANSITION_TIME] = transition_time

return self.set_values(values, index=index)

def set_predefined_color(self, colorname, *, index=0):
def set_predefined_color(self, colorname, *, index=0,
transition_time=None):
try:
color = COLORS[colorname.lower().replace(" ", "_")]
return self.set_hex_color(color, index=index)
return self.set_hex_color(color, index=index,
transition_time=transition_time)
except KeyError:
raise ColorError('Invalid color specified: %s',
colorname)
Expand Down

0 comments on commit fd4add4

Please sign in to comment.