Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions hass_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import urllib.error
import urllib.parse
import urllib.request
from contextlib import suppress
from os import environ
from typing import TYPE_CHECKING

from aiohttp import ClientSession
Expand All @@ -29,8 +29,10 @@ def get_websocket_url(url: str) -> str:

def is_supervisor() -> bool:
"""Return if we're running inside the HA Supervisor (e.g. HAOS)."""
with suppress(urllib.error.URLError):
return urllib.request.urlopen("ws://supervisor/core/websocket").code == 401 # noqa: S310
try:
urllib.request.urlopen("http://supervisor/core/api", timeout=0.5)
except urllib.error.URLError as err:
return err.reason == "Unauthorized" and environ.get("HASSIO_TOKEN") is not None
return False


Expand Down