77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from app.ha.discovery import EntityRole, classify_entity, discover_entities
|
|
from app.ha.models import HaEntitySummary
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("entity", "role", "learnable"),
|
|
[
|
|
(
|
|
HaEntitySummary(
|
|
entity_id="sensor.temperature",
|
|
domain="sensor",
|
|
device_class="temperature",
|
|
state_class="measurement",
|
|
unit_of_measurement="°C",
|
|
),
|
|
EntityRole.MEASUREMENT,
|
|
True,
|
|
),
|
|
(
|
|
HaEntitySummary(
|
|
entity_id="binary_sensor.motion",
|
|
domain="binary_sensor",
|
|
device_class="motion",
|
|
),
|
|
EntityRole.BINARY_CONTEXT,
|
|
True,
|
|
),
|
|
(
|
|
HaEntitySummary(entity_id="person.simon", domain="person"),
|
|
EntityRole.CONTEXT,
|
|
True,
|
|
),
|
|
(
|
|
HaEntitySummary(entity_id="light.living_room", domain="light"),
|
|
EntityRole.ACTUATOR,
|
|
False,
|
|
),
|
|
(
|
|
HaEntitySummary(entity_id="camera.driveway", domain="camera"),
|
|
EntityRole.UNSUPPORTED,
|
|
False,
|
|
),
|
|
],
|
|
)
|
|
def test_classify_entity(
|
|
entity: HaEntitySummary,
|
|
role: EntityRole,
|
|
learnable: bool,
|
|
) -> None:
|
|
result = classify_entity(entity)
|
|
assert result.role is role
|
|
assert result.learnable is learnable
|
|
|
|
|
|
def test_discovery_filters_domain_and_learnable() -> None:
|
|
entities = [
|
|
HaEntitySummary(
|
|
entity_id="sensor.temperature",
|
|
domain="sensor",
|
|
device_class="temperature",
|
|
),
|
|
HaEntitySummary(entity_id="sensor.status", domain="sensor"),
|
|
HaEntitySummary(
|
|
entity_id="binary_sensor.motion",
|
|
domain="binary_sensor",
|
|
device_class="motion",
|
|
),
|
|
]
|
|
|
|
result = discover_entities(entities, domains={" SENSOR "}, learnable=True)
|
|
|
|
assert [item.entity_id for item in result] == ["sensor.temperature"]
|