Skip to content

Commit

Permalink
Merge pull request #723 from hmmbob/fix_static_path_config
Browse files Browse the repository at this point in the history
Fix static path config for HA 2024.7+
  • Loading branch information
AlexxIT authored Sep 8, 2024
2 parents 3bf0799 + a0783df commit 6c4e132
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions custom_components/webrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
from homeassistant.helpers.network import get_url
from homeassistant.helpers.template import Template

try:
from homeassistant.components.http import StaticPathConfig
HA_VERSION_BEFORE_2024_7 = False
except ImportError:
HA_VERSION_BEFORE_2024_7 = True

from . import utils
from .utils import DOMAIN, Server

Expand Down Expand Up @@ -60,14 +66,36 @@ async def async_setup(hass: HomeAssistant, config: dict):
# 1. Serve lovelace card
path = Path(__file__).parent / "www"
for name in ("video-rtc.js", "webrtc-camera.js", "digital-ptz.js"):
hass.http.register_static_path("/webrtc/" + name, str(path / name))
if HA_VERSION_BEFORE_2024_7:
hass.http.register_static_path("/webrtc/" + name, str(path / name))
else:
await hass.http.async_register_static_paths(
[
StaticPathConfig(
"/webrtc/" + name,
str(path / name),
True,
)
]
)

# 2. Add card to resources
version = getattr(hass.data["integrations"][DOMAIN], "version", 0)
await utils.init_resource(hass, "/webrtc/webrtc-camera.js", str(version))

# 3. Serve html page
hass.http.register_static_path("/webrtc/embed", str(path / "embed.html"))
if HA_VERSION_BEFORE_2024_7:
hass.http.register_static_path("/webrtc/embed", str(path / "embed.html"))
else:
await hass.http.async_register_static_paths(
[
StaticPathConfig(
"/webrtc/embed",
"/config/custom_components/webrtc/www/embed.html",
True,
)
]
)

# 4. Serve WebSocket API
hass.http.register_view(WebSocketView)
Expand Down

0 comments on commit 6c4e132

Please sign in to comment.