Skip to content

Commit

Permalink
Fixing device.py so that Travis doesn't fail and added test for set_p…
Browse files Browse the repository at this point in the history
…redefined_color (#80)

* Add logging and fix bug in set_predefined_color
* Add test of set_predefined_color
* Bump version to prepare for new release
  • Loading branch information
Patrik authored Oct 28, 2017
1 parent e065d0f commit 151c730
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 5 additions & 3 deletions pytradfri/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
xy_brightness_to_rgb, COLORS, MIN_KELVIN, MAX_KELVIN,\
MIN_KELVIN_WS, MAX_KELVIN_WS
from .resource import ApiResource
import logging

_LOGGER = logging.getLogger(__name__)


class Device(ApiResource):
Expand Down Expand Up @@ -216,10 +219,9 @@ def set_kelvin_color(self, kelvins, *, index=0):
def set_predefined_color(self, colorname, *, index=0):
try:
color = COLORS[colorname.lower().replace(" ", "_")]
except:
pass
else:
return self.set_hex_color(color, index=index)
except KeyError:
_LOGGER.debug('Could not match color name')

def set_rgb_color(self, r, g, b, *, index=0):
return self.set_values(rgb_to_xyY(r, g, b), index=index)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = "3.0.3"
VERSION = "3.0.4"
DOWNLOAD_URL = \
'https://github.com/ggravlingen/pytradfri/archive/{}.zip'.format(VERSION)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,13 @@ def test_color_device_control():
assert light_control.can_set_kelvin
assert light_control.min_kelvin == 1667
assert light_control.max_kelvin == 25000


def test_setters():
cmd = Device(LIGHT_CWS).light_control \
.set_predefined_color('Warm glow')
assert cmd.data == {'3311': [{'5706': 'efd275'}]}

cmd = Device(LIGHT_CWS).light_control \
.set_predefined_color('Ggravlingen')
assert hasattr(cmd, 'data') is False

0 comments on commit 151c730

Please sign in to comment.