Handle KeyError in getuser (#59667)
This commit is contained in:
parent
c323815760
commit
f596cb19fd
2 changed files with 12 additions and 1 deletions
|
@ -23,13 +23,17 @@ async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
|
||||||
"virtualenv": is_virtual_env(),
|
"virtualenv": is_virtual_env(),
|
||||||
"python_version": platform.python_version(),
|
"python_version": platform.python_version(),
|
||||||
"docker": False,
|
"docker": False,
|
||||||
"user": getuser(),
|
|
||||||
"arch": platform.machine(),
|
"arch": platform.machine(),
|
||||||
"timezone": str(hass.config.time_zone),
|
"timezone": str(hass.config.time_zone),
|
||||||
"os_name": platform.system(),
|
"os_name": platform.system(),
|
||||||
"os_version": platform.release(),
|
"os_version": platform.release(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
info_object["user"] = getuser()
|
||||||
|
except KeyError:
|
||||||
|
info_object["user"] = None
|
||||||
|
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
info_object["os_version"] = platform.win32_ver()[0]
|
info_object["os_version"] = platform.win32_ver()[0]
|
||||||
elif platform.system() == "Darwin":
|
elif platform.system() == "Darwin":
|
||||||
|
|
|
@ -27,3 +27,10 @@ async def test_container_installationtype(hass):
|
||||||
), patch("homeassistant.helpers.system_info.getuser", return_value="user"):
|
), patch("homeassistant.helpers.system_info.getuser", return_value="user"):
|
||||||
info = await hass.helpers.system_info.async_get_system_info()
|
info = await hass.helpers.system_info.async_get_system_info()
|
||||||
assert info["installation_type"] == "Unknown"
|
assert info["installation_type"] == "Unknown"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_getuser_keyerror(hass):
|
||||||
|
"""Test getuser keyerror."""
|
||||||
|
with patch("homeassistant.helpers.system_info.getuser", side_effect=KeyError):
|
||||||
|
info = await hass.helpers.system_info.async_get_system_info()
|
||||||
|
assert info["user"] is None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue