refactor + cleanup
This commit is contained in:
1 parent
4a08956e1a
commit
381835c642
34 files changed
+724
-933
No files matched your search
@@ -0,0 +1,33 @@
|
||||
from itertools import chain
|
||||
from typing import Iterable
|
||||
from src.json_serializer import normalize_obj
|
||||
from .types import AutomationData, AutomationMetdata
|
||||
from .parsers import _parse_actions
|
||||
|
||||
# Single loader
|
||||
def load_automation(
|
||||
automations_raw_data: Iterable[dict],
|
||||
) -> Iterable[AutomationData]:
|
||||
"""Converts an automation dictionary loaded directly from the config into
|
||||
several python typed objects
|
||||
|
||||
Args:
|
||||
automations_raw_data (Iterable[dict])
|
||||
|
||||
Returns:
|
||||
Iterable[AutomationData]
|
||||
|
||||
"""
|
||||
for auto_raw in automations_raw_data:
|
||||
yield AutomationData(
|
||||
metadata=AutomationMetdata.parse_obj(auto_raw),
|
||||
sequence=list(
|
||||
_parse_actions(
|
||||
chain(
|
||||
auto_raw.get("condition", []),
|
||||
auto_raw.get("action", []),
|
||||
)
|
||||
)
|
||||
),
|
||||
trigger=[normalize_obj(obj) for obj in auto_raw.get("trigger", [])],
|
||||
)
|
||||
Reference in new issue
Block a user