'Test the sending of command in optimistic mode.'

def test_sending_mqtt_commands_and_optimistic(self):

    assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test', 'command_topic': 'test_light_rgb/set', 'brightness': True, 'color_temp': True, 'effect': True, 'rgb': True, 'white_value': True, 'qos': 2}})
    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')
    self.hass.block_till_done()
    self.assertEqual(('test_light_rgb/set', '{"state":    "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', '{"state":    "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, color_temp=155, effect='colorloop', white_value=170)
    self.hass.block_till_done()
    self.assertEqual('test_light_rgb/set', self.mock_publish.mock_calls[(-2)][1][0])
    self.assertEqual(2, self.mock_publish.mock_calls[(-2)][1][2])
    self.assertEqual(False, self.mock_publish.mock_calls[(-2)][1][3])
    message_json = json.loads(self.mock_publish.mock_calls[(-2)][1][1])
    self.assertEqual(50, message_json['brightness'])
    self.assertEqual(155, message_json['color_temp'])
    self.assertEqual('colorloop', message_json['effect'])
    self.assertEqual(170, message_json['white_value'])
    self.assertEqual('ON', message_json['state'])
    state = self.hass.states.get('light.test')
    self.assertEqual(STATE_ON, state.state)
    self.assertEqual(50, state.attributes['brightness'])
    self.assertEqual(155, state.attributes['color_temp'])
    self.assertEqual('colorloop', state.attributes['effect'])
    self.assertEqual(170, state.attributes['white_value'])
