Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project are documented here. The format follows [Kee

### Changed

- Every sensor, binary sensor and event entity now has a fitting icon instead of Home Assistant's default eye. The CI state, the last workflow result and the "workflow running" sensor change their icon with their state, and custom query sensors use a code icon.
- Repositories are now requested in batches of 10 instead of 50, so the first refresh of a long repository list no longer risks running into Home Assistant's startup limits.
- When GitHub fails for one batch of repositories (for example with a 502), the other batches are still updated and the affected repositories keep their last values, instead of every repository sensor turning unavailable.

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ To replace the token, open the integration, choose **Reconfigure** and enter the
| 🧪 | Custom queries | Your own read-only GraphQL query as a sensor, added under **Add custom query**. Rendered with templates over `value_json`. Presets included; see the [guide](docs/custom-queries.md) |
| ➕ | Optional sensors | Reviews, issues, active days, strongest weekday, watchers, release downloads, days since last commit or release, pull requests awaiting your review, most active hour and night-owl score (approximate, from GitHub's last 300 events), average time to merge (last 50 merged pull requests), stale pull requests (open, untouched for 14 days), year in review (one-line summary with the details as attributes), followers and following counts, repository traffic (unique visitors and cloners and page views and clones over the last 14 days, peak visitor day, top referrer and page, visitor trend, cloners per visitor; needs write access, see [Access token](#-access-token)) |

Every entity has its own icon. The CI state, the last workflow result and the "workflow running" binary sensor change their icon with their state, and custom query sensors use a code icon. You can still override any icon per entity in Home Assistant.

Everything marked optional is created disabled. GitHub Pulse only fetches data that an enabled entity needs, so unused sensors cost no API calls.

> [!NOTE]
Expand Down
91 changes: 91 additions & 0 deletions custom_components/github_pulse/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"entity": {
"sensor": {
"followers": {"default": "mdi:account-multiple"},
"following": {"default": "mdi:account-arrow-right"},
"contributions_this_month": {"default": "mdi:source-commit"},
"commits_this_month": {"default": "mdi:source-commit"},
"pull_requests_this_month": {"default": "mdi:source-pull"},
"commits_vs_last_month": {"default": "mdi:chart-line-variant"},
"commits_vs_last_year": {"default": "mdi:chart-timeline-variant"},
"busiest_month": {"default": "mdi:calendar-star"},
"current_streak": {"default": "mdi:fire"},
"longest_streak": {"default": "mdi:trophy-outline"},
"reviews_this_month": {"default": "mdi:eye-check-outline"},
"issues_this_month": {"default": "mdi:alert-circle-outline"},
"active_days_this_month": {"default": "mdi:calendar-check"},
"most_productive_weekday": {"default": "mdi:calendar-week"},
"most_active_hour": {"default": "mdi:clock-outline"},
"night_owl_score": {"default": "mdi:owl"},
"average_time_to_merge": {"default": "mdi:source-merge"},
"stale_pull_requests": {"default": "mdi:timer-sand"},
"year_in_review": {"default": "mdi:calendar-text"},
"top_language": {"default": "mdi:code-tags"},
"language_shift": {"default": "mdi:swap-horizontal"},
"review_requests": {"default": "mdi:account-eye-outline"},
"authored_open_pull_requests": {"default": "mdi:source-branch"},
"stars": {"default": "mdi:star-outline"},
"forks": {"default": "mdi:source-fork"},
"open_issues": {"default": "mdi:alert-circle-outline"},
"open_pull_requests": {"default": "mdi:source-pull"},
"latest_release": {"default": "mdi:tag-outline"},
"watchers": {"default": "mdi:bell-outline"},
"latest_release_downloads": {"default": "mdi:download-circle-outline"},
"total_downloads": {"default": "mdi:download-multiple"},
"days_since_last_commit": {"default": "mdi:source-commit"},
"days_since_last_release": {"default": "mdi:tag-text-outline"},
"last_push": {"default": "mdi:cloud-upload-outline"},
"ci_state": {
"default": "mdi:check-network-outline",
"state": {
"success": "mdi:check-circle-outline",
"failure": "mdi:close-circle-outline",
"pending": "mdi:progress-clock",
"error": "mdi:alert-circle-outline",
"expected": "mdi:clock-outline"
}
},
"unique_visitors_14d": {"default": "mdi:account-group-outline"},
"views_14d": {"default": "mdi:eye-outline"},
"unique_cloners_14d": {"default": "mdi:account-arrow-down-outline"},
"clones_14d": {"default": "mdi:content-copy"},
"peak_visitor_day": {"default": "mdi:calendar-arrow-right"},
"top_referrer": {"default": "mdi:link-variant"},
"top_path": {"default": "mdi:file-document-outline"},
"visitor_trend": {"default": "mdi:trending-up"},
"clone_visitor_ratio": {"default": "mdi:percent-outline"},
"actions_last_result": {
"default": "mdi:play-circle-outline",
"state": {
"success": "mdi:check-circle-outline",
"failure": "mdi:close-circle-outline",
"cancelled": "mdi:cancel",
"skipped": "mdi:skip-next-circle-outline",
"timed_out": "mdi:timer-off-outline",
"neutral": "mdi:minus-circle-outline",
"action_required": "mdi:alert-circle-outline",
"stale": "mdi:history",
"startup_failure": "mdi:alert-octagon-outline"
}
},
"actions_runs_today": {"default": "mdi:play-box-multiple-outline"},
"actions_queued_runs": {"default": "mdi:tray-full"},
"actions_failure_rate_7d": {"default": "mdi:alert-decagram-outline"},
"actions_failure_rate_30d": {"default": "mdi:alert-decagram-outline"},
"actions_average_duration": {"default": "mdi:timer-outline"}
},
"binary_sensor": {
"actions_running": {
"default": "mdi:cog-pause-outline",
"state": {
"on": "mdi:cog-sync-outline",
"off": "mdi:cog-pause-outline"
}
}
},
"event": {
"repository_events": {"default": "mdi:bell-ring-outline"},
"account_events": {"default": "mdi:source-pull"}
}
}
}
1 change: 1 addition & 0 deletions custom_components/github_pulse/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def __init__(self, coordinator: QueryCoordinator) -> None:
self._attr_device_info = None
data = subentry.data
self._attr_name = subentry.title
self._attr_icon = "mdi:code-braces"
self._attr_native_unit_of_measurement = data.get(CONF_UNIT) or None
if device_class := data.get(CONF_DEVICE_CLASS):
self._attr_device_class = SensorDeviceClass(device_class)
Expand Down
75 changes: 75 additions & 0 deletions tests/test_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Every entity the integration describes carries an icon."""

from __future__ import annotations

import json
from pathlib import Path
from typing import Any

import pytest

PACKAGE = Path(__file__).parents[1] / "custom_components/github_pulse"
STATE_ICON_KEYS = {
("sensor", "ci_state"),
("sensor", "actions_last_result"),
("binary_sensor", "actions_running"),
}


def _load(name: str) -> dict[str, Any]:
return json.loads((PACKAGE / name).read_text())["entity"]


@pytest.fixture(scope="module")
def icons() -> dict[str, Any]:
return _load("icons.json")


@pytest.fixture(scope="module")
def entities() -> dict[str, Any]:
return _load("translations/en.json")


def _icon_strings(definition: dict[str, Any]) -> list[str]:
return [definition["default"], *definition.get("state", {}).values()]


def test_every_translated_entity_has_an_icon(
icons: dict[str, Any], entities: dict[str, Any]
) -> None:
for platform, keys in entities.items():
assert set(keys) <= set(icons.get(platform, {})), platform


def test_icons_describe_no_unknown_entity(
icons: dict[str, Any], entities: dict[str, Any]
) -> None:
for platform, keys in icons.items():
assert set(keys) <= set(entities.get(platform, {})), platform


def test_every_icon_is_a_material_design_icon(icons: dict[str, Any]) -> None:
for keys in icons.values():
for definition in keys.values():
assert all(icon.startswith("mdi:") for icon in _icon_strings(definition))


def test_no_entity_falls_back_to_the_default_eye(icons: dict[str, Any]) -> None:
eyes = {
key
for keys in icons.values()
for key, definition in keys.items()
if "mdi:eye" in _icon_strings(definition)
}
assert eyes == set()


def test_state_icons_cover_every_option(
icons: dict[str, Any], entities: dict[str, Any]
) -> None:
for platform, key in STATE_ICON_KEYS:
states = icons[platform][key]["state"]
if platform == "binary_sensor":
assert set(states) == {"on", "off"}
else:
assert set(states) == set(entities[platform][key]["state"])
1 change: 1 addition & 0 deletions tests/test_query_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ async def test_the_sensor_shows_the_rendered_result(
assert state.attributes["login"] == "octocat"
assert state.attributes["unit_of_measurement"] == "repos"
assert state.attributes["state_class"] == "measurement"
assert state.attributes["icon"] == "mdi:code-braces"


async def test_device_class_is_applied(
Expand Down
Loading