mirror of
https://github.com/home-assistant/core.git
synced 2025-08-12 23:10:05 +00:00
.circleci
.github
docs
homeassistant
script
tests
auth
components
fixtures
helpers
__init__.py
test_aiohttp_client.py
test_area_registry.py
test_condition.py
test_config_entry_flow.py
test_config_validation.py
test_deprecation.py
test_device_registry.py
test_discovery.py
test_dispatcher.py
test_entity.py
test_entity_component.py
test_entity_platform.py
test_entity_registry.py
test_entity_values.py
test_entityfilter.py
test_event.py
test_icon.py
test_init.py
test_intent.py
test_json.py
test_location.py
test_restore_state.py
test_script.py
test_service.py
test_state.py
test_storage.py
test_sun.py
test_system_info.py
test_temperature.py
test_template.py
test_translation.py
mock
resources
scripts
test_util
testing_config
util
__init__.py
common.py
conftest.py
test_bootstrap.py
test_config.py
test_config_entries.py
test_core.py
test_data_entry_flow.py
test_loader.py
test_main.py
test_requirements.py
test_setup.py
virtualization
.codecov.yml
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hound.yml
.ignore
.readthedocs.yml
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE.md
MANIFEST.in
README.rst
mypy.ini
mypyrc
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
setup.cfg
setup.py
tox.ini
69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
"""Test the entity values helper."""
|
|
from collections import OrderedDict
|
|
from homeassistant.helpers.entity_values import EntityValues as EV
|
|
|
|
ent = 'test.test'
|
|
|
|
|
|
def test_override_single_value():
|
|
"""Test values with exact match."""
|
|
store = EV({ent: {'key': 'value'}})
|
|
assert store.get(ent) == {'key': 'value'}
|
|
assert len(store._cache) == 1
|
|
assert store.get(ent) == {'key': 'value'}
|
|
assert len(store._cache) == 1
|
|
|
|
|
|
def test_override_by_domain():
|
|
"""Test values with domain match."""
|
|
store = EV(domain={'test': {'key': 'value'}})
|
|
assert store.get(ent) == {'key': 'value'}
|
|
|
|
|
|
def test_override_by_glob():
|
|
"""Test values with glob match."""
|
|
store = EV(glob={'test.?e*': {'key': 'value'}})
|
|
assert store.get(ent) == {'key': 'value'}
|
|
|
|
|
|
def test_glob_overrules_domain():
|
|
"""Test domain overrules glob match."""
|
|
store = EV(
|
|
domain={'test': {'key': 'domain'}},
|
|
glob={'test.?e*': {'key': 'glob'}})
|
|
assert store.get(ent) == {'key': 'glob'}
|
|
|
|
|
|
def test_exact_overrules_domain():
|
|
"""Test exact overrules domain match."""
|
|
store = EV(
|
|
exact={'test.test': {'key': 'exact'}},
|
|
domain={'test': {'key': 'domain'}},
|
|
glob={'test.?e*': {'key': 'glob'}})
|
|
assert store.get(ent) == {'key': 'exact'}
|
|
|
|
|
|
def test_merging_values():
|
|
"""Test merging glob, domain and exact configs."""
|
|
store = EV(
|
|
exact={'test.test': {'exact_key': 'exact'}},
|
|
domain={'test': {'domain_key': 'domain'}},
|
|
glob={'test.?e*': {'glob_key': 'glob'}})
|
|
assert store.get(ent) == {
|
|
'exact_key': 'exact',
|
|
'domain_key': 'domain',
|
|
'glob_key': 'glob',
|
|
}
|
|
|
|
|
|
def test_glob_order():
|
|
"""Test merging glob, domain and exact configs."""
|
|
glob = OrderedDict()
|
|
glob['test.*est'] = {"value": "first"}
|
|
glob['test.*'] = {"value": "second"}
|
|
|
|
store = EV(glob=glob)
|
|
assert store.get(ent) == {
|
|
'value': 'second'
|
|
}
|