From 23353812a93d711097be22d83dd6a31c169ed17c Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 20 Mar 2024 07:06:34 +0100 Subject: [PATCH] Add icon translations to Github (#111614) * Add icon translations to Github * Fix --- homeassistant/components/github/icons.json | 42 ++++++++++++++++++++++ homeassistant/components/github/sensor.py | 5 +-- tests/components/github/test_init.py | 23 ++++++++++-- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 homeassistant/components/github/icons.json diff --git a/homeassistant/components/github/icons.json b/homeassistant/components/github/icons.json new file mode 100644 index 00000000000..f8a2eefe0c8 --- /dev/null +++ b/homeassistant/components/github/icons.json @@ -0,0 +1,42 @@ +{ + "entity": { + "sensor": { + "discussions_count": { + "default": "mdi:forum" + }, + "stargazers_count": { + "default": "mdi:star" + }, + "subscribers_count": { + "default": "mdi:glasses" + }, + "forks_count": { + "default": "mdi:source-fork" + }, + "issues_count": { + "default": "mdi:github" + }, + "pulls_count": { + "default": "mdi:source-pull" + }, + "latest_commit": { + "default": "mdi:source-commit" + }, + "latest_discussion": { + "default": "mdi:forum" + }, + "latest_release": { + "default": "mdi:github" + }, + "latest_issue": { + "default": "mdi:github" + }, + "latest_pull_request": { + "default": "mdi:source-pull" + }, + "latest_tag": { + "default": "mdi:tag" + } + } + } +} diff --git a/homeassistant/components/github/sensor.py b/homeassistant/components/github/sensor.py index a0e38862471..a082f888767 100644 --- a/homeassistant/components/github/sensor.py +++ b/homeassistant/components/github/sensor.py @@ -28,7 +28,7 @@ class GitHubSensorEntityDescription(SensorEntityDescription): """Describes GitHub issue sensor entity.""" value_fn: Callable[[dict[str, Any]], StateType] - icon: str = "mdi:github" + attr_fn: Callable[[dict[str, Any]], Mapping[str, Any] | None] = lambda data: None avabl_fn: Callable[[dict[str, Any]], bool] = lambda data: True @@ -45,7 +45,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = ( GitHubSensorEntityDescription( key="stargazers_count", translation_key="stargazers_count", - icon="mdi:star", native_unit_of_measurement="Stars", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -54,7 +53,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = ( GitHubSensorEntityDescription( key="subscribers_count", translation_key="subscribers_count", - icon="mdi:glasses", native_unit_of_measurement="Watchers", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, @@ -63,7 +61,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = ( GitHubSensorEntityDescription( key="forks_count", translation_key="forks_count", - icon="mdi:source-fork", native_unit_of_measurement="Forks", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, diff --git a/tests/components/github/test_init.py b/tests/components/github/test_init.py index a25e27df835..c97a940b05c 100644 --- a/tests/components/github/test_init.py +++ b/tests/components/github/test_init.py @@ -4,7 +4,7 @@ import pytest from homeassistant.components.github import CONF_REPOSITORIES from homeassistant.core import HomeAssistant -from homeassistant.helpers import device_registry as dr +from homeassistant.helpers import device_registry as dr, entity_registry as er, icon from .common import setup_github_integration @@ -21,7 +21,7 @@ async def test_device_registry_cleanup( aioclient_mock: AiohttpClientMocker, caplog: pytest.LogCaptureFixture, ) -> None: - """Test that we remove untracked repositories from the decvice registry.""" + """Test that we remove untracked repositories from the device registry.""" mock_config_entry.add_to_hass(hass) hass.config_entries.async_update_entry( mock_config_entry, @@ -113,3 +113,22 @@ async def test_subscription_setup_polling_disabled( "https://api.github.com/repos/home-assistant/core/events" in x[1] for x in aioclient_mock.mock_calls ) + + +# This tests needs to be adjusted to remove lingering tasks +@pytest.mark.parametrize("expected_lingering_tasks", [True]) +async def test_sensor_icons( + hass: HomeAssistant, + init_integration: MockConfigEntry, + entity_registry: er.EntityRegistry, +) -> None: + """Test to ensure that all sensor entities have an icon definition.""" + entities = er.async_entries_for_config_entry( + entity_registry, + config_entry_id=init_integration.entry_id, + ) + + icons = await icon.async_get_icons(hass, "entity", integrations=["github"]) + for entity in entities: + assert entity.translation_key is not None + assert icons["github"]["sensor"][entity.translation_key] is not None