'Test optimistic mode.'

def test_optimistic(self):

    with assert_setup_component(1, light.DOMAIN):
        assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_template', 'name': 'test', 'command_topic': 'test_light_rgb/set', 'command_on_template': 'on,{{    brightness|d    }},{{    color_temp|d    }},{{    white_value|d    }},{{    red|d    }}-{{    green|d    }}-{{    blue|d    }}', 'command_off_template': 'off', 'qos': 2}})
    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.block_till_done()
    self.assertEqual(('test_light_rgb/set', 'on,,,,--', 2, False), self.mock_publish.mock_calls[(-2)][1])
    state = self.hass.states.get('light.test')
    self.assertEqual(STATE_ON, state.state)
    light.turn_off(self.hass, 'light.test')
    self.hass.block_till_done()
    self.assertEqual(('test_light_rgb/set', 'off', 2, False), self.mock_publish.mock_calls[(-2)][1])
    state = self.hass.states.get('light.test')
    self.assertEqual(STATE_OFF, state.state)
    light.turn_on(self.hass, 'light.test', brightness=50, rgb_color=[75, 75, 75])
    self.hass.block_till_done()
    self.assertEqual('test_light_rgb/set', self.mock_publish.mock_calls[(-2)][1][0])
    payload = self.mock_publish.mock_calls[(-2)][1][1]
    self.assertEqual('on,50,,,75-75-75', payload)
    light.turn_on(self.hass, 'light.test', color_temp=200, white_value=139)
    self.hass.block_till_done()
    payload = self.mock_publish.mock_calls[(-2)][1][1]
    self.assertEqual('on,,200,139,--', payload)
    self.assertEqual(2, self.mock_publish.mock_calls[(-2)][1][2])
    self.assertEqual(False, self.mock_publish.mock_calls[(-2)][1][3])
    state = self.hass.states.get('light.test')
    self.assertEqual(STATE_ON, state.state)
    self.assertEqual((75, 75, 75), state.attributes['rgb_color'])
    self.assertEqual(50, state.attributes['brightness'])
    self.assertEqual(200, state.attributes['color_temp'])
    self.assertEqual(139, state.attributes['white_value'])
