mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Fix blocking I/O in the event loop to get MacOS system_info (#117290)
* Fix blocking I/O in the event look to get MacOS system_info * split pr * Update homeassistant/helpers/system_info.py Co-authored-by: Jan-Philipp Benecke <jan-philipp@bnck.me> * Update homeassistant/helpers/system_info.py --------- Co-authored-by: Jan-Philipp Benecke <jan-philipp@bnck.me>
This commit is contained in:
parent
65a4e5a1af
commit
f318a3b5e2
@ -15,9 +15,12 @@ from homeassistant.loader import bind_hass
|
|||||||
from homeassistant.util.package import is_docker_env, is_virtual_env
|
from homeassistant.util.package import is_docker_env, is_virtual_env
|
||||||
|
|
||||||
from .importlib import async_import_module
|
from .importlib import async_import_module
|
||||||
|
from .singleton import singleton
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
_DATA_MAC_VER = "system_info_mac_ver"
|
||||||
|
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def is_official_image() -> bool:
|
def is_official_image() -> bool:
|
||||||
@ -25,6 +28,12 @@ def is_official_image() -> bool:
|
|||||||
return os.path.isfile("/OFFICIAL_IMAGE")
|
return os.path.isfile("/OFFICIAL_IMAGE")
|
||||||
|
|
||||||
|
|
||||||
|
@singleton(_DATA_MAC_VER)
|
||||||
|
async def async_get_mac_ver(hass: HomeAssistant) -> str:
|
||||||
|
"""Return the macOS version."""
|
||||||
|
return (await hass.async_add_executor_job(platform.mac_ver))[0]
|
||||||
|
|
||||||
|
|
||||||
# Cache the result of getuser() because it can call getpwuid() which
|
# Cache the result of getuser() because it can call getpwuid() which
|
||||||
# can do blocking I/O to look up the username in /etc/passwd.
|
# can do blocking I/O to look up the username in /etc/passwd.
|
||||||
cached_get_user = cache(getuser)
|
cached_get_user = cache(getuser)
|
||||||
@ -65,7 +74,7 @@ async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
|
|||||||
info_object["user"] = None
|
info_object["user"] = None
|
||||||
|
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
info_object["os_version"] = platform.mac_ver()[0]
|
info_object["os_version"] = await async_get_mac_ver(hass)
|
||||||
elif platform.system() == "Linux":
|
elif platform.system() == "Linux":
|
||||||
info_object["docker"] = is_docker_env()
|
info_object["docker"] = is_docker_env()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user