handling missing ids better + more tranlsations

This commit is contained in:
ari committed 2022-09-01 17:21:00 -04:00
1 parent 69a9805c02
commit 774ebe482a
45 files changed
+556 -262

No files matched your search

+6 -2
View File
@@ -11,14 +11,18 @@ logger = get_logger(__file__)
class AutomationDBConnection:
def __init__(self) -> None:
self.db: dict[str, ExtenededAutomation] = {}
self.missing_id_db: list[ExtenededAutomation] = []
def reset(self):
self.db = {}
self.missing_id_db = []
def insert_automations(self, automations: list[ExtenededAutomation]):
repeated_automations = []
for automation in automations:
if self.db.get(automation.id, None) is None:
if automation.id is None:
self.missing_id_db.append(automation)
elif self.db.get(automation.id, None) is None:
self.db[automation.id] = automation
else:
repeated_automations.append(
@@ -33,7 +37,7 @@ class AutomationDBConnection:
raise DBNoAutomationFound(automation_id)
def list_automations(self, offset: int, limit: int) -> Iterable[ExtenededAutomation]:
for i, auto in enumerate(self.db.values()):
for i, auto in enumerate([*self.missing_id_db, *self.db.values()]):
if i >= offset and i < limit + offset:
yield auto
+12 -6
View File
@@ -236,9 +236,11 @@ def load_automation_inline_ref(
) -> Iterator[ExtenededAutomation]:
for auto in inline_automation.automations:
try:
cleaned_automation = clean_automation(auto)
automation_id = cleaned_automation.get("id", None)
yield ExtenededAutomation(
**clean_automation(auto),
tags=tag_manager.get(auto["id"], {}),
**cleaned_automation,
tags={} if automation_id is None else tag_manager.get(automation_id, {}),
configuration_key=inline_automation.configuration_key,
source_file=str(inline_automation.source_file.resolve().relative_to(root_path)),
source_file_type="inline",
@@ -286,9 +288,11 @@ def load_automation_path(
if isinstance(automations, dict):
try:
cleaned_automation = clean_automation(automations)
automation_id = cleaned_automation.get("id", None)
yield ExtenededAutomation(
**clean_automation(automations),
tags=tag_manager.get(automations["id"], {}),
**cleaned_automation,
tags={} if automation_id is None else tag_manager.get(automation_id, {}),
configuration_key=configuration_key,
source_file=str(automation_path.resolve().relative_to(root_path)),
source_file_type="obj",
@@ -305,9 +309,11 @@ def load_automation_path(
return
for automation in automations:
try:
cleaned_automation = clean_automation(automation)
automation_id = cleaned_automation.get("id", None)
yield ExtenededAutomation(
**clean_automation(automation),
tags=tag_manager.get(automation["id"], {}),
**cleaned_automation,
tags={} if automation_id is None else tag_manager.get(automation_id, {}),
configuration_key=configuration_key,
source_file=str(automation_path.resolve().relative_to(root_path)),
source_file_type="list",
+1 -1
View File
@@ -32,7 +32,7 @@ AutomationExtractedIter = Iterator[ExtractedAutomation]
class BaseAutomation(BaseModel):
id: str
id: Optional[str]
alias: Optional[str] = None
description: Optional[str] = None
trigger_variables: Optional[dict[str, Union[str, int, bool, float]]] = None