Skip to content

Commit

Permalink
Report proper features in mqtt_json light (#6941)
Browse files Browse the repository at this point in the history
* Add tests for supported features in mqtt_json (it fails)

* Fix supported features in mqtt_json
  • Loading branch information
jawilson authored and pvizeli committed Apr 5, 2017
1 parent 75a3747 commit f1f033e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 6 additions & 10 deletions homeassistant/components/light/mqtt_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,12 @@ def __init__(self, name, effect_list, topic, qos, retain, optimistic,
self._flash_times = flash_times

self._supported_features = (SUPPORT_TRANSITION | SUPPORT_FLASH)
self._supported_features |= (rgb is not None and SUPPORT_RGB_COLOR)
self._supported_features |= (brightness is not None and
SUPPORT_BRIGHTNESS)
self._supported_features |= (color_temp is not None and
SUPPORT_COLOR_TEMP)
self._supported_features |= (effect is not None and
SUPPORT_EFFECT)
self._supported_features |= (white_value is not None and
SUPPORT_WHITE_VALUE)
self._supported_features |= (xy is not None and SUPPORT_XY_COLOR)
self._supported_features |= (rgb and SUPPORT_RGB_COLOR)
self._supported_features |= (brightness and SUPPORT_BRIGHTNESS)
self._supported_features |= (color_temp and SUPPORT_COLOR_TEMP)
self._supported_features |= (effect and SUPPORT_EFFECT)
self._supported_features |= (white_value and SUPPORT_WHITE_VALUE)
self._supported_features |= (xy and SUPPORT_XY_COLOR)

@asyncio.coroutine
def async_added_to_hass(self):
Expand Down
9 changes: 8 additions & 1 deletion tests/components/light/test_mqtt_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
import unittest

from homeassistant.setup import setup_component
from homeassistant.const import STATE_ON, STATE_OFF, ATTR_ASSUMED_STATE
from homeassistant.const import (
STATE_ON, STATE_OFF, ATTR_ASSUMED_STATE, ATTR_SUPPORTED_FEATURES)
import homeassistant.components.light as light
from tests.common import (
get_test_home_assistant, mock_mqtt_component, fire_mqtt_message,
Expand Down Expand Up @@ -126,6 +127,7 @@ def test_no_color_brightness_color_temp_white_val_if_no_topics(self): \

state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))
self.assertIsNone(state.attributes.get('rgb_color'))
self.assertIsNone(state.attributes.get('brightness'))
self.assertIsNone(state.attributes.get('color_temp'))
Expand Down Expand Up @@ -166,6 +168,7 @@ def test_controlling_state_via_topic(self): \

state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(255, state.attributes.get(ATTR_SUPPORTED_FEATURES))
self.assertIsNone(state.attributes.get('rgb_color'))
self.assertIsNone(state.attributes.get('brightness'))
self.assertIsNone(state.attributes.get('color_temp'))
Expand Down Expand Up @@ -272,6 +275,7 @@ def test_sending_mqtt_commands_and_optimistic(self): \

state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(191, state.attributes.get(ATTR_SUPPORTED_FEATURES))
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))

light.turn_on(self.hass, 'light.test')
Expand Down Expand Up @@ -335,6 +339,7 @@ def test_flash_short_and_long(self): \

state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))

light.turn_on(self.hass, 'light.test', flash="short")
self.hass.block_till_done()
Expand Down Expand Up @@ -374,6 +379,7 @@ def test_transition(self):

state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))

light.turn_on(self.hass, 'light.test', transition=10)
self.hass.block_till_done()
Expand Down Expand Up @@ -418,6 +424,7 @@ def test_invalid_color_brightness_and_white_values(self): \

state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(185, state.attributes.get(ATTR_SUPPORTED_FEATURES))
self.assertIsNone(state.attributes.get('rgb_color'))
self.assertIsNone(state.attributes.get('brightness'))
self.assertIsNone(state.attributes.get('white_value'))
Expand Down

0 comments on commit f1f033e

Please sign in to comment.