Fix traceback due to unavailable module

The class defined in this state references a module that is not
installed. This commit moves the class definition with the try/except
where the deps it requires are loaded.
Fix indentation of class
lint fixes
Merge pull request #12975 from terminalmage/fix-unavailable-module

Fix traceback due to unavailable module