def test_controlling_state_via_topic_and_json_message(self):
        assert _setup_component(self.hass, garage_door.DOMAIN, {
            garage_door.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'state_open': 'beer open',
                'state_closed': 'beer closed',
                'service_open': 'beer service open',
                'service_close': 'beer service close',
                'value_template': '{{ value_json.val }}'
            }
        })

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_CLOSED, state.state)

        fire_mqtt_message(self.hass, 'state-topic', '{"val":"beer open"}')
        self.hass.pool.block_till_done()

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_OPEN, state.state)

        fire_mqtt_message(self.hass, 'state-topic', '{"val":"beer closed"}')
        self.hass.pool.block_till_done()

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_CLOSED, state.state)
Test the controlling state via topic and JSON message.
dataset/ETHPy150Open home-assistant/home-assistant/tests/components/garage_door/test_mqtt.py/TestGarageDoorMQTT.test_controlling_state_via_topic_and_json_message