Skip to content

Commit 79ccc39

Browse files
authored
Auto-convert dicts to EventState in Event (#2061)
## Summary - Adds `__attrs_post_init__` to `Event` that auto-converts dicts in `device_states` to `EventState` objects - Consumers constructing `Event` directly (e.g. in tests) no longer need to manually wrap dicts as `EventState(**state)` - Existing cattrs structuring path is unaffected ## Test plan - [x] All 438 existing tests pass - [x] Verified direct construction with dicts works: `Event(name=..., device_states=[{"name": "...", "type": 3, "value": "open"}])` - [x] Verified passing `EventState` objects directly still works - [x] Pre-commit hooks pass (ruff, mypy, ty)
1 parent d8414e6 commit 79ccc39

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

pyoverkiz/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,12 @@ class Event:
570570
gateway_id: str | None = field(repr=obfuscate_id, default=None)
571571
exec_id: str | None = None
572572
device_url: str | None = field(repr=obfuscate_id, default=None)
573-
device_states: list[EventState] = field(factory=list)
573+
device_states: list[EventState] = field(
574+
factory=list,
575+
converter=lambda states: [
576+
EventState(**s) if isinstance(s, dict) else s for s in states
577+
],
578+
)
574579
old_state: ExecutionState | None = None
575580
new_state: ExecutionState | None = None
576581
actions: list[Action] | None = None

0 commit comments

Comments
 (0)