'Test the controlling of the state via topic.'

def test_controlling_state_via_topic(self):

    assert setup_component(self.hass, light.DOMAIN, {light.DOMAIN: {'platform': 'mqtt_json', 'name': 'test', 'state_topic': 'test_light_rgb', 'command_topic': 'test_light_rgb/set', 'brightness': True, 'color_temp': True, 'effect': True, 'rgb': True, 'white_value': True, 'xy': True, 'qos': '0'}})
    state = self.hass.states.get('light.test')
    self.assertEqual(STATE_OFF, state.state)
    self.assertEqual(255, state.attributes.get(ATTR_SUPPORTED_FEATURES))
    self.assertIsNone(state.attributes.get('rgb_color'))
    self.assertIsNone(state.attributes.get('brightness'))
    self.assertIsNone(state.attributes.get('color_temp'))
    self.assertIsNone(state.attributes.get('effect'))
    self.assertIsNone(state.attributes.get('white_value'))
    self.assertIsNone(state.attributes.get('xy_color'))
    self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
    fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON","color":{"r":255,"g":255,"b":255,"x":0.123,"y":0.123},"brightness":255,"color_temp":155,"effect":"colorloop","white_value":150}')
    self.hass.block_till_done()
    state = self.hass.states.get('light.test')
    self.assertEqual(STATE_ON, state.state)
    self.assertEqual([255, 255, 255], state.attributes.get('rgb_color'))
    self.assertEqual(255, state.attributes.get('brightness'))
    self.assertEqual(155, state.attributes.get('color_temp'))
    self.assertEqual('colorloop', state.attributes.get('effect'))
    self.assertEqual(150, state.attributes.get('white_value'))
    self.assertEqual([0.123, 0.123], state.attributes.get('xy_color'))
    fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"OFF"}')
    self.hass.block_till_done()
    state = self.hass.states.get('light.test')
    self.assertEqual(STATE_OFF, state.state)
    fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON","brightness":100}')
    self.hass.block_till_done()
    light_state = self.hass.states.get('light.test')
    self.hass.block_till_done()
    self.assertEqual(100, light_state.attributes['brightness'])
    fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON","color":{"r":125,"g":125,"b":125}}')
    self.hass.block_till_done()
    light_state = self.hass.states.get('light.test')
    self.assertEqual([125, 125, 125], light_state.attributes.get('rgb_color'))
    fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON","color":{"x":0.135,"y":0.135}}')
    self.hass.block_till_done()
    light_state = self.hass.states.get('light.test')
    self.assertEqual([0.135, 0.135], light_state.attributes.get('xy_color'))
    fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON","color_temp":155}')
    self.hass.block_till_done()
    light_state = self.hass.states.get('light.test')
    self.assertEqual(155, light_state.attributes.get('color_temp'))
    fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON","effect":"colorloop"}')
    self.hass.block_till_done()
    light_state = self.hass.states.get('light.test')
    self.assertEqual('colorloop', light_state.attributes.get('effect'))
    fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON","white_value":155}')
    self.hass.block_till_done()
    light_state = self.hass.states.get('light.test')
    self.assertEqual(155, light_state.attributes.get('white_value'))
