From afcb248ae3c08c453a860f7a238d2336feeb6acf Mon Sep 17 00:00:00 2001 From: Alone Date: Wed, 6 Nov 2024 15:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix=20blocking=20call=20(#1694)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/xiaomi_miot/core/utils.py | 4 +++- custom_components/xiaomi_miot/system_health.py | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/custom_components/xiaomi_miot/core/utils.py b/custom_components/xiaomi_miot/core/utils.py index cc7de7b0d..75f2734ff 100644 --- a/custom_components/xiaomi_miot/core/utils.py +++ b/custom_components/xiaomi_miot/core/utils.py @@ -16,6 +16,8 @@ def get_manifest(field=None, default=None): manifest = json.load(fil) or {} return manifest.get(field, default) if field else manifest +async def async_get_manifest(hass: HomeAssistant, field=None, default=None): + return await hass.async_add_executor_job(get_manifest, field, default) def local_zone(hass=None): try: @@ -93,7 +95,7 @@ async def async_analytics_track_event(hass: HomeAssistant, event, action, label, 'value': value, 'locale': locale.getdefaultlocale()[0], 'tz': hass.config.time_zone, - 'ver': get_manifest('version', ''), + 'ver': await async_get_manifest(hass, 'version', ''), **kwargs, } url = 'https://hacc.miot-spec.com/api/track' diff --git a/custom_components/xiaomi_miot/system_health.py b/custom_components/xiaomi_miot/system_health.py index d63c0e26f..ee53f5a53 100644 --- a/custom_components/xiaomi_miot/system_health.py +++ b/custom_components/xiaomi_miot/system_health.py @@ -1,12 +1,8 @@ """Provide info to system health.""" -import os -import json - from homeassistant.components import system_health from homeassistant.core import HomeAssistant, callback -from .core.const import * -from .core.utils import get_manifest +from .core.utils import async_get_manifest from .core.xiaomi_cloud import MiotCloud @@ -30,7 +26,7 @@ async def system_health_info(hass): 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 hass.async_add_executor_job(get_manifest, 'version', 'unknown') + version = await async_get_manifest(hass, 'version', 'unknown') data = { 'component_version': version, 'can_reach_server': system_health.async_check_can_reach_url(hass, api),