HEX
Server: Apache/2.4.63 (Unix)
System: Linux Synopilou92 4.4.302+ #72806 SMP Mon Jul 21 23:16:00 CST 2025 x86_64
User: pilou92 (1026)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: /volume1/docker/homeassistant2025/custom_components/xiaomi_miot/system_health.py
"""Provide info to system health."""
from homeassistant.components import system_health
from homeassistant.core import HomeAssistant, callback

from .core.utils import async_get_manifest
from .core.xiaomi_cloud import MiotCloud


@callback
def async_register(hass: HomeAssistant, register: system_health.SystemHealthRegistration) -> None:
    """Register system health callbacks."""
    register.async_register_info(system_health_info, '/config/integrations')


async def system_health_info(hass):
    """Get info for the info page."""
    mic = None
    uas = {}
    uds = {}
    all_devices = {}
    for mic in MiotCloud.all_clouds(hass):
        uas[mic.user_id] = mic
        uds[mic.unique_id] = await mic.async_get_devices_by_key('did') or {}
        all_devices.update(uds[mic.unique_id])

    api = mic.get_api_url('') if mic else 'https://api.io.mi.com'
    api_spec = 'https://miot-spec.org/miot-spec-v2/spec/services'

    version = await async_get_manifest(hass, 'version', 'unknown')
    data = {
        'component_version': version,
        'can_reach_server': system_health.async_check_can_reach_url(hass, api),
        'can_reach_spec': system_health.async_check_can_reach_url(
            hass, api_spec, 'https://home.miot-spec.com/?cant-reach',
        ),
        'logged_accounts': len(uas),
        'total_devices': len(all_devices),
    }

    return data