'Test the sending of command in optimistic mode.'

def test_sending_mqtt_commands_and_optimistic(self):

    config = {light.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'command_topic': 'test_light_rgb/set', 'brightness_command_topic': 'test_light_rgb/brightness/set', 'rgb_command_topic': 'test_light_rgb/rgb/set', 'color_temp_command_topic': 'test_light_rgb/color_temp/set', 'effect_command_topic': 'test_light_rgb/effect/set', 'white_value_command_topic': 'test_light_rgb/white_value/set', 'xy_command_topic': 'test_light_rgb/xy/set', 'qos': 2, 'payload_on': 'on', 'payload_off': 'off'}}
    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.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)
    self.mock_publish.reset_mock()
    light.turn_on(self.hass, 'light.test', brightness=50, xy_color=[0.123, 0.123])
    light.turn_on(self.hass, 'light.test', rgb_color=[75, 75, 75], white_value=80)
    self.hass.block_till_done()
    self.mock_publish().async_publish.assert_has_calls([mock.call('test_light_rgb/set', 'on', 2, False), mock.call('test_light_rgb/rgb/set', '75,75,75', 2, False), mock.call('test_light_rgb/brightness/set', 50, 2, False), mock.call('test_light_rgb/white_value/set', 80, 2, False), mock.call('test_light_rgb/xy/set', '0.123,0.123', 2, False)], any_order=True)
    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(80, state.attributes['white_value'])
    self.assertEqual((0.123, 0.123), state.attributes['xy_color'])
