Fix entity translations
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock
|
||||
|
||||
from custom_components.arkteos.binary_sensor import ArkteosConnectionBinarySensor
|
||||
@@ -28,6 +30,16 @@ def test_unique_id_is_stable() -> None:
|
||||
assert ArkteosConnectionBinarySensor(FakeClient()).unique_id == "arkteos_zuran4_connection"
|
||||
|
||||
|
||||
def test_connectivity_translation_is_present_and_specific() -> None:
|
||||
entity = ArkteosConnectionBinarySensor(FakeClient())
|
||||
french = json.loads(
|
||||
(Path(__file__).parents[1] / "custom_components" / "arkteos" / "translations" / "fr.json").read_text()
|
||||
)
|
||||
assert entity.has_entity_name
|
||||
assert entity.translation_key == "connectivity"
|
||||
assert french["entity"]["binary_sensor"]["connectivity"]["name"] == "Connexion"
|
||||
|
||||
|
||||
def test_device_info_is_correct() -> None:
|
||||
info = ArkteosConnectionBinarySensor(FakeClient()).device_info
|
||||
assert info["identifiers"] == {(DOMAIN, "arkteos_zuran4")}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock
|
||||
|
||||
@@ -89,6 +90,31 @@ def test_total_sensor_count_and_unique_ids() -> None:
|
||||
sensors = _sensors(FakeClient())
|
||||
assert len(sensors) == 32
|
||||
assert len({sensor.unique_id for sensor in sensors}) == len(sensors)
|
||||
assert {sensor.unique_id for sensor in sensors} == {
|
||||
f"arkteos_zuran4_{description.key}" for description in SENSOR_DESCRIPTIONS
|
||||
}
|
||||
|
||||
|
||||
def test_sensor_translation_keys_are_specific_and_translated() -> None:
|
||||
translations_path = Path(__file__).parents[1] / "custom_components" / "arkteos" / "translations"
|
||||
french_sensors = json.loads((translations_path / "fr.json").read_text())["entity"]["sensor"]
|
||||
english_sensors = json.loads((translations_path / "en.json").read_text())["entity"]["sensor"]
|
||||
translation_keys = [description.translation_key for description in SENSOR_DESCRIPTIONS]
|
||||
|
||||
assert all(translation_keys)
|
||||
assert len(translation_keys) == len(set(translation_keys))
|
||||
assert set(translation_keys) == set(french_sensors) == set(english_sensors)
|
||||
assert all("name" in french_sensors[key] for key in translation_keys)
|
||||
assert all("name" in english_sensors[key] for key in translation_keys)
|
||||
assert not {"Temperature", "Power", "Frequency", "Duration", "Pressure", "Voltage", "Volume flow rate"} & {
|
||||
english_sensors[key]["name"] for key in translation_keys
|
||||
}
|
||||
|
||||
|
||||
def test_entities_expose_their_description_translation_key() -> None:
|
||||
sensors = _sensors(FakeClient())
|
||||
assert all(sensor.has_entity_name for sensor in sensors)
|
||||
assert all(sensor.translation_key == sensor.entity_description.translation_key for sensor in sensors)
|
||||
|
||||
|
||||
def test_all_node_red_keys_are_described() -> None:
|
||||
|
||||
Reference in New Issue
Block a user