Optimistic MQTT light (#14401)
* Restores light state, case the light is optimistic * lint * hound * hound * Added mqtt_json * hound * added mqtt_template * lint * cleanup * use ATTR
This commit is contained in:
parent
16bf10b1a2
commit
d47006c98f
6 changed files with 165 additions and 73 deletions
|
@ -140,14 +140,16 @@ light:
|
|||
"""
|
||||
import unittest
|
||||
from unittest import mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, STATE_UNAVAILABLE, ATTR_ASSUMED_STATE)
|
||||
import homeassistant.components.light as light
|
||||
import homeassistant.core as ha
|
||||
from tests.common import (
|
||||
assert_setup_component, get_test_home_assistant, mock_mqtt_component,
|
||||
fire_mqtt_message)
|
||||
fire_mqtt_message, mock_coro)
|
||||
|
||||
|
||||
class TestLightMQTT(unittest.TestCase):
|
||||
|
@ -481,12 +483,23 @@ class TestLightMQTT(unittest.TestCase):
|
|||
'payload_on': 'on',
|
||||
'payload_off': 'off'
|
||||
}}
|
||||
|
||||
with assert_setup_component(1, light.DOMAIN):
|
||||
assert setup_component(self.hass, light.DOMAIN, config)
|
||||
fake_state = ha.State('light.test', 'on', {'brightness': 95,
|
||||
'hs_color': [100, 100],
|
||||
'effect': 'random',
|
||||
'color_temp': 100,
|
||||
'white_value': 50})
|
||||
with patch('homeassistant.components.light.mqtt.async_get_last_state',
|
||||
return_value=mock_coro(fake_state)):
|
||||
with assert_setup_component(1, light.DOMAIN):
|
||||
assert setup_component(self.hass, light.DOMAIN, config)
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(95, state.attributes.get('brightness'))
|
||||
self.assertEqual((100, 100), state.attributes.get('hs_color'))
|
||||
self.assertEqual('random', state.attributes.get('effect'))
|
||||
self.assertEqual(100, state.attributes.get('color_temp'))
|
||||
self.assertEqual(50, state.attributes.get('white_value'))
|
||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
|
||||
light.turn_on(self.hass, 'light.test')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue