diff --git a/homeassistant/components/light/mqtt.py b/homeassistant/components/light/mqtt.py index 3c860e074dd..2cdb9ee3fc4 100644 --- a/homeassistant/components/light/mqtt.py +++ b/homeassistant/components/light/mqtt.py @@ -134,6 +134,11 @@ class MqttLight(Light): """ True if device is on. """ return self._state + @property + def assumed_state(self): + """Return True if we do optimistic updates.""" + return self._optimistic + def turn_on(self, **kwargs): """ Turn the device on. """ should_update = False diff --git a/tests/components/light/test_mqtt.py b/tests/components/light/test_mqtt.py index f08e84677a5..139a0be8f20 100644 --- a/tests/components/light/test_mqtt.py +++ b/tests/components/light/test_mqtt.py @@ -45,7 +45,7 @@ light: """ import unittest -from homeassistant.const import STATE_ON, STATE_OFF +from homeassistant.const import STATE_ON, STATE_OFF, ATTR_ASSUMED_STATE import homeassistant.components.light as light from tests.common import ( get_test_home_assistant, mock_mqtt_component, fire_mqtt_message) @@ -115,6 +115,7 @@ class TestLightMQTT(unittest.TestCase): self.assertEqual(STATE_OFF, state.state) self.assertIsNone(state.attributes.get('rgb_color')) self.assertIsNone(state.attributes.get('brightness')) + self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE)) fire_mqtt_message(self.hass, 'test_light_rgb/status', 'on') self.hass.pool.block_till_done() @@ -201,6 +202,7 @@ class TestLightMQTT(unittest.TestCase): state = self.hass.states.get('light.test') self.assertEqual(STATE_OFF, state.state) + self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE)) light.turn_on(self.hass, 'light.test') self.hass.pool.block_till_done()