Allow no device_classes to be defined.

Also a bit of refactoring to consolidate duplicate code.