initial conversion of automation
This commit is contained in:
1 parent
12b4ff6615
commit
47af2fccff
7 files changed
+310
-11
No files matched your search
@@ -1,5 +1,13 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from src.config.AutomationLoader import (
|
||||
AutomationActionNode,
|
||||
AutomationConditionNode,
|
||||
AutomationData,
|
||||
AutomationMetdata,
|
||||
load_automation,
|
||||
_parse_conditions,
|
||||
)
|
||||
from src.json_serializer import NOT_IMPLEMENTED_SV_MSG
|
||||
from src.config.HassSafeConstructor import SecretValue, load_hass_config, IncludedYaml
|
||||
from tests.utils import SAMPLE_HA_PATH
|
||||
|
||||
@@ -16,3 +24,86 @@ class config_finder_tests(TestCase):
|
||||
config["automation"].data[32]["trigger"][0]["device_id"],
|
||||
SecretValue("baby_btn_device_id", "347492ffc6b909a55ebe08745fca1bf6"),
|
||||
)
|
||||
|
||||
def test_various_condition_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_conditions(raw_conditions)
|
||||
):
|
||||
self.assertEqual(parsed, expected)
|
||||
|
||||
def test_automation_loader(self):
|
||||
auto = list(
|
||||
load_automation(
|
||||
[
|
||||
{
|
||||
"id": "1616887975473",
|
||||
"alias": "Home Assistant Off",
|
||||
"description": "",
|
||||
"trigger": [{"platform": "homeassistant", "event": "shutdown"}],
|
||||
"condition": ["states(time.time) >= '10:00:00'"],
|
||||
"action": [
|
||||
{
|
||||
"device_id": SecretValue("my_mobile_phone", "..."),
|
||||
"domain": "mobile_app",
|
||||
"type": "notify",
|
||||
"title": "Hassio Status",
|
||||
"message": "Hassio Is turning off...",
|
||||
}
|
||||
],
|
||||
"mode": "single",
|
||||
}
|
||||
]
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
auto[0],
|
||||
AutomationData(
|
||||
metadata=AutomationMetdata(
|
||||
id="1616887975473",
|
||||
alias="Home Assistant Off",
|
||||
description="",
|
||||
mode="single",
|
||||
),
|
||||
trigger=[{"platform": "homeassistant", "event": "shutdown"}],
|
||||
condition=[
|
||||
AutomationConditionNode(
|
||||
condition="template",
|
||||
condition_data={
|
||||
"value_template": "states(time.time) >= '10:00:00'"
|
||||
},
|
||||
)
|
||||
],
|
||||
action=[
|
||||
AutomationActionNode(
|
||||
action="device",
|
||||
action_data={
|
||||
"device_id": NOT_IMPLEMENTED_SV_MSG,
|
||||
"domain": "mobile_app",
|
||||
"type": "notify",
|
||||
"title": "Hassio Status",
|
||||
"message": "Hassio Is turning off...",
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -71,8 +71,10 @@ class hass_db_tests(TestCase):
|
||||
"sensor.battery_wleak_kitchen",
|
||||
]
|
||||
for entity in entities.search(
|
||||
db, search_text="kitchen", attributes_filter={"state_class": "measurement"}
|
||||
db,
|
||||
search_text="kitchen",
|
||||
attributes_filter={"state_class": "sureme"},
|
||||
):
|
||||
self.assertTrue(expected.count(entity.entity_id) > 0)
|
||||
self.assertEqual(entity.domain, "sensor")
|
||||
self.assertEqual(entity.attributes["state_class"], "sureme")
|
||||
self.assertEqual(entity.attributes["state_class"], "measurement")
|
||||
@@ -0,0 +1,31 @@
|
||||
import json
|
||||
from unittest import TestCase
|
||||
from src.config.HassSafeConstructor import SecretValue
|
||||
from src.json_serializer import json_dumps, NOT_IMPLEMENTED_SV_MSG
|
||||
|
||||
|
||||
class json_serializer_tests(TestCase):
|
||||
def test_convert_secret_value(self):
|
||||
self.assertEqual(
|
||||
json_dumps(
|
||||
{
|
||||
"int": 1,
|
||||
"float": 1.3,
|
||||
"bool": False,
|
||||
"list": [1, "w"],
|
||||
"tup": (1, "w"),
|
||||
"some": {"deep": {"obj": SecretValue("super", "sec")}},
|
||||
}
|
||||
),
|
||||
json.dumps(
|
||||
{
|
||||
"int": 1,
|
||||
"float": 1.3,
|
||||
"bool": False,
|
||||
"list": [1, "w"],
|
||||
"tup": (1, "w"),
|
||||
"some": {"deep": {"obj": NOT_IMPLEMENTED_SV_MSG}},
|
||||
},
|
||||
separators=(",", ":"),
|
||||
),
|
||||
)
|
||||
Reference in new issue
Block a user