initial test for actions
This commit is contained in:
1 parent
5169cfbca9
commit
862ec58193
2 files changed
+28
-4
No files matched your search
@@ -64,11 +64,14 @@ def _parse_actions(
|
||||
raw_actions: Iterable[Union[dict, str]]
|
||||
) -> Iterable[Union[AutomationActionNode, AutomationConditionNode]]:
|
||||
for raw_c in raw_actions:
|
||||
action_type = "unknown"
|
||||
if isinstance(raw_c, str):
|
||||
yield from _parse_conditions([raw_c])
|
||||
continue
|
||||
elif isinstance(raw_c, dict):
|
||||
if raw_c.get("condition"):
|
||||
yield from _parse_conditions([raw_c])
|
||||
continue
|
||||
elif raw_c.get("service"):
|
||||
action_type = "service"
|
||||
elif raw_c.get("repeat"):
|
||||
@@ -81,10 +84,6 @@ def _parse_actions(
|
||||
action_type = "device"
|
||||
elif raw_c.get("choose"):
|
||||
action_type = "choose"
|
||||
else:
|
||||
action_type = "unknown"
|
||||
else:
|
||||
action_type = "unknown"
|
||||
yield AutomationActionNode(action=action_type, action_data=normalize_obj(raw_c))
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from src.config.AutomationLoader import (
|
||||
AutomationMetdata,
|
||||
load_automation,
|
||||
_parse_conditions,
|
||||
_parse_actions,
|
||||
)
|
||||
from src.json_serializer import NOT_IMPLEMENTED_SV_MSG
|
||||
from src.config.HassSafeConstructor import SecretValue, load_hass_config, IncludedYaml
|
||||
@@ -51,6 +52,30 @@ class config_finder_tests(TestCase):
|
||||
):
|
||||
self.assertEqual(parsed, expected)
|
||||
|
||||
def test_various_action_types(self):
|
||||
raw_conditions = [
|
||||
{"condition": "template", "value_template": "silly logic here"},
|
||||
"silly logic here",
|
||||
{"condition": "time", "after": "10:00:00", "weekday": ["mon", "tue"]},
|
||||
]
|
||||
expected_process = [
|
||||
AutomationConditionNode(
|
||||
condition="template",
|
||||
condition_data={"value_template": "silly logic here"},
|
||||
),
|
||||
AutomationConditionNode(
|
||||
condition="template",
|
||||
condition_data={"value_template": "silly logic here"},
|
||||
),
|
||||
AutomationConditionNode(
|
||||
condition="time",
|
||||
condition_data={"after": "10:00:00", "weekday": ["mon", "tue"]},
|
||||
),
|
||||
]
|
||||
|
||||
for parsed, expected in zip(expected_process, _parse_actions(raw_conditions)):
|
||||
self.assertEqual(parsed, expected)
|
||||
|
||||
def test_automation_loader(self):
|
||||
auto = list(
|
||||
load_automation(
|
||||
|
||||
Reference in new issue
Block a user