'Test the controlling state via topic.'

def test_state_via_state_topic(self):

    self.assertTrue(setup_component(self.hass, cover.DOMAIN, {cover.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'state-topic', 'command_topic': 'command-topic', 'qos': 0, 'payload_open': 'OPEN', 'payload_close': 'CLOSE', 'payload_stop': 'STOP'}}))
    state = self.hass.states.get('cover.test')
    self.assertEqual(STATE_UNKNOWN, state.state)
    fire_mqtt_message(self.hass, 'state-topic', '0')
    self.hass.block_till_done()
    state = self.hass.states.get('cover.test')
    self.assertEqual(STATE_CLOSED, state.state)
    fire_mqtt_message(self.hass, 'state-topic', '50')
    self.hass.block_till_done()
    state = self.hass.states.get('cover.test')
    self.assertEqual(STATE_OPEN, state.state)
    fire_mqtt_message(self.hass, 'state-topic', '100')
    self.hass.block_till_done()
    state = self.hass.states.get('cover.test')
    self.assertEqual(STATE_OPEN, state.state)
    fire_mqtt_message(self.hass, 'state-topic', STATE_CLOSED)
    self.hass.block_till_done()
    state = self.hass.states.get('cover.test')
    self.assertEqual(STATE_CLOSED, state.state)
    fire_mqtt_message(self.hass, 'state-topic', STATE_OPEN)
    self.hass.block_till_done()
    state = self.hass.states.get('cover.test')
    self.assertEqual(STATE_OPEN, state.state)
