Skip to content

Commit 44f9db5

Browse files
authored
Implement very basic server version check (#70)
implement very basic server version check
1 parent 3703942 commit 44f9db5

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
aiohttp==3.7.3
1+
aiohttp==3.7.3
2+
packaging==20.8

zwave_js_server/client.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
from typing import Any, Awaitable, Callable, Dict, List, Optional, cast
88

99
from aiohttp import ClientSession, ClientWebSocketResponse, WSMsgType, client_exceptions
10+
from packaging.version import parse as parse_version
1011

12+
from .const import MIN_SERVER_VERSION
1113
from .event import Event
12-
from .model.version import VersionInfo
1314
from .model.driver import Driver
15+
from .model.version import VersionInfo
1416

1517
STATE_CONNECTING = "connecting"
1618
STATE_CONNECTED = "connected"
@@ -39,6 +41,10 @@ class InvalidState(Exception):
3941
"""Exception raised when data gets in invalid state."""
4042

4143

44+
class InvalidServerVersion(Exception):
45+
"""Exception raised when connected to server with incompatible version."""
46+
47+
4248
class FailedCommand(Exception):
4349
"""When a command has failed."""
4450

@@ -265,6 +271,9 @@ async def _handle_connection( # pylint: disable=too-many-branches, too-many-sta
265271
await client.receive_json()
266272
)
267273

274+
# basic check for server version compatability
275+
self._check_server_version(self.version.server_version)
276+
268277
self._logger.info(
269278
"Connected to Home %s (Server %s, Driver %s)",
270279
version.home_id,
@@ -365,3 +374,17 @@ async def _start_listening(self) -> None:
365374
self._logger.warning(
366375
"Re-connected and don't know how to handle new state yet"
367376
)
377+
378+
def _check_server_version(self, server_version: str) -> None:
379+
"""Perform a basic check on the server version compatability."""
380+
cur_version = parse_version(server_version)
381+
min_version = parse_version(MIN_SERVER_VERSION)
382+
if (cur_version.major != min_version.major) or (
383+
cur_version.minor < min_version.minor
384+
):
385+
raise InvalidServerVersion
386+
if cur_version.minor > min_version:
387+
self._logger.warning(
388+
"Connected to a Zwave JS Server with an untested version, \
389+
you may run into compatibility issues!"
390+
)

zwave_js_server/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from enum import Enum, IntEnum
33
from typing import Dict, List
44

5+
MIN_SERVER_VERSION = "1.0.0-beta.1"
6+
57

68
class CommandClass(IntEnum):
79
"""Enum with all known CommandClasses."""

0 commit comments

Comments
 (0)