Skip to content

Commit d26533b

Browse files
authored
Cache version check for the REST API (#53)
1 parent 3c0a57d commit d26533b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

go2rtc_client/rest.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from functools import lru_cache
56
import logging
67
from typing import TYPE_CHECKING, Any, Final, Literal
78

@@ -25,6 +26,12 @@
2526
_MIN_VERSION_UNSUPPORTED: Final = AwesomeVersion("2.0.0")
2627

2728

29+
@lru_cache(maxsize=2)
30+
def _version_is_supported(version: AwesomeVersion) -> bool:
31+
"""Check if the server version is supported."""
32+
return _MIN_VERSION_SUPPORTED <= version < _MIN_VERSION_UNSUPPORTED
33+
34+
2835
class _BaseClient:
2936
"""Base client for go2rtc."""
3037

@@ -149,11 +156,7 @@ async def validate_server_version(self) -> AwesomeVersion:
149156
"""Validate the server version is compatible."""
150157
application_info = await self.application.get_info()
151158
try:
152-
version_supported = (
153-
_MIN_VERSION_SUPPORTED
154-
<= application_info.version
155-
< _MIN_VERSION_UNSUPPORTED
156-
)
159+
version_supported = _version_is_supported(application_info.version)
157160
except AwesomeVersionException as err:
158161
raise Go2RtcVersionError(
159162
application_info.version if application_info else "unknown",

0 commit comments

Comments
 (0)