Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/ezmsg/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,32 @@ def __init__(
continue

if field_name == "SETTINGS":
if not issubclass(field_value, Settings):
logger.error(
f"{name} Settings must be a subclass of `ez.Settings`!"
if not (
(is_dataclass(field_value) and isinstance(field_value, type))
and getattr(
getattr(field_value, "__dataclass_params__", None),
"frozen",
False,
)
):
raise Exception(f"{name} Settings must be a frozen dataclass!")

for settings_type in base_settings_types:
if settings_type is Settings:
continue
if not issubclass(field_value, settings_type):
logger.error(
f"{name} Settings of type {field_value.__name__} must be a subclass of {settings_type.__name__}"
)
cls.__settings_type__ = field_value

if field_name == "STATE":
if not issubclass(field_value, State):
logger.error(f"{name} State must be a subclass of `ez.State`!")
elif field_name == "STATE":
if not (is_dataclass(field_value) and isinstance(field_value, type)):
raise Exception(f"{name} State must be a dataclass!")

for state_type in base_state_types:
if state_type is State:
continue
if not issubclass(field_value, state_type):
logger.error(
f"{name} State of type {field_value.__name__} must be a subclass of {state_type.__name__}"
Expand Down Expand Up @@ -105,8 +114,8 @@ class Component(Addressable, metaclass=ComponentMeta):
_main: Optional[Callable[..., None]]
_threads: Dict[str, Callable]

def __init__(self, *args, settings: Optional[Settings] = None, **kwargs):
super(Component, self).__init__()
def __init__(self, *args, settings: Optional[Any] = None, **kwargs):
super().__init__()

self.SETTINGS = None
self.STATE = None
Expand Down Expand Up @@ -155,7 +164,7 @@ def _check_state(self) -> None:
f"{self.address}: STATE.{field.name} was not initialized!"
)

def apply_settings(self, settings: Settings) -> None:
def apply_settings(self, settings: Any) -> None:
"""
Update the ``Component``‘s ``Settings`` object.

Expand Down