Skip to content

Commit

Permalink
🔧 fix blocking call (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Nov 6, 2024
1 parent 4abc346 commit afcb248
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 3 additions & 1 deletion custom_components/xiaomi_miot/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down
8 changes: 2 additions & 6 deletions custom_components/xiaomi_miot/system_health.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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),
Expand Down

0 comments on commit afcb248

Please sign in to comment.