From 89123b8ec4d5082cd6ba80aca223a296b5420845 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Wed, 23 Oct 2024 18:10:55 +0100 Subject: [PATCH] Allow deriving from SmartModule without being registered --- kasa/smart/smartmodule.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kasa/smart/smartmodule.py b/kasa/smart/smartmodule.py index 1f4c4f482..8fea1d9fb 100644 --- a/kasa/smart/smartmodule.py +++ b/kasa/smart/smartmodule.py @@ -76,9 +76,11 @@ def __init__(self, device: SmartDevice, module: str): self._error_count = 0 def __init_subclass__(cls, **kwargs): - name = getattr(cls, "NAME", cls.__name__) - _LOGGER.debug("Registering %s", cls) - cls.REGISTERED_MODULES[name] = cls + # We only want to register submodules in a modules package so that + # other classes can inherit from smartmodule and not be registered + if cls.__module__.split(".")[-2] == "modules": + _LOGGER.debug("Registering %s", cls) + cls.REGISTERED_MODULES[cls.__name__] = cls def _set_error(self, err: Exception | None): if err is None: