| 1 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
|
| 3 |
""" |
| 4 |
Hardware collection |
| 5 |
""" |
| 6 |
import os |
| 7 |
from openrazer_daemon.hardware.device_base import RazerDevice |
| 8 |
|
| 9 |
# Hack to get a list of hardware modules to import |
| 10 |
HARDWARE_MODULES = ['openrazer_daemon.hardware.' + os.path.splitext(hw_file)[0] for hw_file in os.listdir(os.path.dirname(__file__)) if hw_file not in ('device_base.py', '__init__.py') and hw_file.endswith('.py')] |
| 11 |
|
| 12 |
# List of classes to exclude from the class finding |
| 13 |
EXCLUDED_CLASSES = ('RazerDevice', 'RazerDeviceBrightnessSuspend') |
| 14 |
|
| 15 |
|
| 16 |
def get_device_classes(): |
| 17 |
""" |
| 18 |
Get a list of hardware classes |
| 19 |
|
| 20 |
:return: List of RazerDevice subclasses |
| 21 |
:rtype: list of callable |
| 22 |
""" |
| 23 |
classes = [] |
| 24 |
|
| 25 |
for hw_module in HARDWARE_MODULES: |
| 26 |
imported_module = __import__(hw_module, globals=globals(), locals=locals(), fromlist=['*'], level=0) |
| 27 |
|
| 28 |
for class_name, class_instance in imported_module.__dict__.items(): |
| 29 |
if class_name in EXCLUDED_CLASSES or class_name.startswith('_') or not isinstance(class_instance, type): |
| 30 |
continue |
| 31 |
|
| 32 |
classes.append(class_instance) |
| 33 |
|
| 34 |
return sorted(classes, key=lambda cls: cls.__name__) |