'Test the controlling state via topic and JSON message.'

def test_controlling_state_via_topic_and_json_message(self):

    assert setup_component(self.hass, lock.DOMAIN, {lock.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'state-topic', 'command_topic': 'command-topic', 'payload_lock': 'LOCK', 'payload_unlock': 'UNLOCK', 'value_template': '{{    value_json.val    }}'}})
    state = self.hass.states.get('lock.test')
    self.assertEqual(STATE_UNLOCKED, state.state)
    fire_mqtt_message(self.hass, 'state-topic', '{"val":"LOCK"}')
    self.hass.block_till_done()
    state = self.hass.states.get('lock.test')
    self.assertEqual(STATE_LOCKED, state.state)
    fire_mqtt_message(self.hass, 'state-topic', '{"val":"UNLOCK"}')
    self.hass.block_till_done()
    state = self.hass.states.get('lock.test')
    self.assertEqual(STATE_UNLOCKED, state.state)
