|
7 | 7 | from typing import Any, Awaitable, Callable, Dict, List, Optional, cast |
8 | 8 |
|
9 | 9 | from aiohttp import ClientSession, ClientWebSocketResponse, WSMsgType, client_exceptions |
| 10 | +from packaging.version import parse as parse_version |
10 | 11 |
|
| 12 | +from .const import MIN_SERVER_VERSION |
11 | 13 | from .event import Event |
12 | | -from .model.version import VersionInfo |
13 | 14 | from .model.driver import Driver |
| 15 | +from .model.version import VersionInfo |
14 | 16 |
|
15 | 17 | STATE_CONNECTING = "connecting" |
16 | 18 | STATE_CONNECTED = "connected" |
@@ -39,6 +41,10 @@ class InvalidState(Exception): |
39 | 41 | """Exception raised when data gets in invalid state.""" |
40 | 42 |
|
41 | 43 |
|
| 44 | +class InvalidServerVersion(Exception): |
| 45 | + """Exception raised when connected to server with incompatible version.""" |
| 46 | + |
| 47 | + |
42 | 48 | class FailedCommand(Exception): |
43 | 49 | """When a command has failed.""" |
44 | 50 |
|
@@ -265,6 +271,9 @@ async def _handle_connection( # pylint: disable=too-many-branches, too-many-sta |
265 | 271 | await client.receive_json() |
266 | 272 | ) |
267 | 273 |
|
| 274 | + # basic check for server version compatability |
| 275 | + self._check_server_version(self.version.server_version) |
| 276 | + |
268 | 277 | self._logger.info( |
269 | 278 | "Connected to Home %s (Server %s, Driver %s)", |
270 | 279 | version.home_id, |
@@ -365,3 +374,17 @@ async def _start_listening(self) -> None: |
365 | 374 | self._logger.warning( |
366 | 375 | "Re-connected and don't know how to handle new state yet" |
367 | 376 | ) |
| 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 | + ) |
0 commit comments