Allow deriving from SmartModule without being registered (#1189)

This commit is contained in:
Steven B. 2024-10-23 21:42:01 +01:00 committed by GitHub
parent a88b677776
commit 51958d8078
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,9 +76,11 @@ class SmartModule(Module):
self._error_count = 0 self._error_count = 0
def __init_subclass__(cls, **kwargs): def __init_subclass__(cls, **kwargs):
name = getattr(cls, "NAME", cls.__name__) # We only want to register submodules in a modules package so that
_LOGGER.debug("Registering %s", cls) # other classes can inherit from smartmodule and not be registered
cls.REGISTERED_MODULES[name] = cls if cls.__module__.split(".")[-2] == "modules":
_LOGGER.debug("Registering %s", cls)
cls.REGISTERED_MODULES[cls.__name__] = cls
def _set_error(self, err: Exception | None): def _set_error(self, err: Exception | None):
if err is None: if err is None: