From f01a1b89f0c3142703557c54cfdf84b4d3288c84 Mon Sep 17 00:00:00 2001 From: PineappleEmperor Date: Wed, 7 May 2025 22:00:36 +0100 Subject: [PATCH] feat: added system health configuration to show connected status. --- custom_components/parcelapp/system_health.py | 26 +++++++++++++++++++ .../parcelapp/translations/en.json | 5 ++++ 2 files changed, 31 insertions(+) create mode 100644 custom_components/parcelapp/system_health.py diff --git a/custom_components/parcelapp/system_health.py b/custom_components/parcelapp/system_health.py new file mode 100644 index 0000000..c980845 --- /dev/null +++ b/custom_components/parcelapp/system_health.py @@ -0,0 +1,26 @@ +"""Provide info to system health.""" + +import os +from typing import Any + +from homeassistant.components import system_health +from homeassistant.core import HomeAssistant, callback +from .const import DOMAIN, PARCEL_URL +from .coordinator import ParcelConfigEntry + + +@callback +def async_register(hass: HomeAssistant, register: system_health.SystemHealthRegistration) -> None: + """Register system health callbacks.""" + register.async_register_info(system_health_info) + +async def system_health_info(hass: HomeAssistant) -> dict[str, Any]: + """Get info for the info page.""" + config_entry: ParcelConfigEntry = hass.config_entries.async_entries(DOMAIN)[0] + # quota_info = await config_entry.runtime_data.async_get_quota_info() + + return { + # "consumed_requests": quota_info.consumed_requests, + # "remaining_requests": quota_info.requests_remaining, + "can_reach_server": system_health.async_check_can_reach_url(hass, PARCEL_URL), + } \ No newline at end of file diff --git a/custom_components/parcelapp/translations/en.json b/custom_components/parcelapp/translations/en.json index bb6e517..6c64964 100644 --- a/custom_components/parcelapp/translations/en.json +++ b/custom_components/parcelapp/translations/en.json @@ -82,5 +82,10 @@ } } } + }, + "system_health": { + "info": { + "can_reach_server": "Reach Parcel server" + } } } \ No newline at end of file