-
Notifications
You must be signed in to change notification settings - Fork 57
feat: log when we see a new key we have never seen before #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| from dataclasses import asdict, dataclass, field | ||
| from enum import Enum | ||
| from functools import cached_property | ||
| from typing import Any, NamedTuple, get_args, get_origin | ||
| from typing import Any, ClassVar, NamedTuple, get_args, get_origin | ||
|
|
||
| from .code_mappings import ( | ||
| SHORT_MODEL_TO_ENUM, | ||
|
|
@@ -64,6 +64,8 @@ def _attr_repr(obj: Any) -> str: | |
| class RoborockBase: | ||
| """Base class for all Roborock data classes.""" | ||
|
|
||
| _missing_logged: ClassVar[set[str]] = set() | ||
|
|
||
| @staticmethod | ||
| def _convert_to_class_obj(class_type: type, value): | ||
| if get_origin(class_type) is list: | ||
|
|
@@ -93,6 +95,14 @@ def from_dict(cls, data: dict[str, Any]): | |
| for orig_key, value in data.items(): | ||
| key = _decamelize(orig_key) | ||
| if (field_type := field_types.get(key)) is None: | ||
| if (log_key := f"{cls.__name__}.{key}") not in RoborockBase._missing_logged: | ||
| _LOGGER.debug( | ||
| "Key '%s' (decamelized: '%s') not found in %s fields, skipping", | ||
| orig_key, | ||
| key, | ||
| cls.__name__, | ||
| ) | ||
| RoborockBase._missing_logged.add(log_key) | ||
|
Comment on lines
+98
to
+105
|
||
| continue | ||
| if value == "None" or value is None: | ||
| result[key] = None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shared class variable
_missing_loggedis not thread-safe. Iffrom_dictis called concurrently from multiple threads, race conditions could occur when checking membership and adding to the set. Consider using athreading.Lockor a thread-safe alternative likethreading.RLock()to protect access to this shared state, or use a thread-safe data structure.