2017-02-16 03:47:30 +00:00
|
|
|
"""Test the entity values helper."""
|
|
|
|
from collections import OrderedDict
|
2019-12-09 15:52:24 +00:00
|
|
|
|
2017-02-16 03:47:30 +00:00
|
|
|
from homeassistant.helpers.entity_values import EntityValues as EV
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ent = "test.test"
|
2017-02-16 03:47:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_override_single_value():
|
|
|
|
"""Test values with exact match."""
|
2019-07-31 19:25:30 +00:00
|
|
|
store = EV({ent: {"key": "value"}})
|
|
|
|
assert store.get(ent) == {"key": "value"}
|
2017-02-16 03:47:30 +00:00
|
|
|
assert len(store._cache) == 1
|
2019-07-31 19:25:30 +00:00
|
|
|
assert store.get(ent) == {"key": "value"}
|
2017-02-16 03:47:30 +00:00
|
|
|
assert len(store._cache) == 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_override_by_domain():
|
|
|
|
"""Test values with domain match."""
|
2019-07-31 19:25:30 +00:00
|
|
|
store = EV(domain={"test": {"key": "value"}})
|
|
|
|
assert store.get(ent) == {"key": "value"}
|
2017-02-16 03:47:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_override_by_glob():
|
|
|
|
"""Test values with glob match."""
|
2019-07-31 19:25:30 +00:00
|
|
|
store = EV(glob={"test.?e*": {"key": "value"}})
|
|
|
|
assert store.get(ent) == {"key": "value"}
|
2017-02-16 03:47:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_glob_overrules_domain():
|
|
|
|
"""Test domain overrules glob match."""
|
2019-07-31 19:25:30 +00:00
|
|
|
store = EV(domain={"test": {"key": "domain"}}, glob={"test.?e*": {"key": "glob"}})
|
|
|
|
assert store.get(ent) == {"key": "glob"}
|
2017-02-16 03:47:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_exact_overrules_domain():
|
|
|
|
"""Test exact overrules domain match."""
|
|
|
|
store = EV(
|
2019-07-31 19:25:30 +00:00
|
|
|
exact={"test.test": {"key": "exact"}},
|
|
|
|
domain={"test": {"key": "domain"}},
|
|
|
|
glob={"test.?e*": {"key": "glob"}},
|
|
|
|
)
|
|
|
|
assert store.get(ent) == {"key": "exact"}
|
2017-02-16 03:47:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_merging_values():
|
|
|
|
"""Test merging glob, domain and exact configs."""
|
|
|
|
store = EV(
|
2019-07-31 19:25:30 +00:00
|
|
|
exact={"test.test": {"exact_key": "exact"}},
|
|
|
|
domain={"test": {"domain_key": "domain"}},
|
|
|
|
glob={"test.?e*": {"glob_key": "glob"}},
|
|
|
|
)
|
2017-02-16 03:47:30 +00:00
|
|
|
assert store.get(ent) == {
|
2019-07-31 19:25:30 +00:00
|
|
|
"exact_key": "exact",
|
|
|
|
"domain_key": "domain",
|
|
|
|
"glob_key": "glob",
|
2017-02-16 03:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def test_glob_order():
|
|
|
|
"""Test merging glob, domain and exact configs."""
|
|
|
|
glob = OrderedDict()
|
2019-07-31 19:25:30 +00:00
|
|
|
glob["test.*est"] = {"value": "first"}
|
|
|
|
glob["test.*"] = {"value": "second"}
|
2017-02-16 03:47:30 +00:00
|
|
|
|
|
|
|
store = EV(glob=glob)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert store.get(ent) == {"value": "second"}
|