80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
from app.ha_client import normalize_entity
|
|
|
|
|
|
def test_normalize_entity_basic():
|
|
state = {
|
|
"entity_id": "light.salon",
|
|
"state": "on",
|
|
"attributes": {
|
|
"friendly_name": "Lumière Salon",
|
|
"device_class": "light",
|
|
},
|
|
"last_changed": "2026-01-01T00:00:00Z",
|
|
"last_updated": "2026-01-01T00:00:00Z",
|
|
}
|
|
result = normalize_entity(state)
|
|
|
|
assert result["entity_id"] == "light.salon"
|
|
assert result["domain"] == "light"
|
|
assert result["friendly_name"] == "Lumière Salon"
|
|
assert result["state"] == "on"
|
|
assert result["device_class"] == "light"
|
|
assert result["is_available"] is True
|
|
assert result["is_disabled"] is False
|
|
|
|
|
|
def test_normalize_entity_unavailable():
|
|
state = {
|
|
"entity_id": "sensor.temp",
|
|
"state": "unavailable",
|
|
"attributes": {},
|
|
}
|
|
result = normalize_entity(state)
|
|
|
|
assert result["is_available"] is False
|
|
assert result["domain"] == "sensor"
|
|
|
|
|
|
def test_normalize_entity_with_registry():
|
|
state = {
|
|
"entity_id": "switch.garage",
|
|
"state": "off",
|
|
"attributes": {"friendly_name": "Garage"},
|
|
}
|
|
registry = {
|
|
"entity_id": "switch.garage",
|
|
"area_id": "garage",
|
|
"device_id": "dev_123",
|
|
"platform": "esphome",
|
|
"disabled_by": None,
|
|
"hidden_by": "user",
|
|
}
|
|
result = normalize_entity(state, registry)
|
|
|
|
assert result["area_id"] == "garage"
|
|
assert result["device_id"] == "dev_123"
|
|
assert result["integration"] == "esphome"
|
|
assert result["is_disabled"] is False
|
|
assert result["is_hidden"] is True
|
|
|
|
|
|
def test_normalize_entity_disabled_in_registry():
|
|
state = {
|
|
"entity_id": "sensor.disabled",
|
|
"state": "unknown",
|
|
"attributes": {},
|
|
}
|
|
registry = {
|
|
"entity_id": "sensor.disabled",
|
|
"disabled_by": "user",
|
|
"hidden_by": None,
|
|
"area_id": None,
|
|
"device_id": None,
|
|
"platform": "mqtt",
|
|
}
|
|
result = normalize_entity(state, registry)
|
|
|
|
assert result["is_disabled"] is True
|
|
assert result["is_available"] is False
|
|
assert result["integration"] == "mqtt"
|