def test_setting_sensor_value_via_mqtt_message(self):
        self.hass.config.components = ['mqtt']
        assert _setup_component(self.hass, sensor.DOMAIN, {
            sensor.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'test-topic',
                'unit_of_measurement': 'fav unit'
            }
        })

        fire_mqtt_message(self.hass, 'test-topic', '100')
        self.hass.pool.block_till_done()
        state = self.hass.states.get('sensor.test')

        self.assertEqual('100', state.state)
        self.assertEqual('fav unit',
                         state.attributes.get('unit_of_measurement'))
Test the setting of the value via MQTT.
dataset/ETHPy150Open home-assistant/home-assistant/tests/components/sensor/test_mqtt.py/TestSensorMQTT.test_setting_sensor_value_via_mqtt_message